예제 #1
0
		/// <summary>
		/// Single player mode
		/// </summary>
		/// <param name="gameLogic"></param>
		/// <param name="models"></param>
		/// <param name="gameSettings"></param>
		#region private static void FSM_SinglePlayer(...)
		private static void FSM_SinglePlayer(Connect4Game gameLogic, GameSettings gameSettings, IBoard board)
		{
			switch (gameLogic.GameState)
			{
			case GameSettings.GAMESTATE.S_BeforeGame:
			{
				if (gameLogic.STARTING_PLAYER == gameSettings.RED_PLAYER)
				{
					gameLogic.GameState = GameSettings.GAMESTATE.S_Player1Move;
					gameLogic.HUMAN_PLAYER = gameSettings.RED_PLAYER;
				}
				else
				{
					gameLogic.GameState = GameSettings.GAMESTATE.S_WaitForCPU;
					gameLogic.HUMAN_PLAYER = gameSettings.YELLOW_PLAYER;
				}

				break;
			}
			case GameSettings.GAMESTATE.S_Player1Move:
			{
				//HandleMouseInput(gameSettings, gameLogic);
				
				//HandleKeyInput(gameSettings, gameLogic);
				
				break;
			}
			case GameSettings.GAMESTATE.S_DropPlayerStone:
			{
				if (board.DropStone(gameLogic))
				{
					if (board.Bounce())
						gameLogic.GameState = GameSettings.GAMESTATE.S_SwitchPlayer;
				}
				
				break;
			}
			case GameSettings.GAMESTATE.S_SwitchPlayer:
			{
				// Change player
				gameLogic.SwitchPlayer();
				
				gameLogic.CheckIfFinished();
				
				
				if (gameLogic.NextGameState == GameSettings.GAMESTATE.S_GameFinished)
				{
					gameLogic.GameState = GameSettings.GAMESTATE.S_GameFinished;
				}
				else
				{
					board.SwitchStones(gameLogic);
					
					if (gameLogic.activePlayer == gameSettings.RED_PLAYER)
					{
						// Reset stone position for the next new stone
						gameLogic.SetNextPlayerStone();
						
						gameLogic.GameState = GameSettings.GAMESTATE.S_Player1Move;
					}
					else
					{
						gameLogic.GameState = GameSettings.GAMESTATE.S_WaitForCPU;
					}
				}
				
				break;
			}
			case GameSettings.GAMESTATE.S_WaitForCPU:
			{
				// Start the AI
				if (!gameLogic.AIStarted)
				{
					gameLogic.CPUMove();
				}
				
				if (gameLogic.NextGameState == GameSettings.GAMESTATE.S_DropCPUStone)
				{
					gameLogic.AbortAI();

					board.Update(gameLogic.column * board.ColumnDistance);
					
					gameLogic.GameState = GameSettings.GAMESTATE.S_DropCPUStone;
				}
				break;
			}
			case GameSettings.GAMESTATE.S_DropCPUStone:
			{
				if (board.DropStone(gameLogic))
				{
					if (board.Bounce())
						gameLogic.GameState = GameSettings.GAMESTATE.S_SwitchPlayer;
				}
				
				break;
			}
			case GameSettings.GAMESTATE.S_GameFinished:
			{
				IsFinished = true;
				break;
			}
			}
		}