Ejemplo n.º 1
0
 public void TestGameInitialGrid()
 {
     Game testGame = new Game();
     string resultField = testGame.GetGridAsString();
     string expected = string.Format(
         "{0}" +
         "UL 01234567 UR{0}" +
         "   ________   {0}" +
         "0 |A+B+C+D+| 0{0}" +
         "1 |+-+-+-+-| 1{0}" +
         "2 |-+-+-+-+| 2{0}" +
         "3 |+-+-+-+-| 3{0}" +
         "4 |-+-+-+-+| 4{0}" +
         "5 |+-+-+-+-| 5{0}" +
         "6 |-+-+-+-+| 6{0}" +
         "7 |+-+K+-+-| 7{0}" +
         "  |________|  {0}" +
         "DL 01234567 DR{0}{0}",
         Environment.NewLine);
     Assert.AreEqual<string>(expected, resultField);
 }
Ejemplo n.º 2
0
        public static void Main()
        {
            Game game = new Game();

            while (!game.GameIsFinished)
            {
                Console.Clear();
                Console.SetCursorPosition(0, 0);
                Console.WriteLine(game.GetGridAsString());

                string message;
                message = game.KingIsOnTheMove ? "Please enter king's turn: " : "Please enter pawn's turn: ";

                while (true)
                {
                    Console.Write(message);
                    string userInput = GetUserInput();

                    if (userInput == string.Empty)
                    {
                        Console.WriteLine("Please enter something!");
                        continue;
                    }

                    if (game.ValidateCommand(userInput))
                    {
                        if (ExecuteCommand(userInput, game))
                        {
                            break;
                        }
                        else
                        {
                            if (game.CheckIfAllPawnsAreStuck())
                            {
                                Console.WriteLine("King wins!");
                            }
                            else if (game.CheckIfKingIsStuck())
                            {
                                Console.WriteLine("King loses!");
                            }
                            else
                            {
                                Console.WriteLine("You can't go in this direction! ");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Illegal move!");
                    }
                }

                if (game.CheckIfKingExited())
                {
                    Console.WriteLine("End!");
                    Console.WriteLine("King wins in {0} moves!", game.KingTurns);
                    break;
                }
            }

            Console.WriteLine("Game is finished!");
            Console.WriteLine("\nThank you for using this game!\n\n");
        }