示例#1
0
        private static void Main(string[] args)
        {
            TicTacToeEngine t = new TicTacToeEngine();

            Console.WriteLine(t.Board());

            String input = Console.ReadLine();

            while (input != "exit")
            {
                if (input != "reset")
                {
                    int value;
                    if (int.TryParse(input, out value))
                    {
                        if (t.ChooseCell(value))
                        {
                            t.AssignCell(value);
                            t.CheckWinner();
                            Console.WriteLine(t.Board());
                        }

                        input = Console.ReadLine();
                    }
                }
                else
                {
                    t.reset();
                    Console.WriteLine(t.Board());
                    input = Console.ReadLine();
                }
            }
        }
示例#2
0
        private void button_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            b.Text    = t.AssignCell(Int32.Parse(b.Name.Substring(b.Name.Length - 1)));
            b.Enabled = false;
            t.CheckWinner();
            if (t.Gamestate != GameState.PlayerOPlays && t.Gamestate != GameState.PlayerXPlays)
            {
                String message = "status: " + t.Gamestate.ToString();
                if (t.Gamestate == GameState.PlayerOWins)
                {
                    message = "Gefeliciteerd! Speler O wint";
                }
                else if (t.Gamestate == GameState.PlayerXWins)
                {
                    message = "Gefeliciteerd! Speler X wint";
                }
                else if (t.Gamestate == GameState.Equal)
                {
                    message = "Gelijkspel! Geen speler wint";
                }
                System.Windows.Forms.MessageBox.Show(message);
            }
        }