예제 #1
0
 //开始游戏
 public void StartGame(Game.TTT.PlayMode mode)
 {
     currentPlayMode = mode;
     view.StartPanel.gameObject.SetActive(false);
     view.GamePanel.gameObject.SetActive(true);
     if (mode == Game.TTT.PlayMode.OnePlayerMode)
     {
         aiTurn = !view.OffensiveToggle.isOn;
         if (aiTurn)
         {
             singlePlayerAI = new TicTacToeAI(Player.Player1);
             OnGameAreaClick(singlePlayerAI.NextStep(gameState));
         }
         else
         {
             singlePlayerAI = new TicTacToeAI(Player.Player2);
         }
     }
 }
예제 #2
0
    private void OnGameAreaClick(int index)
    {
        //空白处
        if (gameState[index] == Player.None && !gameover)
        {
            gameState[index] = currentPlayer;
            GetCurrentWinState().AddStep(index);
            AddGameAreaImage(index);

            if (GetCurrentWinState().Win())
            {
                //当前玩家胜利,停止游戏
                gameover          = true;
                view.WinText.text = currentPlayer.ToString() + " Win!";
                ShowEndUI();
            }
            else // 切换玩家,继续游戏
            {
                if (CheckGameOver())
                {
                    view.WinText.text = "No Winer";
                    ShowEndUI();
                }
                else
                {
                    SwitchPlayer();
                    if (currentPlayMode == Game.TTT.PlayMode.OnePlayerMode && aiTurn == false)
                    {
                        aiTurn = true;
                        OnGameAreaClick(singlePlayerAI.NextStep(gameState));
                    }
                    else
                    {
                        aiTurn = false;
                    }
                }
            }
        }
    }