Example #1
0
        public static void Main2(string[] args)
        {
            // Setting up the game.
            TTTGame curGame = new TTTGame();

            Console.WriteLine("This is a new TTT game");

            while (!curGame.IsGameFinished())
            {
                // Ask for index to place player sign.
                Console.WriteLine("its " + curGame.GetCurrentPlayer() + " turn, please type position: ");
                int.TryParse(Console.ReadLine(), out int x);
                int.TryParse(Console.ReadLine(), out int y);

                // try to place the sign and respond if not available.
                if (!curGame.TryToPlacePiece(x, y))
                {
                    Console.WriteLine("that position is marked / unavailable, please try again.");
                }

                // Print the current game table.
                Console.WriteLine(curGame.GetCurrentTable());
            }

            // Output according to result
            Console.WriteLine(GetWinnerString(curGame.GetWinner()));
        }
Example #2
0
        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton button = sender as RadioButton;

            if (button.Checked)
            {
                // If pressed, rename & deactivate the button.
                button.Text    = curGame.GetCurrentPlayer().ToString();
                button.Enabled = false;

                // Check which button was pressed.
                for (int x = 0; x < 3; x++)
                {
                    for (int y = 0; y < 3; y++)
                    {
                        if (button == buttons[x, y])
                        {
                            curGame.TryToPlacePiece(x, y);
                            ColorButton(button, Color.Black);
                            break;
                        }
                    }
                }

                // push-down all the buttons if the game is over.
                if (curGame.IsGameFinished())
                {
                    FinishTasks();
                }
            }
        }