示例#1
0
void GameplayScreen::Update(Game* game)
{
	// Immediately return if paused
	if (isPaused || isGameOver)
		return;

	if (isPowerUpState)
	{
		if (Ghost::CurrentState() != Frightened)
		{
			// Return to standard background music
			isPowerUpState = false;
			Mix_PlayMusic(background, -1);
		}
	}

	if (levelManager->GetPlayer()->HasDeathAnimationFinished())
	{
		// Check if we are out of lives
		if (livesRemaining <= 0)
		{
			fprintf(stdout, "Game Over!\n");
			GameEnd(0);
			return;
		}
		else
		{
			levelManager->ResetAgentPositions();
		}
	}

	// Check for victory condition
	if (levelManager->GetPellets().empty())
	{
		// The level was completed
		if (levelManager->LevelCompletedAnimation())
		{
			// Go to the next level if one exists
			if (levelManager->NextLevel() == false)
				GameEnd(1);
		}
		return;
	}

	levelManager->Update(game->GetDeltaTime());

	//// Update the player
	//levelManager->GetPlayer()->Update(game->GetDeltaTime());

	//// Update the AI
	//for (std::vector<Ghost*>::iterator iter = levelManager->GetGhosts().begin(); 
	//	iter != levelManager->GetGhosts().end(); ++iter)
	//{
	//	(*iter)->Update(game->GetDeltaTime());
	//}

	// Handle the collisions last
	HandleCollisions();
}
示例#2
0
bool CTableFrameSink::SubGameLost(WORD wSeat)
{
	CMD_S_Lost  LostSeat;
	LostSeat.wSeat =wSeat;
	m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_LOST,&LostSeat,sizeof(LostSeat));
	m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_LOST,&LostSeat,sizeof(LostSeat));

	BYTE bPlayCnt =0;
	WORD seat=0;
	//只剩下一个玩家了
	for(int i=0;i<GAME_PLAYER;i++)
	{
		if(m_bPlayStatus[i] ==GS_PLAYING && wSeat != i)
		{
			seat=i;
			bPlayCnt++;
		}
	}

	if(bPlayCnt ==1)
	{
		return GameEnd(seat,GER_NO_PLAYER);
	} else m_bPlayStatus[wSeat] =GS_FREE;
	return true;
}
//=============================================================
//Windows Functions
//=============================================================
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   PSTR szCmdLine, int iCmdShow)
{
	MSG			msg;
	static int	iTickTrigger = 0;
	int			iTickCount;

	if (GameInitialize(hInstance))
	{
		//Initialize the game engine
		if (!GameEngine::GetEngine()->Initialize(iCmdShow))
			return FALSE;

		//Enter the main message loop
		while (TRUE)
		{
			if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				//Process the message
				if (msg.message == WM_QUIT)
					break;
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else
			{
				//Make sure the game engine isn't sleeping
				if (!GameEngine::GetEngine()->GetSleep())
				{
					//Check the tick count to see if a game cycle has elapsed
					iTickCount = GetTickCount();
					if (iTickCount > iTickTrigger)
					{
						iTickTrigger = iTickCount +
							GameEngine::GetEngine()->GetFrameDelay();
						HandleKeys();
						GameCycle();
					}
				}
			}
		}
		return (int)msg.wParam;
	}

	//End the game
	GameEnd();

	return TRUE;
}
示例#4
0
void GoLevel(void)
/* pide un nivel y su c?digo de acceso y lo lanza si es v?lido */
{
    int n_password;

    _level = GetNumber("GO LEVEL\n\n\n\n\nLEVEL NUMBER: %s\n", 30);

    if (_level == 0) {
        _level = 1;
        return;
    }

    n_password = GetNumber("GO LEVEL\n\n\n\n\nACCESS CODE: %s\n", 999998);

    ParseParam(ReadLevel());

    if (n_password == 822994)
        GameEnd();
    else if (n_password != 170868 && _password != n_password) {
        _level = 1;

        strcpy(_text_mask, "GO LEVEL\n\n\n\n\nWRONG ACCESS CODE\n");

        for (;;) {
            DrawWaterVirtualScreen();
            DrawText();
            qdgdfv_dump_virtual_screen();

            qdgdfv_input_poll();

            if (_qdgdfv_key_escape || _qdgdfv_key_enter)
                break;
        }

        while (_qdgdfv_key_escape || _qdgdfv_key_enter)
            qdgdfv_input_poll();
    }
    else {
        do {
            Game();
            ParseParam(ReadLevel());
        } while (_level_resolved);
    }
}
示例#5
0
void GameCore(int x, int y, int z, int a)
/* n?cleo del juego */
{
    int cycle_count = 0;

    while (!_qdgdfv_key_escape && !_last_level_resolved) {
        qdgdfv_input_poll();

        /* F10: pause switch */
        if (qdgdfv_extended_key_status(&_qdgdfv_key_f10) == 1)
            _user_pause ^= 1;

        if (DrawNewFrame()) {
            if (!_user_pause) {
                TimeEvents(y);

                Motion(&x, &y, &z, &a);

                cycle_count++;

                if (!(cycle_count & 0x01) && y < _water_level)
                    continue;
            }
            else
                SetMessage("", "", "PAUSED...", "", 1);

            Objects();

            Render(x, y, z, a);
        }
    }

    SwapScreens(0);

    while (_qdgdfv_key_escape)
        qdgdfv_input_poll();

    /* si se ha resuelto el ?ltimo nivel, mensaje */
    if (_last_level_resolved)
        GameEnd();
}
示例#6
0
//////////////////////////////////////////////////////////////////
// Functions
//////////////////////////////////////////////////////////////////
int CWin::Run()
{
	MSG msg;

	ZeroMemory( &msg, sizeof(msg) );
	
	while( msg.message!=WM_QUIT )
	{
		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		} 
		else 
		{
		  GameLoop(m_hWnd);
		}
	}
	
	GameEnd();
	
	return msg.wParam;
}
LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	//Route Windows messages to game engine member fucntions
	switch (msg)
	{
	case WM_CREATE:
		//Set the game window and start the game
		SetWindow(hWindow);
		GameStart(hWindow);
		return 0;

	case WM_ACTIVATE:
		//Activate and deactivate the game and update the Sleep status
		if (wParam != WA_INACTIVE)
		{
			GameActivate(hWindow);
			SetSleep(FALSE);
		}
		else
		{
			GameDeactivate(hWindow);
			SetSleep(TRUE);
		}
		return 0;

	case WM_PAINT:
		HDC			hDC;
		PAINTSTRUCT	ps;
		hDC = BeginPaint(hWindow, &ps);

		//Paint the game
		GamePaint(hDC);

		EndPaint(hWindow, &ps);
		return 0;

	case WM_LBUTTONDOWN:
		//Handle left mouse button press
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;

	case WM_LBUTTONUP:
		//Handle left mouse button release
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;

	case WM_RBUTTONDOWN:
		//Handle right mouse button press
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;

	case WM_RBUTTONUP:
		//Handle right mouse button release
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;

	case WM_MOUSEMOVE:
		//Handle mouse movement
		MouseMove(LOWORD(lParam), HIWORD(lParam));
		return 0;

	case WM_DESTROY:
		//End the game and exit the application
		GameEnd();
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWindow, msg, wParam, lParam);
}
示例#8
0
//游戏消息处理
bool __cdecl CTableFrameSink::OnGameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)
{
	if(m_bIsGameEnd)
	{
		return true;
	}
	switch (wSubCmdID)
	{
	case SUB_C_GUIDE:
		{
			WORD wSeat = pIServerUserItem->GetChairID();

			//指南针道具
			m_bPropCnt[wSeat][PROP_GUIDE]--;
			return true;
		}
	case SUB_C_BOMB:
		{
			WORD wSeat = pIServerUserItem->GetChairID();

			//指南针道具
			m_bPropCnt[wSeat][PROP_BOM]--;
			return true;
		}
	case SUB_C_STOPIT:
		{
			if(wDataSize != sizeof(CMD_C_StopIt)) return false;
			CMD_C_StopIt *pCnt = (CMD_C_StopIt *)pDataBuffer;
			WORD wSeat = pIServerUserItem->GetChairID();
			CMD_S_StopIt Stop;
			Stop.nSrcUserId =(BYTE)wSeat;
			Stop.nDesUserId =pCnt->nDesUserId;
			//禁手道具
			m_bPropCnt[wSeat][PROP_STOPIT]--;
			Stop.nPropCount = m_bPropCnt[wSeat][PROP_STOPIT];

			m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_STOPIT,&Stop,sizeof(Stop));
			m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_STOPIT,&Stop,sizeof(Stop));
			return true;
		}
	case SUB_C_CLOG:
		{
			if(wDataSize != sizeof(CMD_C_Clog)) return false;
			CMD_C_Clog *pCnt = (CMD_C_Clog *)pDataBuffer;
			WORD wSeat = pIServerUserItem->GetChairID();
			CMD_S_Clog  Clog;
			memset(&Clog,ERROR_ALL,sizeof(Clog));
			Clog.nDesUserId = pCnt->nDesUserId;
			Clog.nSrcUserId = (BYTE)wSeat;
			CArrayTemplate<CPoint> Map;
			for(int i=0;i<CHESSCOUNT_H;i++)
			{
				for(int j=0;j<CHESSCOUNT_W;j++)
				{
					if(m_bChess[pCnt->nDesUserId][i][j] == ERROR_ALL &&i>0 &&i<CHESSCOUNT_H-1&&\
						j>0 && j<CHESSCOUNT_W-1)
					{
						Map.Add(CPoint(i,j));
					}
				}
			}
			if(Map.GetCount())
			{
				
				int randMaxNum=(int)Map.GetCount() >=12?12:(int)Map.GetCount();
				//取偶数
				randMaxNum = randMaxNum%2?randMaxNum-1:randMaxNum;
				srand((unsigned int)time(NULL));
				int pos=0;
				while(randMaxNum>0)
				{
					BYTE chessValue =RandNumber(0,MAX_CHESS_VALUE);
					int randNum = rand()%(int)Map.GetCount();
					Clog.nChessPosX[pos] =(BYTE)Map.GetAt(randNum).y;
					Clog.nChessPosY[pos] =(BYTE)Map.GetAt(randNum).x;
					Clog.nChessFace[pos]=chessValue;
					pos++;
					Map.RemoveAt(randNum);
					randMaxNum--;
					randNum = rand()%(int)Map.GetCount();
					Clog.nChessPosX[pos] =(BYTE)Map.GetAt(randNum).y;
					Clog.nChessPosY[pos] =(BYTE)Map.GetAt(randNum).x;
					Clog.nChessFace[pos]=chessValue;
					pos++;
					Map.RemoveAt(randNum);
					randMaxNum--;
				}
			}

			//障碍道具
			m_bPropCnt[wSeat][PROP_CLOG]--;
			Clog.nPropCount = m_bPropCnt[wSeat][PROP_CLOG];

			m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_CLOG,&Clog,sizeof(Clog));
			m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_CLOG,&Clog,sizeof(Clog));

			return true;
		}
	case SUB_C_TIMER:
		{
			if(wDataSize != sizeof(CMD_C_Timer)) return false;
			CMD_C_Timer *pCnt = (CMD_C_Timer *)pDataBuffer;
			WORD wSeat = pIServerUserItem->GetChairID();
			m_bTimerCnt[wSeat]=pCnt->nTime;
			CString str;
			str.Format("--%d--\n",m_bTimerCnt[wSeat]);
			TRACE(str);
			if(m_bTimerCnt[wSeat] ==0)
			{
				return SubGameLost(wSeat);
			}
			return true;
		}
	case SUB_C_LINK:
		{
			if(wDataSize != sizeof(CMD_C_Link)) return false;
			CMD_C_Link *pPos = (CMD_C_Link *)pDataBuffer;
			WORD wSeat = pIServerUserItem->GetChairID();
			CArrayTemplate<CPoint> path;
			CPoint p1,p2;
			if(!m_GameLogic.IsLink(m_bChess[wSeat],CPoint(pPos->nFirst_X,pPos->nFirst_Y),CPoint(pPos->nEnd_X,pPos->nEnd_Y),\
				&path,&p1,&p2))
			{
				return false;
			}
			else
			{
				if(pPos->bLinkKind ==LK_SERIES_LINK)
				{
					m_bSeriesLinkCnt[wSeat] ++;
				}
				BYTE bValue =m_bChess[wSeat][pPos->nFirst_Y][pPos->nFirst_X];
				m_bChess[wSeat][pPos->nFirst_Y][pPos->nFirst_X]=ERROR_ALL;
				m_bChess[wSeat][pPos->nEnd_Y][pPos->nEnd_X]=ERROR_ALL;

				CMD_S_Link LinkPos;
				ZeroMemory(&LinkPos,sizeof(LinkPos));
				LinkPos.nEnd_X =pPos->nEnd_X;
				LinkPos.nEnd_Y =pPos->nEnd_Y;
				LinkPos.nFirst_X =pPos->nFirst_X;
				LinkPos.nFirst_Y =pPos->nFirst_Y;
				LinkPos.nCurrentPlayer = (BYTE)wSeat;
				if(bValue >=PROP_MIN_VALUE)
				{
					m_bPropCnt[wSeat][bValue-PROP_MIN_VALUE] ++;
					LinkPos.nPropCount =m_bPropCnt[wSeat][bValue-PROP_MIN_VALUE];
					LinkPos.nPropType  = bValue-PROP_MIN_VALUE;
				}
				else
					LinkPos.nPropType = ERROR_ALL;

				m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_LINK,&LinkPos,sizeof(LinkPos));
				m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_LINK,&LinkPos,sizeof(LinkPos));

				//检验游戏是否结束
				bool bIsGameEnd=true;
				for(int i=0;i<CHESSCOUNT_H;i++)
				{
					for(int j=0;j<CHESSCOUNT_W;j++)
					{
						if(m_bChess[wSeat][i][j] != ERROR_ALL)
						{
							i=CHESSCOUNT_H;
							bIsGameEnd=false;
							break;
						}
					}
				}
				if(bIsGameEnd)
				{
					GameEnd(wSeat,GER_NORMAL);
				}

				return true;
			}
		}
	case SUB_C_REALIGN:
		{
			if(wDataSize != sizeof(CMD_C_Realign)) return false;
			CMD_C_Realign *pcRealign = (CMD_C_Realign *)pDataBuffer;
			WORD wSeat = pIServerUserItem->GetChairID();

			memcpy(m_bChess[wSeat],pcRealign->nChess,sizeof(pcRealign->nChess));

			CMD_S_Realign sRealign;
			sRealign.nCurrentPlayer = (BYTE)wSeat;
			memcpy(sRealign.nChess,pcRealign->nChess,sizeof(pcRealign->nChess));

			//4为障碍道具
			m_bPropCnt[wSeat][PROP_RESET]--;
			sRealign.nPropCount = m_bPropCnt[wSeat][PROP_RESET];

			m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_REALIGN,&sRealign,sizeof(sRealign));
			m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_REALIGN,&sRealign,sizeof(sRealign));

			return true;
		}
	default:
		{
			return false;
		}
	}

	return false;
}
示例#9
0
void CGame::ClientReadNet()
{
	if (gu->gameTime - lastCpuUsageTime >= 1) {
		lastCpuUsageTime = gu->gameTime;

		if (playing) {
			net->Send(CBaseNetProtocol::Get().SendCPUUsage(profiler.GetPercent("CPU load")));
#if defined(USE_GML) && GML_ENABLE_SIM
			net->Send(CBaseNetProtocol::Get().SendLuaDrawTime(gu->myPlayerNum, luaDrawTime));
#endif
		} else {
			// the CPU-load percentage is undefined prior to SimFrame()
			net->Send(CBaseNetProtocol::Get().SendCPUUsage(0.0f));
		}
	}

	boost::shared_ptr<const netcode::RawPacket> packet;

	// compute new timeLeft to "smooth" out SimFrame() calls
	if (!gameServer) {
		const unsigned int currentFrame = SDL_GetTicks();

		if (timeLeft > 1.0f)
			timeLeft -= 1.0f;
		timeLeft += consumeSpeed * ((float)(currentFrame - lastframe) / 1000.f);
		if (skipping)
			timeLeft = 0.01f;
		lastframe = currentFrame;

		// read ahead to calculate the number of NETMSG_NEWFRAMES
		// we still have to process (in variable "que")
		int que = 0; // Number of NETMSG_NEWFRAMEs waiting to be processed.
		unsigned ahead = 0;
		while ((packet = net->Peek(ahead))) {
			if (packet->data[0] == NETMSG_NEWFRAME || packet->data[0] == NETMSG_KEYFRAME)
				++que;
			++ahead;
		}

		if(que < leastQue)
			leastQue = que;
	}
	else
	{
		// make sure ClientReadNet returns at least every 15 game frames
		// so CGame can process keyboard input, and render etc.
		timeLeft = (float)MAX_CONSECUTIVE_SIMFRAMES * gs->userSpeedFactor;
	}

	// always render at least 2FPS (will otherwise be highly unresponsive when catching up after a reconnection)
	unsigned procstarttime = SDL_GetTicks();
	// really process the messages
	while (timeLeft > 0.0f && (SDL_GetTicks() - procstarttime) < 500 && (packet = net->GetData(gs->frameNum)))
	{
		const unsigned char* inbuf = packet->data;
		const unsigned dataLength = packet->length;
		const unsigned char packetCode = inbuf[0];

		switch (packetCode) {
			case NETMSG_QUIT: {
				try {
					netcode::UnpackPacket pckt(packet, 3);
					std::string message;
					pckt >> message;
					logOutput.Print(message);
					if (!gameOver) {
						GameEnd(std::vector<unsigned char>());
					}
					AddTraffic(-1, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid QuitMessage: %s", e.err.c_str());
				}
				break;
			}

			case NETMSG_PLAYERLEFT: {
				const unsigned char player = inbuf[1];
				if (!playerHandler->IsValidPlayer(player)) {
					logOutput.Print("Got invalid player num (%i) in NETMSG_PLAYERLEFT", player);
					break;
				}
				playerHandler->PlayerLeft(player, inbuf[2]);
				eventHandler.PlayerRemoved(player, (int) inbuf[2]);

				AddTraffic(player, packetCode, dataLength);
				break;
			}

			case NETMSG_MEMDUMP: {
				MakeMemDump();
#ifdef TRACE_SYNC
				tracefile.Commit();
#endif
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_STARTPLAYING: {
				unsigned timeToStart = *(unsigned*)(inbuf+1);
				if (timeToStart > 0) {
					GameSetupDrawer::StartCountdown(timeToStart);
				} else {
					StartPlaying();
				}
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_SENDPLAYERSTAT: {
				//logOutput.Print("Game over");
			// Warning: using CPlayer::Statistics here may cause endianness problems
			// once net->SendData is endian aware!
				net->Send(CBaseNetProtocol::Get().SendPlayerStat(gu->myPlayerNum, playerHandler->Player(gu->myPlayerNum)->currentStats));
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_PLAYERSTAT: {
				const unsigned char player = inbuf[1];
				if (!playerHandler->IsValidPlayer(player)) {
					logOutput.Print("Got invalid player num %i in playerstat msg",player);
					break;
				}
				playerHandler->Player(player)->currentStats = *(CPlayer::Statistics*)&inbuf[2];
				if (gameOver) {
					CDemoRecorder* record = net->GetDemoRecorder();
					if (record != NULL) {
						record->SetPlayerStats(player, playerHandler->Player(player)->currentStats);
					}
				}
				AddTraffic(player, packetCode, dataLength);
				break;
			}

			case NETMSG_PAUSE: {
				const unsigned char player = inbuf[1];
				if (!playerHandler->IsValidPlayer(player)) {
					logOutput.Print("Got invalid player num %i in pause msg",player);
					break;
				}
				gs->paused=!!inbuf[2];
				logOutput.Print(gs->paused ? "%s paused the game" : "%s unpaused the game" ,
											playerHandler->Player(player)->name.c_str());
				eventHandler.GamePaused(player, gs->paused);
				lastframe = SDL_GetTicks();
				AddTraffic(player, packetCode, dataLength);
				break;
			}

			case NETMSG_INTERNAL_SPEED: {
				gs->speedFactor = *((float*) &inbuf[1]);
				sound->PitchAdjust(sqrt(gs->speedFactor));
				//	logOutput.Print("Internal speed set to %.2f",gs->speedFactor);
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_USER_SPEED: {
				gs->userSpeedFactor = *((float*) &inbuf[2]);

				const unsigned char player = inbuf[1];
				if (!playerHandler->IsValidPlayer(player) && player != SERVER_PLAYER) {
					logOutput.Print("Got invalid player num %i in user speed msg", player);
					break;
				}
				const char* pName = (player == SERVER_PLAYER)? "server": playerHandler->Player(player)->name.c_str();

				logOutput.Print("Speed set to %.1f [%s]", gs->userSpeedFactor, pName);
				AddTraffic(player, packetCode, dataLength);
				break;
			}

			case NETMSG_CPU_USAGE: {
				logOutput.Print("Game clients shouldn't get cpu usage msgs?");
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_PLAYERINFO: {
				const unsigned char player = inbuf[1];
				if (!playerHandler->IsValidPlayer(player)) {
					logOutput.Print("Got invalid player num %i in playerinfo msg", player);
					break;
				}
				playerHandler->Player(player)->cpuUsage = *(float*) &inbuf[2];
				playerHandler->Player(player)->ping = *(boost::uint32_t*) &inbuf[6];

				AddTraffic(player, packetCode, dataLength);
				break;
			}

			case NETMSG_PLAYERNAME: {
				try {
					netcode::UnpackPacket pckt(packet, 2);
					unsigned char player;
					pckt >> player;
					if (!playerHandler->IsValidPlayer(player))
						throw netcode::UnpackPacketException("Invalid player number");

					pckt >> playerHandler->Player(player)->name;
					playerHandler->Player(player)->readyToStart=(gameSetup->startPosType != CGameSetup::StartPos_ChooseInGame);
					playerHandler->Player(player)->active=true;
					wordCompletion->AddWord(playerHandler->Player(player)->name, false, false, false); // required?
					AddTraffic(player, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid PlayerName: %s", e.err.c_str());
				}
				break;
			}

			case NETMSG_CHAT: {
				try {
					ChatMessage msg(packet);

					HandleChatMsg(msg);
					AddTraffic(msg.fromPlayer, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid ChatMessage: %s", e.err.c_str());
				}
				break;
			}

			case NETMSG_SYSTEMMSG:{
				try {
					netcode::UnpackPacket pckt(packet, 4);
					string s;
					pckt >> s;
					logOutput.Print(s);
					AddTraffic(-1, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid SystemMessage: %s", e.err.c_str());
				}
				break;
			}

			case NETMSG_STARTPOS:{
				const unsigned char player = inbuf[1];
				if (!playerHandler->IsValidPlayer(player) && player != SERVER_PLAYER) {
					logOutput.Print("Got invalid player num %i in start pos msg", player);
					break;
				}
				const int team = inbuf[2];
				if (!teamHandler->IsValidTeam(team)) {
					logOutput.Print("Got invalid team num %i in startpos msg", team);
				} else {
					float3 pos(*(float*)&inbuf[4],
					           *(float*)&inbuf[8],
					           *(float*)&inbuf[12]);
					if (!luaRules || luaRules->AllowStartPosition(player, pos)) {
						teamHandler->Team(team)->StartposMessage(pos);
						if (inbuf[3] != 2 && player != SERVER_PLAYER)
						{
							playerHandler->Player(player)->readyToStart = !!inbuf[3];
						}
						if (pos.y != -500) // no marker marker when no pos set yet
						{
							char label[128];
							SNPRINTF(label, sizeof(label), "Start %i", team);
							inMapDrawer->LocalPoint(pos, label, player);
							// FIXME - erase old pos ?
						}
					}
				}
				AddTraffic(player, packetCode, dataLength);
				break;
			}

			case NETMSG_RANDSEED: {
				gs->SetRandSeed(*((unsigned int*)&inbuf[1]), true);
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_GAMEID: {
				const unsigned char* p = &inbuf[1];
				CDemoRecorder* record = net->GetDemoRecorder();
				if (record != NULL) {
					record->SetGameID(p);
				}
				memcpy(gameID, p, sizeof(gameID));
				logOutput.Print(
				  "GameID: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
				  p[ 0], p[ 1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7],
				  p[ 8], p[ 9], p[10], p[11], p[12], p[13], p[14], p[15]);
				AddTraffic(-1, packetCode, dataLength);
				break;
			}

			case NETMSG_PATH_CHECKSUM: {
				const unsigned char playerNum = inbuf[1];
				if (!playerHandler->IsValidPlayer(playerNum)) {
					logOutput.Print("Got invalid player num %i in path checksum msg", playerNum);
					break;
				}

				const boost::uint32_t playerCheckSum = *(boost::uint32_t*) &inbuf[2];
				const boost::uint32_t localCheckSum = pathManager->GetPathCheckSum();
				const CPlayer* player = playerHandler->Player(playerNum);

				if (playerCheckSum == 0) {
					logOutput.Print(
						"[DESYNC WARNING] path-checksum for player %d (%s) is 0; non-writable cache?",
						playerNum, player->name.c_str()
					);
				} else {
					if (playerCheckSum != localCheckSum) {
						logOutput.Print(
							"[DESYNC WARNING] path-checksum %08x for player %d (%s) does not match local checksum %08x",
							playerCheckSum, playerNum, player->name.c_str(), localCheckSum
						);
					}
				}
			} break;

			case NETMSG_KEYFRAME: {
				int serverframenum = *(int*)(inbuf+1);
				net->Send(CBaseNetProtocol::Get().SendKeyFrame(serverframenum));
				if (gs->frameNum == (serverframenum - 1)) {
				} else {
					// error
					LogObject() << "Error: Keyframe difference: " << gs->frameNum - (serverframenum - 1);
				}
				/* Fall through */
			}
			case NETMSG_NEWFRAME: {
				timeLeft -= 1.0f;
				SimFrame();
				// both NETMSG_SYNCRESPONSE and NETMSG_NEWFRAME are used for ping calculation by server
#ifdef SYNCCHECK
				net->Send(CBaseNetProtocol::Get().SendSyncResponse(gs->frameNum, CSyncChecker::GetChecksum()));
				if ((gs->frameNum & 4095) == 0) {// reset checksum every ~2.5 minute gametime
					CSyncChecker::NewFrame();
				}
#endif
				AddTraffic(-1, packetCode, dataLength);

				if (videoCapturing->IsCapturing()) {
					return;
				}
				break;
			}

			case NETMSG_COMMAND: {
				try {
					netcode::UnpackPacket pckt(packet, 1);
					short int psize;
					pckt >> psize;
					unsigned char player;
					pckt >> player;
					if (!playerHandler->IsValidPlayer(player))
						throw netcode::UnpackPacketException("Invalid player number");

					Command c;
					pckt >> c.id;
					pckt >> c.options;
					for(int a = 0; a < ((psize-9)/4); ++a) {
						float param;
						pckt >> param;
						c.params.push_back(param);
					}
					selectedUnits.NetOrder(c,player);
					AddTraffic(player, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid Command: %s", e.err.c_str());
				}
				break;
			}

			case NETMSG_SELECT: {
				try {
					netcode::UnpackPacket pckt(packet, 1);
					short int psize;
					pckt >> psize;
					unsigned char player;
					pckt >> player;
					if (!playerHandler->IsValidPlayer(player))
						throw netcode::UnpackPacketException("Invalid player number");

					vector<int> selected;
					for (int a = 0; a < ((psize-4)/2); ++a) {
						short int unitid;
						pckt >> unitid;

						if (uh->GetUnit(unitid) == NULL)
							throw netcode::UnpackPacketException("Invalid unit ID");

						if ((uh->GetUnit(unitid)->team == playerHandler->Player(player)->team) || gs->godMode) {
							selected.push_back(unitid);
						}
					}
					selectedUnits.NetSelect(selected, player);

					AddTraffic(player, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid Select: %s", e.err.c_str());
				}
				break;
			}

			case NETMSG_AICOMMAND:
			case NETMSG_AICOMMAND_TRACKED: {
				try {
					netcode::UnpackPacket pckt(packet, 1);
					short int psize;
					pckt >> psize;
					unsigned char player;
					pckt >> player;

					if (!playerHandler->IsValidPlayer(player))
						throw netcode::UnpackPacketException("Invalid player number");

					short int unitid;
					pckt >> unitid;
					if (unitid < 0 || static_cast<size_t>(unitid) >= uh->MaxUnits())
						throw netcode::UnpackPacketException("Invalid unit ID");

					Command c;
					pckt >> c.id;
					pckt >> c.options;
					if (packetCode == NETMSG_AICOMMAND_TRACKED) {
						pckt >> c.aiCommandId;
					}

					// insert the command parameters
					for (int a = 0; a < ((psize - 11) / 4); ++a) {
						float param;
						pckt >> param;
						c.params.push_back(param);
					}

					selectedUnits.AiOrder(unitid, c, player);
					AddTraffic(player, packetCode, dataLength);
				} catch (netcode::UnpackPacketException &e) {
					logOutput.Print("Got invalid AICommand: %s", e.err.c_str());
				}
				break;
			}
示例#10
0
void Game::Step5End() {
    // Check if game is over
    if (gameOver) {
        // If single winner
        if (winners.size() == 1)
            winner = winners[0];

        // If more than one winner
        else if (winners.size() > 1) {

            // Get max
            int maxMoney = winners[0]->GetElektro();
            for (int i = 1; i < winners.size(); i++) {
                if (winners[i]->GetElektro() > maxMoney)
                    maxMoney = winners[i]->GetElektro();
            }

            // Take the max only
            for (int i = 0; i < winners.size(); i++)
                if (winners[i]->GetElektro() != maxMoney)
                    winners.erase(winners.begin() + i);

            // If only one winner
            if (winners.size() == 1) {
                winner = winners[0];

            // If more than one winner
            }
            else if (winners.size() > 1) {

                int maxCitiesIndex = 0;
                for (int i = 1; i < winners.size(); i++) {
                    if (winners[i]->GetHouses().size() > winners[maxCitiesIndex]->GetHouses().size())
                        maxCitiesIndex = i;
                }
                winner = winners[maxCitiesIndex];
            }
            
            // End the game
            GameEnd();
        }
    }
    // If not, reset gameOver
    gameOver = false;

    // Change the visible power plants
    if (phase == 1 || phase == 2) {
        // Place highest plant under stack 
        cardStack.PlaceHighestVisibleAtEndOfStack();
        cardStack.DrawPlant();
    }
    else if (phase == 3) {
        // Remove lowest plant from the game
        cardStack.RemoveLowestVisible();
        cardStack.DrawPlant();
    }

    // Check if we drew the step 3 card
    if (cardStack.GetJustDrewStep() == 3) {
        cardStack.AdjustForStep3();
        cardStack.ShuffleStack();
        phase = 3;

        cout << "Entering phase 3." << endl;
    }

    // Restock raw materials
    for (int i = 0; i < res::total; i++) {
        Resource resource = static_cast<Resource>(COAL + i);

        int resourceAdded = overview.GetRuleByNumOfPlayers(players.size()).GetResourceAt(phase, resource);
        // Check that there are enough unused resources to add
        resourceAdded = std::min(resourceAdded, getUnusedResources(resource)); 
        rMarket->AddResource(resource, resourceAdded);
    }

    fullTurn++;

    Step1Start();
}
void HandleKey(Key key, int key_status)
{
  boolean anyTextGadgetActiveOrJustFinished = anyTextGadgetActive();
  static struct SetupKeyboardInfo ski;
  static struct SetupShortcutInfo ssi;
  static struct
  {
    Key *key_custom;
    Key *key_snap;
    Key key_default;
    byte action;
  } key_info[] =
  {
    { &ski.left,  &ssi.snap_left,  DEFAULT_KEY_LEFT,  JOY_LEFT        },
    { &ski.right, &ssi.snap_right, DEFAULT_KEY_RIGHT, JOY_RIGHT       },
    { &ski.up,    &ssi.snap_up,    DEFAULT_KEY_UP,    JOY_UP          },
    { &ski.down,  &ssi.snap_down,  DEFAULT_KEY_DOWN,  JOY_DOWN        },
    { &ski.snap,  NULL,            DEFAULT_KEY_SNAP,  JOY_BUTTON_SNAP },
    { &ski.drop,  NULL,            DEFAULT_KEY_DROP,  JOY_BUTTON_DROP }
  };
  int joy = 0;
  int i;

  if (game_status == GAME_MODE_PLAYING)
  {
    /* only needed for single-step tape recording mode */
    static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
    static boolean element_dropped[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
    int pnr;

    ssi = setup.shortcut;

    for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
    {
      byte key_action = 0;

      if (setup.input[pnr].use_joystick)
	continue;

      ski = setup.input[pnr].key;

      for (i = 0; i < NUM_PLAYER_ACTIONS; i++)
	if (key == *key_info[i].key_custom)
	  key_action |= key_info[i].action;

      for (i = 0; i < NUM_DIRECTIONS; i++)
	if (key == *key_info[i].key_snap)
	  key_action |= key_info[i].action | JOY_BUTTON_SNAP;

      if (tape.single_step && clear_button_2[pnr])
      {
	stored_player[pnr].action &= ~KEY_BUTTON_2;
	clear_button_2[pnr] = FALSE;
      }

      if (key_status == KEY_PRESSED)
	stored_player[pnr].action |= key_action;
      else
	stored_player[pnr].action &= ~key_action;

      if (tape.single_step && tape.recording && tape.pausing)
      {
	if (key_status == KEY_PRESSED &&
	    (key_action & (KEY_MOTION | KEY_BUTTON_1)))
	{
	  TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);

	  if (key_action & KEY_MOTION)
	  {
	    if (stored_player[pnr].action & KEY_BUTTON_2)
	      element_dropped[pnr] = TRUE;
	  }
	}
	else if (key_status == KEY_RELEASED &&
		 (key_action & KEY_BUTTON_2))
	{
	  if (!element_dropped[pnr])
	  {
	    TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);

	    stored_player[pnr].action |= KEY_BUTTON_2;
	    clear_button_2[pnr] = TRUE;
	  }

	  element_dropped[pnr] = FALSE;
	}
      }
#if 1
      else if (tape.recording && tape.pausing)
      {
	/* prevent key release events from un-pausing a paused game */
	if (key_status == KEY_PRESSED &&
	    (key_action & KEY_ACTION))
	  TapeTogglePause(TAPE_TOGGLE_MANUAL);
      }
#else
      else if (tape.recording && tape.pausing && (key_action & KEY_ACTION))
	TapeTogglePause(TAPE_TOGGLE_MANUAL);
#endif
    }
  }
  else
  {
    for (i = 0; i < NUM_PLAYER_ACTIONS; i++)
      if (key == key_info[i].key_default)
	joy |= key_info[i].action;
  }

  if (joy)
  {
    if (key_status == KEY_PRESSED)
      key_joystick_mapping |= joy;
    else
      key_joystick_mapping &= ~joy;

    HandleJoystick();
  }

  if (game_status != GAME_MODE_PLAYING)
    key_joystick_mapping = 0;

  if (key_status == KEY_RELEASED)
    return;

  if ((key == KSYM_Return || key == KSYM_KP_Enter) &&
      (GetKeyModState() & KMOD_Alt) && video.fullscreen_available)
  {
    setup.fullscreen = !setup.fullscreen;

    ToggleFullscreenIfNeeded();

    if (game_status == GAME_MODE_SETUP)
      RedrawSetupScreenAfterFullscreenToggle();

    return;
  }

#if 0
  if (game_status == GAME_MODE_PLAYING && local_player->LevelSolved_GameEnd &&
      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
#else
  if (game_status == GAME_MODE_PLAYING && AllPlayersGone &&
      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
#endif
  {
    GameEnd();

    return;
  }

  if (game_status == GAME_MODE_MAIN &&
      (key == setup.shortcut.toggle_pause || key == KSYM_space))
  {
    StartGameActions(options.network, setup.autorecord, level.random_seed);

    return;
  }

  if (game_status == GAME_MODE_MAIN || game_status == GAME_MODE_PLAYING)
  {
    if (key == setup.shortcut.save_game)
      TapeQuickSave();
    else if (key == setup.shortcut.load_game)
      TapeQuickLoad();
    else if (key == setup.shortcut.toggle_pause)
      TapeTogglePause(TAPE_TOGGLE_MANUAL);

    HandleTapeButtonKeys(key);
    HandleSoundButtonKeys(key);
  }

  if (game_status == GAME_MODE_PLAYING && !network_playing)
  {
    int centered_player_nr_next = -999;

    if (key == setup.shortcut.focus_player_all)
      centered_player_nr_next = -1;
    else
      for (i = 0; i < MAX_PLAYERS; i++)
	if (key == setup.shortcut.focus_player[i])
	  centered_player_nr_next = i;

    if (centered_player_nr_next != -999)
    {
      game.centered_player_nr_next = centered_player_nr_next;
      game.set_centered_player = TRUE;

      if (tape.recording)
      {
	tape.centered_player_nr_next = game.centered_player_nr_next;
	tape.set_centered_player = TRUE;
      }
    }
  }

  HandleKeysSpecial(key);

  if (HandleGadgetsKeyInput(key))
  {
    if (key != KSYM_BackSpace)	/* always allow ESC key to be handled */
      key = KSYM_UNDEFINED;
  }

  switch (game_status)
  {
    case GAME_MODE_PSEUDO_TYPENAME:
      HandleTypeName(0, key);
      break;

    case GAME_MODE_TITLE:
    case GAME_MODE_MAIN:
    case GAME_MODE_LEVELS:
    case GAME_MODE_SETUP:
    case GAME_MODE_INFO:
    case GAME_MODE_SCORES:
      switch (key)
      {
	case KSYM_space:
	case KSYM_Return:
	  if (game_status == GAME_MODE_TITLE)
	    HandleTitleScreen(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_MAIN)
	    HandleMainMenu(0, 0, 0, 0, MB_MENU_CHOICE);
          else if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, 0, MB_MENU_CHOICE);
	  break;

	case KSYM_BackSpace:
	  if (game_status != GAME_MODE_MAIN)
	    FadeSkipNextFadeIn();

	  if (game_status == GAME_MODE_TITLE)
	    HandleTitleScreen(0, 0, 0, 0, MB_MENU_LEAVE);
          else if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, 0, MB_MENU_LEAVE);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, 0, MB_MENU_LEAVE);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, 0, MB_MENU_LEAVE);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, 0, MB_MENU_LEAVE);
	  break;

        case KSYM_Page_Up:
          if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  break;

        case KSYM_Page_Down:
          if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  break;

#ifdef DEBUG
	case KSYM_0:
	  GameFrameDelay = (GameFrameDelay == 500 ? GAME_FRAME_DELAY : 500);
	  break;

	case KSYM_b:
	  setup.sp_show_border_elements = !setup.sp_show_border_elements;
	  printf("Supaplex border elements %s\n",
		 setup.sp_show_border_elements ? "enabled" : "disabled");
	  break;
#endif

	default:
	  break;
      }
      break;

    case GAME_MODE_EDITOR:
      if (!anyTextGadgetActiveOrJustFinished || key == KSYM_BackSpace)
	HandleLevelEditorKeyInput(key);
      break;

    case GAME_MODE_PLAYING:
    {
      switch (key)
      {
        case KSYM_BackSpace:
	  RequestQuitGame(setup.ask_on_escape);
	  break;

#ifdef DEBUG
	case KSYM_0:
#if 0
	case KSYM_1:
	case KSYM_2:
	case KSYM_3:
	case KSYM_4:
	case KSYM_5:
	case KSYM_6:
	case KSYM_7:
	case KSYM_8:
	case KSYM_9:
#endif
	  if (key == KSYM_0)
	  {
	    if (GameFrameDelay == 500)
	      GameFrameDelay = GAME_FRAME_DELAY;
	    else
	      GameFrameDelay = 500;
	  }
	  else
	    GameFrameDelay = (key - KSYM_0) * 10;
	  printf("Game speed == %d%% (%d ms delay between two frames)\n",
		 GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay);
	  break;

	case KSYM_d:
	  if (options.debug)
	  {
	    options.debug = FALSE;
	    printf("debug mode disabled\n");
	  }
	  else
	  {
	    options.debug = TRUE;
	    printf("debug mode enabled\n");
	  }
	  break;

	case KSYM_S:
	  if (!global.fps_slowdown)
	  {
	    global.fps_slowdown = TRUE;
	    global.fps_slowdown_factor = 2;
	    printf("fps slowdown enabled -- display only every 2nd frame\n");
	  }
	  else if (global.fps_slowdown_factor == 2)
	  {
	    global.fps_slowdown_factor = 4;
	    printf("fps slowdown enabled -- display only every 4th frame\n");
	  }
	  else
	  {
	    global.fps_slowdown = FALSE;
	    global.fps_slowdown_factor = 1;
	    printf("fps slowdown disabled\n");
	  }
	  break;

	case KSYM_f:
	  ScrollStepSize = TILEX/8;
	  printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
	  break;

	case KSYM_g:
	  ScrollStepSize = TILEX/4;
	  printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
	  break;

	case KSYM_h:
	  ScrollStepSize = TILEX/2;
	  printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
	  break;

	case KSYM_l:
	  ScrollStepSize = TILEX;
	  printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
	  break;

	case KSYM_v:
	  printf("::: currently using game engine version %d\n",
		 game.engine_version);
	  break;
#endif

	default:
	  break;
      }
      break;
    }

    default:
      if (key == KSYM_BackSpace)
      {
	game_status = GAME_MODE_MAIN;
	DrawMainMenu();

	return;
      }
  }
}
void HandleJoystick()
{
  int joystick	= HandleJoystickForAllPlayers();
  int keyboard	= key_joystick_mapping;
  int joy	= (joystick | keyboard);
  int left	= joy & JOY_LEFT;
  int right	= joy & JOY_RIGHT;
  int up	= joy & JOY_UP;
  int down	= joy & JOY_DOWN;
  int button	= joy & JOY_BUTTON;
  int newbutton	= (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED);
  int dx	= (left ? -1	: right ? 1	: 0);
  int dy	= (up   ? -1	: down  ? 1	: 0);

  switch (game_status)
  {
    case GAME_MODE_TITLE:
    case GAME_MODE_MAIN:
    case GAME_MODE_LEVELS:
    case GAME_MODE_SETUP:
    case GAME_MODE_INFO:
    {
      static unsigned long joystickmove_delay = 0;

      if (joystick && !button &&
	  !DelayReached(&joystickmove_delay, GADGET_FRAME_DELAY))
	newbutton = dx = dy = 0;

      if (game_status == GAME_MODE_TITLE)
	HandleTitleScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
      else if (game_status == GAME_MODE_MAIN)
	HandleMainMenu(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
      else if (game_status == GAME_MODE_LEVELS)
        HandleChooseLevel(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
      else if (game_status == GAME_MODE_SETUP)
	HandleSetupScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
      else if (game_status == GAME_MODE_INFO)
	HandleInfoScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
      break;
    }

    case GAME_MODE_SCORES:
      HandleHallOfFame(0, 0, dx, dy, !newbutton);
      break;

    case GAME_MODE_EDITOR:
      HandleLevelEditorIdle();
      break;

    case GAME_MODE_PLAYING:
      if (tape.playing || keyboard)
	newbutton = ((joy & JOY_BUTTON) != 0);

#if 0
      if (local_player->LevelSolved_GameEnd && newbutton)
#else
      if (AllPlayersGone && newbutton)
#endif
      {
	GameEnd();

	return;
      }

      break;

    default:
      break;
  }
}
示例#13
0
void CGameGunHound::Loop()
{
	//-----------------------------------------
	//ハウンドメイン
	//-----------------------------------------

	if( m_bResetOK )
	{
		if( m_bResetPlease )
		{
			m_bResetPlease = gxFalse;
			m_sEndSeq = -1;
			ChangeGameSeq( enMainSeqGameEnd );
		}
		else if( CDashBoard::GetInstance()->IsMenuBar() )
		{
			m_bPauseFlag = gxTrue;
		}
		else
		{
			m_bPauseFlag = gxFalse;
		}

	}


	switch( m_GameSeq ){
	case enMainSeqInit:
		//-----------------------------------------
		//ゲーム初期化
		//-----------------------------------------
		m_bBriefingRoot = gxTrue;
		m_bResetOK      = gxFalse;
		viiDbg::log("ハウンドシーケンス:enMainSeqInit");
		//SaveDataInit();
		//GameConfigLoad();
		m_bPauseFlag = gxFalse;
		ChangeGameSeq( enMainSeqStart );
		break;

	case enMainSeqStart:
		//-----------------------------------------
		//スコア初期化
		//-----------------------------------------
		m_bResetOK = gxFalse;
		viiDbg::log("ハウンドシーケンス:enMainSeqStart");

#ifdef _VII_DEBUG_
		CDashBoard::GetInstance()->SetMenuDisable(gxFalse);
		CDashBoard::GetInstance()->SetLogo(gxFalse);
		CDashBoard::GetInstance()->SetWallPaper(gxFalse);
		ChangeGameSeq( enMainSeqRestart );
#else
//		ChangeGameSeq( enMainSeqGameOpeningDemo );
		CDashBoard::GetInstance()->SetMenuDisable(gxFalse);
		CDashBoard::GetInstance()->SetLogo(gxFalse);
		CDashBoard::GetInstance()->SetWallPaper(gxFalse);
		ChangeGameSeq( enMainSeqGameTitle );
#endif
		break;

	case enMainSeqGameTitle:
		//-----------------------------------------
		//タイトルのシーケンス
		//-----------------------------------------
		UploadTexture();
		m_bResetOK = gxFalse;
		ChangeGameSeq( enMainSeqRestart );
		break;

	case enMainSeqRestart:
		//-----------------------------------------
		//リスタートのポイント
		//-----------------------------------------
		m_bResetOK = gxFalse;

		ResetClass();

#ifdef GX_DEBUG
		ChangeGameSeq( enMainSeqDebugMenu );
#else
		ChangeGameSeq( enMainSeqGameMainMenu );
#endif
		break;

	case enMainSeqGameMainMenu:
		//-----------------------------------------
		//メインメニューのシーケンス
		//-----------------------------------------
		m_bResetOK = gxTrue;
		CDashBoard::GetInstance()->SetMenuDisable(gxTrue);
		switch( MainMenu() ){
		case enMenuSeqBack:
		case enMenuSeqNext:
			g_StGameInfo.Reset();
			if( m_sMainMenuSelected == CMainMenu::enMainMenuOpening )
			{
				//オープニングへ
				ChangeGameSeq( enMainSeqGameOpeningDemo );
			}
			else if( m_sMainMenuSelected == CMainMenu::enMainMenuDebug )
			{
				//デバッグモードへ
				g_StGameInfo.m_sGameMode = StGameInfo::enGameModeNormal;
				ChangeGameSeq( enMainSeqDebugMenu );
			}
			else if( m_sMainMenuSelected == CMainMenu::enMainMenuEnding )
			{
				//エンディング
				CDashBoard::GetInstance()->SetIcon( enIconNone );
				ChangeGameSeq( enMainSeqGameEndingDemo );
			}
			else if( m_sMainMenuSelected == CMainMenu::enMainMenuStart )
			{
				//ゲームスタートへ
				CDashBoard::GetInstance()->SetIcon( enIconNone );
				g_StGameInfo.m_sGameMode = StGameInfo::enGameModeNormal;
				g_StGameInfo.m_bMessage = gxTrue;
				ChangeGameSeq( enMainSeqGameBriefing );
			}
			else if( m_sMainMenuSelected == CMainMenu::enMainMenuTutorial )
			{
				//チュートリアルスタートへ
				g_StGameInfo.m_bMusic   = gxTrue;
				g_StGameInfo.m_bMessage = gxTrue;
				g_StGameInfo.m_bReplay  = gxFalse;
				CDashBoard::GetInstance()->SetIcon( enIconNone );
				g_StGameInfo.m_sGameMode = StGameInfo::enGameModeNormal;
				g_StGameInfo.PlayStage = enScenarioTutorial;
				StageSet();
				g_StGameInfo.PlayArea  = m_sSelectedStage;
				ChangeGameSeq( enMainSeqGameInit );
			}
			else if( m_sMainMenuSelected == CMainMenu::enMainMenuMission )
			{
				//ゲームスタートへ
				CDashBoard::GetInstance()->SetIcon( enIconNone );
				g_StGameInfo.m_sGameMode = StGameInfo::enGameModeMission;
				g_StGameInfo.PlayStage   = m_sSelectedStage;//enScenarioTutorial;
				g_StGameInfo.PlayArea = 0;

				StageSet();

				ChangeGameSeq( enMainSeqGameInit );

			}
			else if( m_sMainMenuSelected == CMainMenu::enMainMenuExit )
			{
				//ゲーム終了
				ExitGame();
			}
			break;

		default:
			break;
		}
		break;

	case enMainSeqGameOpeningDemo:
		//-----------------------------------------
		//オープニングのシーケンス
		//-----------------------------------------
		m_bResetOK = gxFalse;
		if( AdvertiseDemo()  )
		{
			ChangeGameSeq( enMainSeqGameTitle );
		}
		break;

	case enMainSeqDebugMenu:
		//-----------------------------------------
		//デバッグメニュー
		//-----------------------------------------
		m_bResetOK = gxTrue;
		switch( DebugMenu() ) {
		case enMenuSeqBack:
			ChangeGameSeq( enMainSeqGameMainMenu );
			break;
		case enMenuSeqNext:
//			g_StGameInfo.Reset();
			g_StGameInfo.m_bMessage = gxTrue;
			g_StGameInfo.m_bMusic   = gxTrue;
			g_StGameInfo.m_bReplay  = gxFalse;
			ChangeGameSeq( enMainSeqGameInit );
			break;
		}
		break;

	case enMainSeqGameBriefing:
		g_StGameInfo.ContinueArea = 0;

		CCockpit::GetInstance()->SetHidden();
		CDashBoard::GetInstance()->SetMenuDisable(gxFalse);
		m_bResetOK = gxTrue;

		if( m_pSetUp == NULL )
		{
			//セットアップ画面を作る
			m_pSetUp = new CSetUp( -1 );//g_StGameInfo.PlayStage );
		}

		if( BriefingMain() )
		{
			//ステージ決定
			StageSet();
			m_bBriefingRoot = gxTrue;
			ChangeGameSeq( enMainSeqGameSetUp );
		}

		CockpitControl();
		break;

	case enMainSeqGameSetUp:
		CCockpit::GetInstance()->SetHidden();
		m_bResetOK = gxTrue;

		if( m_pSetUp->IsEnd() )
		{
			ChangeGameSeq( enMainSeqGameBefore );
		}

		CockpitControl();
		break;

	case enMainSeqGameBefore:
		//-----------------------------------------
		//ゲーム初期化
		//-----------------------------------------
		CCockpit::GetInstance()->ReNew();
		CCockpit::GetInstance()->SetHidden();

		CockpitControl();

		m_bResetOK = gxTrue;

		if( !m_pSetUp->IsWait() )
		{
			//CCockpit::GetInstance()->Reset();
			viiMus::StopBGM( enSoundBgm1 );
			ChangeGameSeq( enMainSeqGameInit );
		}

		break;

	case enMainSeqGameInit:
		//-----------------------------------------
		//ゲーム初期化
		//-----------------------------------------
		CCockpit::GetInstance()->Destroy();
		CCockpit::GetInstance()->SetHidden();
		m_bResetOK = gxFalse;

		if( pGame ) delete pGame;
		pGame = new CGameManager();

		GameInit();

		pGame->init();

		CockpitControl();

		viiMus::Destroy();
		ChangeGameSeq( enMainSeqGameMain );
		break;

	case enMainSeqGameMain:
		//-----------------------------------------
		//ゲームメイン
		//-----------------------------------------
		CDashBoard::GetInstance()->SetMenuDisable(gxFalse);
		m_bResetOK = gxTrue;

		if( m_pSetUp )
		{
			m_bResetOK = gxFalse;

			m_pSetUp->Draw();

			if( m_pSetUp->GoDestroy() )
			{
				//----------------------------------------------
				//セットアップ終了
				//----------------------------------------------
				CCockpit::GetInstance()->Reset();
				delete m_pSetUp;
				m_pSetUp = NULL;
			}
		}

		if( !m_bGameStart && pGame->IsGameStart() )
		{
			m_bGameStart = gxTrue;
		}

		GameMain();

		if( pGame->IsStageClear() )
		{
			m_sEndSeq = pGame->GetNextSeq();	//m_sEndSeq = 1;	//次へ
			ChangeGameSeq( enMainSeqGameEnd );
		}
		else if( CCockpit::GetInstance()->IsGameOver() )
		{
			m_sEndSeq = enClearSeqContinue;
			ChangeGameSeq( enMainSeqGameEnd );
		}

		break;

	case enMainSeqGameEnd:
		//-----------------------------------------
		//ゲーム終了
		//-----------------------------------------
		m_bResetOK = gxFalse;

		GameEnd();

		if( pGame )
		{
			delete pGame;
			pGame = NULL;
		}

		if( !m_bBriefingRoot )
		{
			m_sEndSeq = 0;
		}

		CCockpit::GetInstance()->ReNew();

		if( m_sMainMenuSelected == CMainMenu::enMainMenuMission || m_sMainMenuSelected == CMainMenu::enMainMenuTutorial)
		{
			//---------------------------------------
			//ストーリーモード以外の時
			//---------------------------------------

			//スコアを加算する
			g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore );

			//ミッションモードだった
			ChangeGameSeq( enMainSeqGameMainMenu );

			//チュートリアルモードだった
			ChangeGameSeq( enMainSeqGameMainMenu );

		}
		else if( m_sEndSeq == enClearSeqStageClear )
		{
#ifdef _TRIAL_VERSION_
			//タイトルに戻る
			g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore );
			ChangeGameSeq( enMainSeqRestart );
#else
			//ステージクリアだった
			g_StGameInfo.SetStageClear( g_StGameInfo.PlayStage );
			switch( g_StGameInfo.PlayStage ){
			case enScenarioJungle:
				g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission2 );
				break;
			case enScenarioRiver:
				g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission3 );
				break;
			case enScenarioMountain:
				g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission4 );
				break;
			case enScenarioBase:
				g_CHoundSaveData.SetHiddenOpen( enHiddenItemMission5 );
				break;
			}

			ChangeGameSeq( enMainSeqGameBriefing );
#endif
		}
		else if( m_sEndSeq == enClearSeqContinue )
		{
			//ステージ失敗だった(コンティニュールート)
			ChangeGameSeq( enMainSeqGameContinue );
		}
		else if( m_sEndSeq == enClearSeqGameOver )
		{
			//ゲームオーバーだった
			ChangeGameSeq( enMainSeqGameContinue );
		}
		else if( m_sEndSeq == enClearSeqEnding )
		{
			//エンディングだった
			g_StGameInfo.SetStageClear( g_StGameInfo.PlayStage );
			g_CHoundSaveData.UpdateHighScore( MISSION_ALLOVER_BONUS );

			Uint32 uScore = 0;

			//ゲームスコアを加算
			m_stEndingBonus.uAllScore = g_StGameInfo.m_uAllScore;

			//オールオーバーボーナスをコンティニュー回数で割る
			m_stEndingBonus.uContinueBonus = MISSION_ALLOVER_BONUS/(g_StGameInfo.m_sContinueCnt+1);
			m_stEndingBonus.uContinueBonus = m_stEndingBonus.uContinueBonus/10;
			m_stEndingBonus.uContinueBonus = m_stEndingBonus.uContinueBonus*10;


			//Trueエンディングの場合場合ボーナス
			m_stEndingBonus.uTrueEndBonus = 0;
			if( g_StGameInfo.m_bTrueEnd )
			{
				m_stEndingBonus.uTrueEndBonus = ENDING_TRUEVERSION_BONUS;
				g_CHoundSaveData.SetHiddenOpen( enHiddenItemViewEnding );
			}

			//ノーコンティニューだった場合2倍ボーナス
			if( g_StGameInfo.m_sContinueCnt == 0 )
			{
				m_stEndingBonus.uNoContinueBonus = m_stEndingBonus.uAllScore + m_stEndingBonus.uContinueBonus + m_stEndingBonus.uTrueEndBonus;
			}

			uScore =  m_stEndingBonus.uAllScore;
			uScore += m_stEndingBonus.uContinueBonus;
			uScore += m_stEndingBonus.uTrueEndBonus;
			uScore += m_stEndingBonus.uNoContinueBonus;

			m_stEndingBonus.uTotalScore = uScore;

			//スコアを加算する
			g_CHoundSaveData.UpdateHighScore( uScore );

			ChangeGameSeq( enMainSeqGameEndingDemo );
		}
		else
		{
			//リセットだった
/*
			if( m_bGameStart && m_sMainMenuSelected == CMainMenu::enMainMenuStart )
			{
				m_sResetCount = 120;
				ChangeGameSeq( enMainSeqResetInGame );
			}
			else
			{
				ChangeGameSeq( enMainSeqRestart );
			}
*/
			ChangeGameSeq( enMainSeqRestart );

		}
		break;

	case enMainSeqGameContinue:
		//-----------------------------------------
		//コンティニュー
		//-----------------------------------------
		m_bResetOK = gxTrue;
		m_bGameStart = gxFalse;
		switch( ContinueScreen() ){
		case enMenuSeqNext:
			{
				//タイトルに戻る
				g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore );
				ChangeGameSeq( enMainSeqRestart );
			}
			break;

		case enMenuSeqBack:
			{
				//コンティニューする
//				Sint32 sMem = g_StGameInfo.PlayArea;
//				StageSet();
				//スコアをリセットする
/*
				g_StGameInfo.m_uAllScore   = (g_StGameInfo.m_uAllScore/2);
				g_StGameInfo.m_uAllScore   -= g_StGameInfo.m_uAllScore%10;;
*/
				//スコア更新
				g_CHoundSaveData.UpdateHighScore( g_StGameInfo.m_uAllScore );
				g_StGameInfo.m_uAllScore   = 0;//(g_StGameInfo.m_uAllScore/2);
				g_StGameInfo.m_uStageScore = g_StGameInfo.m_uAllScore;

				if( g_StGameInfo.m_sContinueCnt < 99 ) g_StGameInfo.m_sContinueCnt ++;
				g_StGameInfo.ContinueArea = g_StGameInfo.PlayArea;
				ChangeGameSeq( enMainSeqGameInit );
			}
			break;

		default:
			break;
		}
		break;

	case enMainSeqGameEndingDemo:
		//-----------------------------------------
		//ゲーム終了
		//-----------------------------------------
		m_bResetOK = gxTrue;
		m_bGameStart = gxFalse;
		CCockpit::GetInstance()->SetHidden();
		CDashBoard::GetInstance()->SetMenuDisable(gxFalse);
		if( EndingDemo() )
		{
			ChangeGameSeq( enMainSeqRestart );
		}
		break;
	case enMainSeqResetInGame:
		if( m_sResetCount > 0 )
		{
			m_sResetCount --;
		}
		else
		{
			g_StGameInfo.m_uAllScore   = 0;
			g_StGameInfo.m_uStageScore = 0;
			g_StGameInfo.ContinueArea = g_StGameInfo.PlayArea;
			CCockpit::GetInstance()->ReNew();
			ChangeGameSeq( enMainSeqGameInit );
		}
		break;
	default:
		break;
	}

	viiMus::GetInstance()->Action();
	CFadeManager::GetInstance()->action();
}
示例#14
0
Sint32 CGameGunHound::AdvertiseDemo()
{
	//---------------------------------------------
	//デモ
	//---------------------------------------------

	if( m_pOpeningDemo == NULL )
	{
		m_pOpeningDemo = new COpeningDemo();
	}

	m_pOpeningDemo->Action();

	Sint32 opCode = m_pOpeningDemo->GetOperation();

	if( m_pOpeningDemo->IsEnd() )
	{
		delete m_pOpeningDemo;
		m_pOpeningDemo = NULL;
		opCode = COpeningDemo::enOperationEnd;
	}
	else
	{
		m_pOpeningDemo->Draw();
	}

	switch( opCode ){
	case COpeningDemo::enOperationInit:
		//ゲームを初期化
		g_StGameInfo.PlayStage = GetDemoStage();
		pGame = new CGameManager();
		GameInit();
		g_StGameInfo.m_bMusic   = gxFalse;
		g_StGameInfo.m_bMessage = gxFalse;
		g_StGameInfo.m_bReplay  = gxTrue;
		pGame->init();
		m_sDemoCount ++;
		break;

	case COpeningDemo::enOperationMain:
		//ゲームを更新

		GameMain();

		if( CCockpit::GetInstance()->IsGameOver() )
		{
			m_pOpeningDemo->SetStatusGameOver();
		}
		break;

	case COpeningDemo::enOperationEnd:
		GameEnd();
		if( pGame )
		{
			delete pGame;
			pGame = NULL;
		}
		CCockpit::GetInstance()->ReNew();
		return -1;

	default:
		break;
	}

	return 0;
}
示例#15
0
/*メイン関数*/
void TextClass::Main(UserClass &User){
	//メニューパラメータセット
	static struct MenuArg_rec MenuRightParam;
	SetMenuParam_GameRight(MenuRightParam);
	static MenuClass GameRightMenu(MenuRightParam);

	//定数
	const int OtherSelect = 6;


	//ゲームカウントの初期化
	InitGameCount(User);

	//テキストチェック
	CheckText(User);	

	//制御コードチェック
	if( WriteMode != EYECATCH ) CheckCotrolCode(User);

	//背景描画
	Graph.DrawBack(User);

	//キャラクタ描画
	Graph.DrawChar(User);

	//テキストボックス描画
	if( WriteMode != NOTWINDOW ) Graph.DrawWindow();

	//描画モード取得
	//WriteMode = GetWriteMode();

	//コンフィグで未読スキップ許可設定
	ReadUpdate(User);

	//既読チェック
	CheckRead();
	
	//デバッグ用既読操作
	ControlRead();

	//メニュー設置・処理
	if( WriteMode == NORMAL ){
		GameRightMenu.Create();
		Select = GameRightMenu.GetSelectNo();
	}
	
	//テキスト描画
	if( WriteMode == NORMAL    ) NormalWrite(User);	//通常テキスト描画
	if( WriteMode == EYECATCH  ) EyeCatching(User);	//アイキャッチ
	if( WriteMode == BACKLOG   ) BackLogMain(User);	//バックログ
	if( WriteMode == NOTWINDOW ) NotWindow();		//ウィンドウ非表示
	if( WriteMode == END	   ) GameEnd(User);		//ゲーム終了

	//メニューを選択していなければ、テキストを進める・スキップ・オート
	if( Select == OtherSelect && WriteMode == NORMAL){
		PutNextLine(User);
		//SkipFunction(User);
		AutoFunction(User);
	}
	
	//現在のカウントをセット
	SetGameData(User);
}
示例#16
0
/**
 * Implements the state machine.
 */
void StateMachine(void)
{
    char *gameend;

    State = STATE_WAITING;

    CurrentPosition = InitialPosition();
    ComputerSide = Black;

    while(State != STATE_END) {

	if(AutoSave) {
	    SaveGame(CurrentPosition, AutoSaveFileName);
	}

        switch(State) {
            case STATE_WAITING:
                if(!XBoardMode) {
                    Print(0, "%s(%d): ", 
                        CurrentPosition->turn == White ? "White":"Black", 
                        (CurrentPosition->ply/2)+1);
                }

                if(!ReadLine(InputBuffer, 1023)) {
                    State = STATE_END;
                } else {
                    struct Command *command = ParseInput(InputBuffer);
                    if(command) {
                        ExecuteCommand(command);
                        if(command->move != M_NONE) {
                            if(!ForceMode) State = STATE_CALCULATING;
                        }
                    }
                }
                break;
            case STATE_CALCULATING:
                ComputerSide = CurrentPosition->turn;
                SearchRoot(CurrentPosition);
                if(EasyMode || ForceMode) {
                    State = STATE_WAITING;
                }
                else {
                    State = STATE_PONDERING;
                }
                break;
            case STATE_PONDERING:
                switch(PermanentBrain(CurrentPosition)) {
                    case PB_NO_PB_MOVE:
                        State = STATE_WAITING;
                        break;
                    case PB_NO_PB_HIT:
                        State = ForceMode ? STATE_WAITING : STATE_CALCULATING;
                        break;
                    case PB_HIT:
                        if(EasyMode) {
                            State = STATE_WAITING;
                        }
                        break;
                }
                break;
            case STATE_ANALYZING:
		AnalysisMode(CurrentPosition);
                break;
        }

        /*
         * Check for game termination
         */

        gameend = GameEnd(CurrentPosition);
        if(gameend != NULL) {
            Print(0, "%s\n", gameend);
            if(State == STATE_ANALYZING) {
                State = STATE_WAITING;
            }
        }
    }

    FreePosition(CurrentPosition);
}
示例#17
0
文件: Game.c 项目: GURKE/Memory
int Mouse_Clicked(int *mod, int *card1, int *card2, struct Card *cards[], int amCards, SDL_Event event, int amplayers, int GameSizeX, int GameSizeY)
{
    int Types[] = { 1, 2 };
    int actcard = dist2object(&objects, event.button.x, event.button.y, Types, 2);

    if (objects[actcard].type == 2) // Button
    {
        switch (objects[actcard].button.Type) // Beenden
        {
        case 0:
            return -1;
        case 1:
            Save_Game(amplayers, amCards, cards, GameSizeX, GameSizeY);
            break;
        case 2:
            Load_Game();
            break;
        default:
            break;
        }
    }
    else
    {
        switch (*mod)
        {
        case 0:
        case 1: // tap card
            if (actcard > -1 && objects[actcard].enabled && !objects[actcard].card.visible)
            {
                if (*mod == 0)
                    *card1 = actcard;
                else
                    *card2 = actcard;

                objects[actcard].card.visible = 1;
                (*mod)++;
            }
            break;

        case 2: // Remove them or move them back
            if (objects[*card1].card.type == objects[*card2].card.type)
            {
                objects[*card1].enabled = 0;
                objects[*card2].enabled = 0;

                pairs[AktPlayer]++;

                char *c = (char *)malloc(sizeof(char));
                sprintf(c, "%d", pairs[AktPlayer]);
                objects[textfield[AktPlayer][1]].picture = Create_Picture_By_Text(objects[textfield[AktPlayer][1]].picture, concat(c, " pairs found"), 0);

                NuOfRePairs--;
                *c = (char *)malloc(sizeof(char));
                sprintf(c, "%d", NuOfRePairs);
                objects[PosOfReCards].picture = Create_Picture_By_Text(objects[PosOfReCards].picture, concat("Amount of remaining pairs: ", c), 0);

                if (NuOfRePairs == 0) // Game ends
                {
                    GameEnd(amplayers);
                }
            }
            else
            {
                objects[*card1].card.visible = 0;
                objects[*card2].card.visible = 0;

                char *c = (char *)malloc(sizeof(char));
                sprintf(c, "%d", AktPlayer + 1);
                objects[textfield[AktPlayer][0]].picture = Create_Picture_By_Text(objects[textfield[AktPlayer][0]].picture, concat("Player ", c), 0);

                AktPlayer++;
                if (AktPlayer == amplayers) AktPlayer = 0;

                sprintf(c, "%d", AktPlayer + 1);
                objects[textfield[AktPlayer][0]].picture = Create_Picture_By_Text(objects[textfield[AktPlayer][0]].picture, concat("Player ", c), 1);
            }
            *mod = 0;
            break;
        default:
            break;
        }
        paint_screen(_screen, &objects);
    }
}