예제 #1
0
        private void Panel_Click(object sender, EventArgs e)
        {
            if (_gameState != GameState.Playing)
            {
                _board.Clear();

                foreach (Panel panel in _panels)
                {
                    panel.BackColor = Color.White;
                    panel.BackgroundImage = null;
                }

                _gameState = GameState.Playing;

                return;
            }

            Panel clickedPanel = sender as Panel;
            int indexToBoard = int.Parse(clickedPanel.Name[clickedPanel.Name.Length - 1].ToString());

            if (!_board.IsLegalMove(indexToBoard))
            {
                return;
            }

            _board.Put(indexToBoard, Board.Player.Human);
            clickedPanel.BackgroundImage = Properties.Resources.XPiece;

            if (_board.IsFull() || _board.GetWinner() != Board.Player.None)
            {
                GameOver();
            }
            else
            {
                DoComputerMove();
            }
        }
예제 #2
0
        private void GameOver()
        {
            int[] winnerPositions;
            Board.Player winner = _board.GetWinner(out winnerPositions);

            if (winner != Board.Player.None)
            {
                foreach (int winnerPosition in winnerPositions)
                {
                    _panels[winnerPosition].BackColor = Color.Yellow;
                }

                if (winner == Board.Player.Human)
                {
                    humanScoreLabel.Text = (int.Parse(humanScoreLabel.Text) + 1).ToString();
                }
                else
                {
                    computerScoreLabel.Text = (int.Parse(computerScoreLabel.Text) + 1).ToString();
                }
            }

            _gameState = GameState.GameOver;
        }
예제 #3
0
 static void Main(string[] args)
 {
     GameState MainGame;
     MainGame = new GameState();
     MainGame.MainGameLoop();
 }