Beispiel #1
0
        public static void Run()
        {
            var playerOne = new Player(Player.GetName(), "O");
            var context   = new ValidationContext(playerOne);

            playerOne.Name = Validate(playerOne.Name, "Name", context);
            var playerTwo = new Player(Player.GetName(), "X");

            playerTwo.Name = Validate(playerTwo.Name, "Name", context);


            var dimensions = Game.GetDimensions();
            var testGame   = new Game(playerOne, playerTwo, dimensions);

            testGame.Board.PrintBoard();

            while (testGame.Turns < dimensions * dimensions)
            {
                var coordsResult  = new List <ValidationResult>();
                var coordsXY      = Coords.CoordsInput(testGame.CurrentPlayer.Name);
                var coordsContext = new ValidationContext(coordsXY);

                coordsXY.XY = Validate(coordsXY.XY, "XY", coordsContext);
                var validTurn = testGame.Board.Move(Coords.TakeCoords(coordsXY.XY), testGame.CurrentPlayer.Symbol);
                if (validTurn == true)
                {
                    testGame.Board.PrintBoard();
                    var checkWin = testGame.Board.Win(testGame.CurrentPlayer.Symbol);
                    if (checkWin == true)
                    {
                        Console.WriteLine($"The {testGame.CurrentPlayer.Symbol}'s have won!");
                        break;
                    }

                    testGame.Turns++;
                }
            }
            Console.WriteLine("What a game");
        }