Example #1
0
 public void TestValidateCommandEmptyString()
 {
     Game game = new Game();
     game.MovesCount = 2;
     bool result = game.ValidateCommand(string.Empty);
     Assert.AreEqual(false, result);
 }
Example #2
0
 public void TestCoordinatesInBoardRandomValues()
 {
     BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
     Game game = new Game();
     int[] values = new int[] { 8, 7 };
     object[] arguments = new object[] { values };
     MethodInfo testedMethod = typeof(Game).GetMethod("CheckIfInBoard", bindingFlags);
     bool result = (bool)testedMethod.Invoke(game, arguments);
     Assert.AreEqual(true, result);
 }
Example #3
0
 public void TestGetKingDestinationUpRight()
 {
     BindingFlags bindingnFlags = BindingFlags.Instance | BindingFlags.NonPublic;
     Game game = new Game();
     int[] coordinates = new int[] { 9, 6 };
     object[] arguments = new object[] { coordinates, 'U', 'R' };
     MethodInfo testedMethod = typeof(Game).GetMethod("GetKingDestination", bindingnFlags);
     int[] result = (int[])testedMethod.Invoke(game, arguments);
     int[] expected = new int[] { 8, 7 };
     CollectionAssert.AreEqual(expected, result);
 }
        public static bool ExecuteCommand(string cmd, Game game)
        {
            char startLetter = cmd[0];
            int[] oldCoordinates = new int[2];
            int[] coords = new int[2];

            if (startLetter == 'K')
            {
                return game.PlayKingMove(cmd[1], cmd[2]);
            }
            else if (startLetter == 'A' || startLetter == 'B' || startLetter == 'C' || startLetter == 'D')
            {
                return game.PlayPawnMove(startLetter, cmd[1]);
            }
            else
            {
                throw new ArgumentException("Attempting to move a non existing figure!");
            }
        }
Example #5
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);
 }
Example #6
0
 public void TestValidateCommandValidKingInputUpRight()
 {
     Game game = new Game();
     game.MovesCount = 2;
     bool result = game.ValidateCommand("KUR");
     Assert.AreEqual(true, result);
 }
Example #7
0
 public void TestValidateCommandValidDPawnCommand()
 {
     Game game = new Game();
     game.MovesCount = 1;
     bool result = game.ValidateCommand("DL");
     Assert.AreEqual(true, result);
 }
Example #8
0
 public void TestValidateCommandPawnCommandEmptyString()
 {
     Game game = new Game();
     game.MovesCount = 1;
     bool result = game.ValidateCommand(string.Empty);
 }
Example #9
0
 public void TestValidateCommandKingInputInvalidCommand()
 {
     Game game = new Game();
     game.MovesCount = 2;
     bool result = game.ValidateCommand("KFC");
     Assert.AreEqual(false, result);
 }
Example #10
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");
        }
Example #11
0
 public void TestPlayKingMoveUpRight()
 {
     Game game = new Game();
     bool result = game.PlayKingMove('U', 'R');
     bool expected = true;
     Assert.AreEqual(expected, result);
 }
Example #12
0
 public void TestGetPawnDestinationDownLeft()
 {
     BindingFlags bindingnFlags = BindingFlags.Instance | BindingFlags.NonPublic;
     Game game = new Game();
     int[] values = new int[] { 2, 5 };
     object[] arguments = new object[] { values, 'L' };
     MethodInfo testedMethod = typeof(Game).GetMethod("GetPawnDestination", bindingnFlags);
     int[] result = (int[])testedMethod.Invoke(game, arguments);
     int[] expected = new int[] { 3, 4 };
     CollectionAssert.AreEqual(expected, result);
 }
Example #13
0
 public void TestPlayPawnIsStuck()
 {
     Game game = new Game();
     game.PlayPawnMove('A', 'L');
     bool result = game.CheckIfAllPawnsAreStuck();
     bool expected = false;
     Assert.AreEqual(expected, result);
 }
Example #14
0
 public void TestPlayPawnInvalidPawn()
 {
     Game game = new Game();
     game.PlayPawnMove('E', 'R');
 }
Example #15
0
 public void TestPlayPawnDMoveRight()
 {
     Game game = new Game();
     bool result = game.PlayPawnMove('D', 'R');
     bool expected = true;
     Assert.AreEqual(expected, result);
 }
Example #16
0
 public void TestPlayPawnAMoveLeft()
 {
     Game game = new Game();
     bool result = game.PlayPawnMove('A', 'L');
     bool expected = false;
     Assert.AreEqual(expected, result);
 }
Example #17
0
 public void TestValidateCommandInvalidPawnCommand()
 {
     Game game = new Game();
     game.MovesCount = 1;
     bool result = game.ValidateCommand("SL");
     Assert.AreEqual(false, result);
 }
Example #18
0
 public void TestPlayKingMoveDownRight()
 {
     Game game = new Game();
     bool result = game.PlayKingMove('D', 'R');
     bool expected = false;
     Assert.AreEqual(expected, result);
 }