Ejemplo n.º 1
0
        public void GameSimulationMoveTurtleTest()
        {
            Simulation game = new Simulation(10, 10);

            Enums.Result target = game.MoveTurtle();
            Assert.IsNotNull(target);
            Assert.IsInstanceOfType(target, typeof(Enums.Result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Move turtle.
        /// </summary>
        /// <param name="isGameRunning">Flag if game instance created.</param>
        /// <param name="game">Instance of the game, if existing.</param>
        private static Enums.Result MoveTurtle(bool isGameRunning, ref Simulation game)
        {
            Enums.Result result = Enums.Result.Continue;

            if (isGameRunning)
            {
                Console.Clear();
                result = game.MoveTurtle();
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Check if turtle has moved succesfully without hitting a mine or if it has reached the goal.
 /// </summary>
 /// <param name="isGameRunning">Flag if game instance created.</param>
 /// <param name="game">Instance of the game, if existing.</param>
 /// <param name="result">Result with the outcome of the game.</param>
 private static void CheckGame(ref bool isGameRunning, ref Simulation game, Enums.Result result)
 {
     if (isGameRunning && result.Equals(Enums.Result.Win))
     {
         Console.Clear();
         Console.WriteLine("Congratulations! You have done it!");
         isGameRunning = false;
     }
     else if (isGameRunning && result.Equals(Enums.Result.Loss))
     {
         Console.Clear();
         Console.WriteLine("You have lost :( Better luck next time.");
         isGameRunning = false;
     }
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            bool       isGameRunning = false;
            Simulation game          = null;

            Enums.Result result = Enums.Result.Continue;

            string welcome = "Welcome to the game Escape Mines. You have to help the hero in this case a turtle escape the mine field. The turtle is represented by an arrow pointing in whichever direction it is currently going to move forward. You can rotate the direction left or right using the left and right arrows on your keyboard. You can move by pressing the letter 'm'. Your goal is to reach the exit which is represented by the letter 'e', careful not to hit the mines though. The mines are represented by an 'x'. To start the game you need to configure the difficulty of the game by entering height and width of the mine field. When you are ready, please press the spacebar. Enjoy!";

            Console.Write(WordWrap(welcome));

            Console.Write("Height: ");
            string height          = Console.ReadLine();
            int    validatedHeight = 0;

            ValidateUserInput(ref height, ref validatedHeight);

            Console.Write("Length: ");
            string length          = Console.ReadLine();
            int    validatedLength = 0;

            ValidateUserInput(ref length, ref validatedLength);

            ConsoleKeyInfo keyInfo;

            while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Escape)
            {
                switch (keyInfo.Key)
                {
                case ConsoleKey.M:
                    result = MoveTurtle(isGameRunning, ref game);
                    CheckGame(ref isGameRunning, ref game, result);
                    break;

                case ConsoleKey.RightArrow:
                    RotateTurtle(isGameRunning, ref game, false);
                    break;

                case ConsoleKey.LeftArrow:
                    RotateTurtle(isGameRunning, ref game, true);
                    break;

                case ConsoleKey.Spacebar:
                    StartGame(validatedLength, validatedHeight, ref isGameRunning, ref game);
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Moves turtle checks if mine or exit hit.
        /// </summary>
        public Enums.Result MoveTurtle()
        {
            Enums.Result result = Enums.Result.Continue;

            if (turtleDirection.Equals(Enums.Directions.North) && turtlePosition.y > 0)
            {
                turtlePosition = new Point(turtlePosition.x, turtlePosition.y - 1);
            }
            else if (turtleDirection.Equals(Enums.Directions.West) && turtlePosition.x > 0)
            {
                turtlePosition = new Point(turtlePosition.x - 1, turtlePosition.y);
            }
            else if (turtleDirection.Equals(Enums.Directions.South) && turtlePosition.y < numColumns - 1)
            {
                turtlePosition = new Point(turtlePosition.x, turtlePosition.y + 1);
            }
            else if (turtleDirection.Equals(Enums.Directions.East) && turtlePosition.x < numRows - 1)
            {
                turtlePosition = new Point(turtlePosition.x + 1, turtlePosition.y);
            }

            DrawGame();

            foreach (Point mine in mines)
            {
                if (turtlePosition.Equals(mine))
                {
                    result = Enums.Result.Loss;
                }
            }

            if (turtlePosition.Equals(exit))
            {
                result = Enums.Result.Win;
            }

            return(result);
        }