示例#1
0
        static void Main(string[] args)
        {
            var ui = new UI();

            var spieler   = "X";
            var kommando  = "neu";
            var spielfeld = TicTacToe.Spielfeld_neu();
            var gewinner  = "";

            while (kommando != "ende" && gewinner == "")
            {
                ui.Spielfeld_ausgeben(spielfeld);
                kommando = ui.Kommando_lesen();

                spielfeld = TicTacToe.Kommando_ausführen(spielfeld, kommando, spieler);
                gewinner  = TicTacToe.Gewinner_ermitteln(spielfeld, spieler);
                kommando  = ui.Gewinner_ausgeben(gewinner, kommando);
                spieler   = TicTacToe.Spieler_festlegen(kommando, spieler);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
myLabel:
            Console.WriteLine(" Please enter x or y ");
            char playerMarker;

            //as long as the first character is x or y we are happy
            try
            {
                playerMarker = Console.ReadLine()[0];
            }
            catch (IndexOutOfRangeException)
            {
                //just in case input is empty
                //we loop back to our question
                goto myLabel;
            }

            if (playerMarker != 'x' && playerMarker != 'y')
            {
                goto myLabel;
            }

            //create game
            TicTacToe myGame = new TicTacToe(playerMarker);

            myGame.PrintIndexBoard();
            // Console.ReadLine();
            AI  computerPlayer = new AI();
            int spot           = computerPlayer.PickSpot(myGame);

            for (int i = 0; i < 40; i++)
            {
                spot = computerPlayer.PickSpot(myGame);
                Console.WriteLine(spot);
            }



            Console.ReadLine();
        }
示例#3
0
 public void Button_play_Click(object sender, EventArgs e)
 {
     TicTacToe.SetOnePlayerName(Txt_player.Text);
     this.Close();
 }
示例#4
0
        static void Main(string[] args)
        {
            TicTacToe game = new TicTacToe(3);

            // Initial board

            Console.WriteLine(Figgle.FiggleFonts.Standard.Render("Tic Tac Toe"));
            // TODO: Move to readme.txt file
            WriteLine("Hi There! Greetings!!");
            WriteLine("This is very simple TicTacToe 3X3 board game between you as player and COmputer as another player");
            WriteLine("However, this does not make any smart computer moves..means more chances for you to win.");
            WriteLine("Hint: Computer makes a random Dumb moves");

            WriteLine();
            WriteLine("How to..");
            WriteLine("\tThis simple game will allow you to make first play");
            WriteLine("\tTo play your position, type matrix coordinate of 3x3 board e.g. for Row 0, Col 0 , enter 00 OR To play Row 2, Col 1 -> Enter 21 with no quotes and so on");
            WriteLine();
            WriteLine("Caution: This is initial draft version and not fully tested for all moves and may contain issues/Bugs");
            WriteLine("Coming soon in next version...smart Computer move algorithm");
            WriteLine("Enjoy!!!");

            bool keepPlaying = true;
            bool gameStarted = false;

            while (keepPlaying)
            {
                if (gameStarted)
                {
                    Clear();
                }

                gameStarted = true;

                game.Print();

                while (game.Result == null)
                {
                    WriteLine(@"Play your position: (e.g. for Row 0, Col 0 , enter 00 OR To play Row 2, Col 1 -> type 21 (with no quotes) and Hit ENTER and so on)");
                    string pos = ReadLine();

                    var move = game.PlayerMove(pos);

                    if (move == -1)
                    {
                        WriteLine($"You played {pos} out of range or invalid..pls try again");
                        continue;
                    }

                    if (move == 0)
                    {
                        WriteLine($"You played {pos} which is already played..pls try again");
                        continue;
                    }

                    if (game.Result == null)
                    {
                        game.computerMove();
                    }

                    Clear();
                    game.Print();
                }

                switch (game.Result)
                {
                case 1:
                    WriteLine("Congrates, you WON!!");
                    break;

                case -1:
                    WriteLine("Sorry computer won, try again");
                    break;

                case 0:
                    WriteLine("Oops! Its Tie");
                    break;
                }

                WriteLine("Would you like to play again? (Y/N)");
                string ans = "";

                while (true)
                {
                    ans = ReadLine();
                    if (ans.Equals("Y") || ans.Equals("N"))
                    {
                        break;
                    }
                    else
                    {
                        WriteLine("Invalid input, pls try again...");
                    }
                }


                if (ans.Equals("N"))
                {
                    keepPlaying = false;
                }
                else
                {
                    game.ResetBoard();
                }
            }
        }
 public TTTBoard()
 {
     InitializeComponent();
     game = new TicTacToe(this);
 }
示例#6
0
 public ViewController(TicTacToe main) : base(main)
 {
     Main  = main;
     _form = new FormMatch(this);
     _form.Show();
 }
示例#7
0
 private void button_play_Click(object sender, EventArgs e)
 {
     TicTacToe.SetPlayerNames(Txt_player1.Text, Txt_player2.Text);
     this.Close();
 }