Beispiel #1
0
        static void Main(string[] args)
        {
            Board      board      = new Board();
            WinChecker winChecker = new WinChecker();
            Renderer   renderer   = new Renderer();
            Player     player1    = new Player();
            Player     player2    = new Player();

            while (!winChecker.IsDraw(board) && winChecker.Check(board) == State.Undecided)
            {
                renderer.Render(board);

                Position nextMove;
                if (board.NextTurn == State.X)
                {
                    nextMove = player1.GetPosition(board);
                }
                else
                {
                    nextMove = player2.GetPosition(board);
                }

                if (!board.SetState(nextMove, board.NextTurn))
                {
                    Console.WriteLine("That is not a legal move.");
                }
            }

            renderer.Render(board);
            renderer.RenderResults(winChecker.Check(board));

            Console.ReadKey();
        }
Beispiel #2
0
        private void genericButton_Click(object sender)
        {
            String buttonsender = ((Button)sender).Text;

            if (buttonsender == "")
            {
                if (board.NextTurn == State.X || richTextBox1.Text.Equals(RichTextHeader + "Player 1 Starts"))
                {
                    ((Button)sender).Text = "X";
                    richTextBox1.Text     = RichTextHeader + "Player 2, its your turn !";
                    board.SwitchNextTurn();
                }
                else
                {
                    ((Button)sender).Text = "O";
                    richTextBox1.Text     = RichTextHeader + "Player 1, its your turn !";
                    board.SwitchNextTurn();
                }
            }
            State currentState = winChecker.Check(board);

            if (currentState == State.X)
            {
                richTextBox1.Text = RichTextHeader + "Player 1 Won ! Congratulations";
                enableButtons(false);
            }
            else if (currentState == State.O)
            {
                richTextBox1.Text = RichTextHeader + "Player 2 Won ! Congratulations";
                enableButtons(false);
            }
            else if (winChecker.IsDraw(board))
            {
                richTextBox1.Text = RichTextHeader + "Its a draw, press Restart for another game !";
                enableButtons(false);
            }
        }