Пример #1
0
 private void WinnerHook(WinnerType value)
 {
     this.winner = value;
     if (this.gameOver)
     {
         EventSystem.Publish(this, GameOverEvent);
     }
 }
Пример #2
0
        public void PrintWinner(WinnerType winner)
        {
            Console.SetCursorPosition(0, DefaultWinnerAnnoucementPosition);
            PrintLineDivider();

            WriteLineInColor(winner == WinnerType.Player ? "You won!" : "Unfortunately you lost...",
                             winner == WinnerType.Player ? ConsoleColor.Cyan : ConsoleColor.DarkRed);

            Console.WriteLine($"\nPress ENTER to quit...");
            Console.ReadLine();
        }
Пример #3
0
        /// <summary>
        /// Display winning message according to game result
        /// </summary>
        /// <param name="playerType"></param>
        private void DisplayYouWinOrGameOver(WinnerType playerType)
        {
            //game is over, hide current player name
            activePlayerText.gameObject.SetActive(false);

            switch (playerType)
            {
            case WinnerType.Human:
                Instantiate(youWinPrefab);
                break;

            case WinnerType.Cpu:
                Instantiate(gameOverPrefab);
                break;

            case WinnerType.Draw:
                Instantiate(drawPrefab);
                break;
            }
        }
Пример #4
0
        public bool HasWon()
        {
            bool firstRowWin  = this.board[0][0].Equals(this.board[0][1]) && this.board[0][0].Equals(this.board[0][2]) && !this.board[0][0].Type.Equals(CellType.Empty);
            bool secondRowWin = this.board[1][0].Equals(this.board[1][1]) && this.board[1][0].Equals(this.board[1][2]) && !this.board[1][0].Type.Equals(CellType.Empty);
            bool thirdRowWin  = this.board[2][0].Equals(this.board[2][1]) && this.board[2][0].Equals(this.board[2][2]) && !this.board[2][0].Type.Equals(CellType.Empty);

            bool firstColWin  = this.board[0][0].Equals(this.board[1][0]) && this.board[0][0].Equals(this.board[2][0]) && !this.board[0][0].Type.Equals(CellType.Empty);
            bool secondColWin = this.board[0][1].Equals(this.board[1][1]) && this.board[0][1].Equals(this.board[2][1]) && !this.board[0][1].Type.Equals(CellType.Empty);
            bool thirdColWin  = this.board[0][2].Equals(this.board[1][2]) && this.board[0][2].Equals(this.board[2][2]) && !this.board[0][2].Type.Equals(CellType.Empty);

            bool firstDiagWin  = this.board[0][0].Equals(this.board[1][1]) && this.board[0][0].Equals(this.board[2][2]) && !this.board[0][0].Type.Equals(CellType.Empty);
            bool secondDiagWin = this.board[2][0].Equals(this.board[1][1]) && this.board[2][0].Equals(this.board[0][2]) && !this.board[2][0].Type.Equals(CellType.Empty);

            if (firstRowWin)
            {
                this.Winner = WinnerType.FirstRow;
                return(true);
            }
            else if (secondRowWin)
            {
                this.Winner = WinnerType.SecondRow;
                return(true);
            }
            else if (thirdRowWin)
            {
                this.Winner = WinnerType.ThirdRow;
                return(true);
            }
            else if (firstColWin)
            {
                this.Winner = WinnerType.FirstCol;
                return(true);
            }
            else if (secondColWin)
            {
                this.Winner = WinnerType.SecondCol;
                return(true);
            }
            else if (thirdColWin)
            {
                this.Winner = WinnerType.ThirdCol;
                return(true);
            }
            else if (firstDiagWin)
            {
                this.Winner = WinnerType.FirstDiag;
                return(true);
            }
            else if (secondDiagWin)
            {
                this.Winner = WinnerType.SecondDiag;
                return(true);
            }

            bool isDraw = true;

            for (int i = 0; i < this.board.Length; i++)
            {
                if (!this.board[i].All(x => !x.Equals(new Cell())))
                {
                    isDraw = false;
                }
            }

            if (isDraw)
            {
                this.Winner = WinnerType.Draw;
                return(true);
            }

            return(false);
        }