Beispiel #1
0
void AssassinWar::initGameScreen()
{
    m_pGameScreen = new GameScreen(m_iScreenWidth, m_iScreenHeight);

    m_pGameScreen->initScreen();

    m_pGameScreen->initGameModule();

    m_pGameScreen->setStyleSheet("background-color:transparent;");

    setCentralWidget(m_pGameScreen);

    connect(m_pGameScreen, SIGNAL(screenOpened()), this, SLOT(gameRun()));
    connect(m_pGameScreen, SIGNAL(screenClosed()), this, SLOT(gameClose()));
}
Beispiel #2
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    // There isn't much windows specific initialization to do here, just allocate a console in debug builds
    //     as well as reporting memory leaks
#ifdef _DEBUG
    AllocConsole();
    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
#endif

    // Setup our error handler
    SetUnhandledExceptionFilter(ExceptionHandler);

    // Run the game
    gameRun();

    return 0;
}
Beispiel #3
0
void AtlantikNetwork::processNode(QDomNode n)
{
	QDomAttr a;

	for ( ; !n.isNull() ; n = n.nextSibling() )
	{
		QDomElement e = n.toElement();
		if(!e.isNull())
		{
			if (e.tagName() == "server")
			{
				a = e.attributeNode( QString("version") );
				if ( !a.isNull() )
					m_serverVersion = a.value();

				emit receivedHandshake();
			}
			else if (e.tagName() == "msg")
			{
				a = e.attributeNode(QString("type"));
				if (!a.isNull())
				{
					if (a.value() == "error")
						emit msgError(e.attributeNode(QString("value")).value());
					else if (a.value() == "info")
						emit msgInfo(e.attributeNode(QString("value")).value());
					else if (a.value() == "chat")
						emit msgChat(e.attributeNode(QString("author")).value(), e.attributeNode(QString("value")).value());
				}
			}
			else if (e.tagName() == "display")
			{
				int estateId = -1;

				a = e.attributeNode(QString("estateid"));
				if (!a.isNull())
				{
					estateId = a.value().toInt();
					Estate *estate;
					estate = m_atlanticCore->findEstate(a.value().toInt());

					emit displayDetails(e.attributeNode(QString("text")).value(), e.attributeNode(QString("cleartext")).value().toInt(), e.attributeNode(QString("clearbuttons")).value().toInt(), estate);

					bool hasButtons = false;
					for( QDomNode nButtons = n.firstChild() ; !nButtons.isNull() ; nButtons = nButtons.nextSibling() )
					{
						QDomElement eButton = nButtons.toElement();
						if (!eButton.isNull() && eButton.tagName() == "button")
						{
							emit addCommandButton(eButton.attributeNode(QString("command")).value(), eButton.attributeNode(QString("caption")).value(), eButton.attributeNode(QString("enabled")).value().toInt());
							hasButtons = true;
						}
					}

					if (!hasButtons)
						emit addCloseButton();
				}
			}
			else if (e.tagName() == "client")
			{
				a = e.attributeNode(QString("playerid"));
				if (!a.isNull())
					m_playerId = a.value().toInt();

				a = e.attributeNode(QString("cookie"));
				if (!a.isNull())
					emit clientCookie(a.value());
			}
			else if (e.tagName() == "configupdate")
			{
				int configId = -1;
				a = e.attributeNode(QString("configid"));
				if (!a.isNull())
				{
					configId = a.value().toInt();
					ConfigOption *configOption;
					if (!(configOption = m_atlanticCore->findConfigOption(configId)))
						configOption = m_atlanticCore->newConfigOption( configId );

					a = e.attributeNode(QString("name"));
					if (configOption && !a.isNull())
						configOption->setName(a.value());

					a = e.attributeNode(QString("description"));
					if (configOption && !a.isNull())
						configOption->setDescription(a.value());

					a = e.attributeNode(QString("edit"));
					if (configOption && !a.isNull())
						configOption->setEdit(a.value().toInt());

					a = e.attributeNode(QString("value"));
					if (configOption && !a.isNull())
						configOption->setValue(a.value());

					if (configOption)
						configOption->update();
				}

				int gameId = -1;
				a = e.attributeNode(QString("gameid"));
				if (!a.isNull())
				{
					gameId = a.value().toInt();
					for( QDomNode nOptions = n.firstChild() ; !nOptions.isNull() ; nOptions = nOptions.nextSibling() )
					{
						QDomElement eOption = nOptions.toElement();
						if (!eOption.isNull() && eOption.tagName() == "option")
							emit gameOption(eOption.attributeNode(QString("title")).value(), eOption.attributeNode(QString("type")).value(), eOption.attributeNode(QString("value")).value(), eOption.attributeNode(QString("edit")).value(), eOption.attributeNode(QString("command")).value());
					}
					emit endConfigUpdate();
				}
			}
			else if (e.tagName() == "deletegame")
			{
				a = e.attributeNode(QString("gameid"));
				if (!a.isNull())
				{
					int gameId = a.value().toInt();

					Game *game = m_atlanticCore->findGame(gameId);
					if (game)
						m_atlanticCore->removeGame(game);
				}
			}
			else if (e.tagName() == "gameupdate")
			{
				int gameId = -1;

				a = e.attributeNode(QString("gameid"));
				if (!a.isNull())
				{
					gameId = a.value().toInt();

					Player *playerSelf = m_atlanticCore->playerSelf();
					if ( playerSelf && playerSelf->game() )
						kdDebug() << "gameupdate for " << QString::number(gameId) << " with playerSelf in game " << QString::number(playerSelf->game()->id()) << endl;
					else
						kdDebug() << "gameupdate for " << QString::number(gameId) << endl;


					Game *game = 0;
					if (gameId == -1)
					{
						a = e.attributeNode(QString("gametype"));
						if ( !a.isNull() && !(game = m_atlanticCore->findGame(a.value())) )
							game = m_atlanticCore->newGame(gameId, a.value());
					}
					else if (!(game = m_atlanticCore->findGame(gameId)))
						game = m_atlanticCore->newGame(gameId);

					a = e.attributeNode(QString("canbejoined"));
					if (game && !a.isNull())
						game->setCanBeJoined(a.value().toInt());

					a = e.attributeNode(QString("description"));
					if (game && !a.isNull())
						game->setDescription(a.value());

					a = e.attributeNode(QString("name"));
					if (game && !a.isNull())
						game->setName(a.value());

					a = e.attributeNode(QString("players"));
					if (game && !a.isNull())
						game->setPlayers(a.value().toInt());

					a = e.attributeNode(QString("master"));
					if (game && !a.isNull())
					{
						// Ensure setMaster succeeds by creating player if necessary
						Player *player = m_atlanticCore->findPlayer( a.value().toInt() );
						if ( !player )
							player = m_atlanticCore->newPlayer( a.value().toInt() );
						game->setMaster( player );
					}

					QString status = e.attributeNode(QString("status")).value();
					if ( m_serverVersion.left(4) == "0.9." || (playerSelf && playerSelf->game() == game) )
					{
						if (status == "config")
							emit gameConfig();
						else if (status == "init")
							emit gameInit();
						else if (status == "run")
							emit gameRun();
						else if (status == "end")
							emit gameEnd();
					}

					if (game)
						game->update();
				}
			}
			else if (e.tagName() == "deleteplayer")
			{
				a = e.attributeNode(QString("playerid"));
				if (!a.isNull())
				{
					int playerId = a.value().toInt();

					Player *player = m_atlanticCore->findPlayer(playerId);
					if (player)
						m_atlanticCore->removePlayer(player);
				}
			}
			else if (e.tagName() == "playerupdate")
			{
				int playerId = -1;

				a = e.attributeNode(QString("playerid"));
				if (!a.isNull())
				{
					playerId = a.value().toInt();

					Player *player;
					if (!(player = m_atlanticCore->findPlayer(playerId)))
						player = m_atlanticCore->newPlayer( playerId, (m_playerId == playerId) );

					// Update player name
					a = e.attributeNode(QString("name"));
					if (player && !a.isNull())
						player->setName(a.value());

					// Update player game
					a = e.attributeNode(QString("game"));
					if (player && !a.isNull())
					{
						int gameId = a.value().toInt();
						if (gameId == -1)
							player->setGame( 0 );
						else
						{
							// Ensure setGame succeeds by creating game if necessary
							Game *game = m_atlanticCore->findGame(a.value().toInt());
							if (!game)
								game = m_atlanticCore->newGame(a.value().toInt()); // 
							player->setGame( game );
						}
					}

					// Update player host
					a = e.attributeNode(QString("host"));
					if (player && !a.isNull())
						player->setHost(a.value());

					// Update player image/token
					a = e.attributeNode(QString("image"));
					if (player && !a.isNull())
						player->setImage(a.value());

					// Update player money
					a = e.attributeNode(QString("money"));
					if (player && !a.isNull())
						player->setMoney(a.value().toInt());

					a = e.attributeNode(QString("bankrupt"));
					if (player && !a.isNull())
						player->setBankrupt(a.value().toInt());

					a = e.attributeNode(QString("hasdebt"));
					if (player && !a.isNull())
						player->setHasDebt(a.value().toInt());

					a = e.attributeNode(QString("hasturn"));
					if (player && !a.isNull())
						player->setHasTurn(a.value().toInt());

					// Update whether player can roll
					a = e.attributeNode(QString("can_roll"));
					if (player && !a.isNull())
						player->setCanRoll(a.value().toInt());

					// Update whether player can buy
					a = e.attributeNode(QString("can_buyestate"));
					if (player && !a.isNull())
						player->setCanBuy(a.value().toInt());

					// Update whether player can auction
					a = e.attributeNode(QString("canauction"));
					if (player && !a.isNull())
						player->setCanAuction(a.value().toInt());

					// Update whether player can use a card
					a = e.attributeNode(QString("canusecard"));
					if (player && !a.isNull())
						player->setCanUseCard(a.value().toInt());

					// Update whether player is jailed
					a = e.attributeNode(QString("jailed"));
					if (player && !a.isNull())
					{
						player->setInJail(a.value().toInt());
						// TODO: emit signal with player ptr so board can setText and display something
					}

					// Update player location
					a = e.attributeNode(QString("location"));
					if (!a.isNull())
					{
						m_playerLocationMap[player] = a.value().toInt();

						bool directMove = false;

						Estate *estate = m_atlanticCore->findEstate(a.value().toInt());

						a = e.attributeNode(QString("directmove"));
						if (!a.isNull())
							directMove = a.value().toInt();

						if (player && estate)
						{
							if (directMove)
								player->setLocation(estate);
							else
								player->setDestination(estate);
						}
					}

					if (player)
						player->update();
				}
			}
			else if (e.tagName() == "estategroupupdate")
			{
				a = e.attributeNode(QString("groupid"));
				if (!a.isNull())
				{
					int groupId = a.value().toInt();

					EstateGroup *estateGroup = 0;
					bool b_newEstateGroup = false;
					
					if (!(estateGroup = m_atlanticCore->findEstateGroup(groupId)))
					{
						// Create EstateGroup object
						estateGroup = m_atlanticCore->newEstateGroup(a.value().toInt());
						b_newEstateGroup = true;
					}

					a = e.attributeNode(QString("name"));
					if (estateGroup && !a.isNull())
						estateGroup->setName(a.value());

					// Emit signal so GUI implementations can create view(s)
					// TODO:  port to atlanticcore and create view there
					if (estateGroup)
					{
						if (b_newEstateGroup)
							emit newEstateGroup(estateGroup);
						estateGroup->update();
					}
				}
			}
			else if (e.tagName() == "estateupdate")
			{
				int estateId = -1;

				a = e.attributeNode(QString("estateid"));
				if (!a.isNull())
				{
					estateId = a.value().toInt();
					
					Estate *estate = 0;
					bool b_newEstate = false;

					// FIXME: allow any estateId, GUI should not use it to determin its geometry
					if (estateId >= 0 && estateId < 100 && !(estate = m_atlanticCore->findEstate(a.value().toInt())))
					{
						// Create estate object
						estate = m_atlanticCore->newEstate(estateId);
						b_newEstate = true;

						QObject::connect(estate, SIGNAL(estateToggleMortgage(Estate *)), this, SLOT(estateToggleMortgage(Estate *)));
						QObject::connect(estate, SIGNAL(estateHouseBuy(Estate *)), this, SLOT(estateHouseBuy(Estate *)));
						QObject::connect(estate, SIGNAL(estateHouseSell(Estate *)), this, SLOT(estateHouseSell(Estate *)));
						QObject::connect(estate, SIGNAL(newTrade(Player *)), this, SLOT(newTrade(Player *)));

						// Players without estate should get one
						Player *player = 0;
						QPtrList<Player> playerList = m_atlanticCore->players();
						for (QPtrListIterator<Player> it(playerList); (player = *it) ; ++it)
							if (m_playerLocationMap[player] == estate->id())
								player->setLocation(estate);
					}

					a = e.attributeNode(QString("name"));
					if (estate && !a.isNull())
						estate->setName(a.value());

					a = e.attributeNode(QString("color"));
					if (estate && !a.isNull() && !a.value().isEmpty())
						estate->setColor(a.value());

					a = e.attributeNode(QString("bgcolor"));
					if (estate && !a.isNull())
						estate->setBgColor(a.value());

					a = e.attributeNode(QString("owner"));
					Player *player = m_atlanticCore->findPlayer(a.value().toInt());
					if (estate && !a.isNull())
						estate->setOwner(player);

					a = e.attributeNode(QString("houses"));
					if (estate && !a.isNull())
						estate->setHouses(a.value().toInt());

					a = e.attributeNode(QString("mortgaged"));
					if (estate && !a.isNull())
						estate->setIsMortgaged(a.value().toInt());

					a = e.attributeNode(QString("group"));
					if (!a.isNull())
					{
						EstateGroup *estateGroup = m_atlanticCore->findEstateGroup(a.value().toInt());
						if (estate)
							estate->setEstateGroup(estateGroup);
					}

					a = e.attributeNode(QString("can_toggle_mortgage"));
					if (estate && !a.isNull())
						estate->setCanToggleMortgage(a.value().toInt());

					a = e.attributeNode(QString("can_be_owned"));
					if (estate && !a.isNull())
						estate->setCanBeOwned(a.value().toInt());

					a = e.attributeNode(QString("can_buy_houses"));
					if (estate && !a.isNull())
						estate->setCanBuyHouses(a.value().toInt());

					a = e.attributeNode(QString("can_sell_houses"));
					if (estate && !a.isNull())
						estate->setCanSellHouses(a.value().toInt());

					a = e.attributeNode(QString("price"));
					if (estate && !a.isNull())
						estate->setPrice(a.value().toInt());

					a = e.attributeNode(QString("houseprice"));
        				if (estate && !a.isNull())
                				estate->setHousePrice(a.value().toInt());

        				a = e.attributeNode(QString("sellhouseprice"));
        				if (estate && !a.isNull())
                				estate->setHouseSellPrice(a.value().toInt());
						
					a = e.attributeNode(QString("mortgageprice"));
        				if (estate && !a.isNull())
                				estate->setMortgagePrice(a.value().toInt());

        				a = e.attributeNode(QString("unmortgageprice"));
        				if (estate && !a.isNull())
                				estate->setUnmortgagePrice(a.value().toInt());
						
					a = e.attributeNode(QString("money"));
					if (estate && !a.isNull())
						estate->setMoney(a.value().toInt());

					// Emit signal so GUI implementations can create view(s)
					// TODO:  port to atlanticcore and create view there
					if (estate)
					{
						if (b_newEstate)
							emit newEstate(estate);
						estate->update();
					}
				}
			}
int main(int argc, char *argv[]){ 
  char esc,tmp,strInputs[8] = {'I','T','L','F','C','U','E','O'};
  int i,j,activeStructures[8];
  Init();
  while(1){
           char c,c2;
           if(MainMenu.buttons[0].clicked){//PLAY button
                                           gameInit();
                                           gameRun();
                                           MainMenu.buttons[0].clicked = 0;
                                           }
           else if(MainMenu.buttons[1].clicked){//BEST SCORE button
                printf("Name : %s   Best Score : %d",HighScore.name,HighScore.score);
                getch();
                MainMenu.buttons[1].clicked = 0;
                }
           else if(MainMenu.buttons[2].clicked){//SETTINGS button
                if(SettingsMenu.buttons[0].clicked){//MATRIXSIZE button
                     printf("Current Matrix Size : %d",Board.settings.matrixSize);
                     printf("\nPress Enter To Change...");
                     c2 = getch();
                     if(c2 == 13) {
                           printf("\nNew Size : ");
                           scanf("%d",&Board.settings.matrixSize);
						   if(Board.settings.matrixSize > BOARD_MAX_SIZE)Board.settings.matrixSize = BOARD_MAX_SIZE;
						   else if(Board.settings.matrixSize < 5)Board.settings.matrixSize = 5;
                           printf("Current Matrix Size : %d",Board.settings.matrixSize);
                           getch();
                     }
                     SettingsMenu.buttons[0].clicked = 0;
                     }
                else if(SettingsMenu.buttons[1].clicked){//RANGE button
                     printf("Number Range : %d , %d",Board.settings.range[0],Board.settings.range[1]);
                     printf("\n(Difference must be greater then 2 <2,10>)\nPress Enter To Change...");
                     c2 = getch();
                     if(c2 == 13) {
                           printf("\nRange Begin : ");
                           scanf("%d",&Board.settings.range[0]);
						   if(Board.settings.range[0] < 2)Board.settings.range[0] = 2;
                           printf("Range End : ");
                           scanf("%d",&Board.settings.range[1]);
						   if(Board.settings.range[1] > 10)Board.settings.range[1] = 10;
						   if(Board.settings.range[0] > Board.settings.range[1] - 2){
						   Board.settings.range[0] = 2;
						   Board.settings.range[1] = 10;
						   }
                           printf("\nNew Number Range : %d , %d",Board.settings.range[0],Board.settings.range[1]);
                           getch();
                      }
                     SettingsMenu.buttons[1].clicked = 0;
                     }
                else if(SettingsMenu.buttons[2].clicked){//STRUCTURE button

				     printf("Active Structures : ");
				     for(i = 0;i < Board.settings.numberOfStructures;i++)printf(" %c ",Board.settings.structures[i].name);
                     printf("\nAvaliable Structures : I T L C E F O U");
                     printf("\nPress Enter To Change...");
                     c2 = getch();
                     if(c2 == 13) {
					       printf("\n\nThe characters you used will be saved up till you use different ones\n\n");//ingilizceye çevir
					       i = 0;
						   esc = 0;
						   while(i < 8 && !esc){
								j = 0;
								printf("Enter Structure : ");
								scanf(" %c",&tmp);
								while(j < 8 && strInputs[j] != tmp && strInputs[j] != (tmp-'a'+'A') )j++;
								if(j < 8)activeStructures[i] = j;
								else esc = 1;
								i++;
						   }
						   if(i > 1){
								if(!esc)MYS_Settings_CreateStructures(&Board.settings,activeStructures,i);
								else MYS_Settings_CreateStructures(&Board.settings,activeStructures,i-1);
						   }
						   printf("Active Structures : ");
						   for(i = 0;i < Board.settings.numberOfStructures;i++)printf(" %c ",Board.settings.structures[i].name);
						   getch();
					 }
                     SettingsMenu.buttons[2].clicked = 0;
                     }
                else if(SettingsMenu.buttons[3].clicked){//PLAYER NAME button
					 char name[32];
					 printf("Current Name : %s",Board.settings.player.name);
                     printf("\n(Name Length must be greater then 2)\nPress Enter To Change...");
                     c2 = getch();
                     if(c2 == 13) {
                           printf("\nNew Name : ");
                           gets(name);
						   if(strlen(name) > 2)
                           strcpy(Board.settings.player.name,name);
						   printf("Current Name : %s",Board.settings.player.name);
						   SaveScore();
                           getch();
                     }
                     SettingsMenu.buttons[3].clicked = 0;
				
				}
				else if(SettingsMenu.buttons[4].clicked){//BACK button
                     SettingsMenu.buttons[4].clicked = 0;
                     MainMenu.buttons[2].clicked = 0;
                     MainMenu.focusedButtonIndex = 0;
                     }
                else{
                     drawMenu(&SettingsMenu);
                     c = getch();
                     if(c == 27){//BACK button
                          SettingsMenu.buttons[4].clicked = 0;
                          MainMenu.buttons[2].clicked = 0;
                          MainMenu.focusedButtonIndex = 0;
                          }
                     else menuInput(&SettingsMenu,c);
                     }
                }
           else if(MainMenu.buttons[3].clicked){//EXIT button
                printf("CODED BY EMRE KUL");
                getch();
                return;
                }
           else {//w s enter key
                drawMenu(&MainMenu);
                c = getch();
                menuInput(&MainMenu,c);
                } 
           system("cls");    
   }
  return 0;
}
Beispiel #5
0
void eoMainLoop()
{

  while ( ! engVarDone )
  {
    tickStartFrame(); //Keep track of time
    SDL_Event event;

    while ( SDL_PollEvent(&event) )
    {
      switch(event.type)
      {
        case SDL_QUIT:
          engVarDone = 1;
        break;
        case SDL_KEYDOWN:
          inputKeyDown( event.key.keysym );
        break;
        case SDL_KEYUP:
          inputKeyUp( event.key.keysym );
        break;
        case SDL_MOUSEMOTION:
          inputMouseMove( event.motion );
        break;
        case SDL_MOUSEBUTTONDOWN:
          inputMouseButton( event.button );
        break;
        case SDL_MOUSEBUTTONUP:
          inputMouseButton( event.button );
        break;
        case SDL_JOYAXISMOTION:
          inputJoyMove( event.jaxis );
        break;
        case SDL_JOYBUTTONDOWN:
          inputJoyButton( event.jbutton );
        break;
        case SDL_JOYBUTTONUP:
          inputJoyButton( event.jbutton );
        break;
      }
    }

  //Run keys
  inputRunKeys();

  engRender();

  gameRun();

  //Render 2D overlays.
  guiDraw();

  //Music
  sndRun();

  tickStopLogic();
  SDL_GL_SwapBuffers();

  //If we don't have vsync on, or if we are above 60 fps.
  int dt = ticksLogic();
  if( !(dt>0 && dt < 16) ) dt=0;
  #ifndef WIN32
    usleep(16666-dt*1000);
  #else
    Sleep(16-dt);
  #endif
  if( engVarShowTimes )
    eoPrint("Frame time: %i ms. Code time: %i ms.", eoTicks(), dt );
  }
}