private bool ValidateMove(Directions.TurtleDirections direction, int spaces)
        {
            if (direction == Directions.TurtleDirections.North && (PositionX - spaces) < 0)
            {
                Messages.InvalidMove(direction, PositionX);
                return(false);
            }

            if (direction == Directions.TurtleDirections.East && (PositionY + spaces) > GameBoard.GAME_BOARD_SIZE - 1)
            {
                Messages.InvalidMove(direction, GameBoard.GAME_BOARD_SIZE - PositionY - 1);
                return(false);
            }

            if (direction == Directions.TurtleDirections.South && (PositionX + spaces) > GameBoard.GAME_BOARD_SIZE - 1)
            {
                Messages.InvalidMove(direction, GameBoard.GAME_BOARD_SIZE - PositionX - 1);
                return(false);
            }

            if (direction == Directions.TurtleDirections.West && (PositionY - spaces) < 0)
            {
                Messages.InvalidMove(direction, PositionY);
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private bool ValidateMove(Directions.TurtleDirections direction, int spaces)
        {
            if (direction == Directions.TurtleDirections.NORTH && (PositionX - spaces) < 0)
            {
                Messages.InvalidInput();
                return(false);
            }
            else if (direction == Directions.TurtleDirections.EAST && (PositionY + spaces) > TurtleMovementArea.AreaSize)
            {
                Messages.InvalidInput();
                return(false);
            }
            else if (direction == Directions.TurtleDirections.SOUTH && (PositionX + spaces) > TurtleMovementArea.AreaSize)
            {
                Messages.InvalidInput();
                return(false);
            }
            else if (direction == Directions.TurtleDirections.WEST && (PositionY - spaces) < 0)
            {
                Messages.InvalidInput();
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
 public Game()
 {
     _turtle    = new Turtle();
     _gameBoard = new GameBoard();
     _quit      = false;
     _pen       = Pen.PenActions.Up;
     _direction = Directions.TurtleDirections.South;
 }
        internal void GameLoop()
        {
            _gameBoard.InitiateGameBoard();

            do
            {
                Console.Clear();

                Console.WriteLine(Messages.ErrorMessage);
                Messages.ErrorMessage = string.Empty;

                _gameBoard.DrawGameBoard(_turtle.PositionX, _turtle.PositionY, _turtle.TurtleSymbol);
                Messages.Instructions();
                Console.WriteLine("Pen is " + (_pen == Pen.PenActions.Down ? "drawing" : "not drawing") + ".");
                Console.WriteLine($"Turtle is moving {_direction}.");

                Console.Write("Select your option: ");
                if (int.TryParse(Console.ReadLine(), out _option))
                {
                    if (_option > 0 && _option < 3)
                    {
                        _pen = (Pen.PenActions)_option;
                    }
                    else if (_option > 2 && _option < 7)
                    {
                        _direction = (Directions.TurtleDirections)_option;
                        Console.WriteLine($"Turtle is moving {_direction}.");
                        Console.Write("Enter number of spaces to move: ");
                        int spaces;
                        if (int.TryParse(Console.ReadLine(), out spaces))
                        {
                            _turtle.Walk(_direction, spaces, _pen);
                        }
                        else
                        {
                            Messages.InvalidInput();
                        }
                    }
                    else if (_option == 7)
                    {
                        _quit = true;
                    }
                    else
                    {
                        Messages.InvalidInput();
                    }
                }
                else
                {
                    Messages.InvalidInput();
                }
            } while (!_quit);
        }
Esempio n. 5
0
        public void GameLoop()
        {
            _gameBoard.InitGameBoard();

            do
            {
                Console.Clear();                                     //prepare screen for next display
                Console.WriteLine(Messages.ErrorMessage);            //display any erro message (or blank if no error message)
                Messages.ErrorMessage = "";                          //reset error message for next input
                _gameBoard.DrawGameBoard(_turtle.PositionX, _turtle.PositionY, _turtle.TurtleSymbol);
                Messages.Instructions();                             //display game instructions
                Console.WriteLine("Pen is " + (_pen == Pen.PenActions.Down ? "DRAWING" : "NOT DRAWING"));
                Console.WriteLine($"Turtle is moving {_direction}"); //display what direction was selected
                Console.WriteLine("Select your option: ");

                if (int.TryParse(Console.ReadLine(), out _option))  //make sure input is an integer
                {
                    if (_option > 0 && _option < 3)
                    {
                        _pen = (Pen.PenActions)_option;
                    }
                    else if (_option > 2 && _option < 7)
                    {
                        _direction = (Directions.TurtleDirections)_option;
                        Console.WriteLine($"Turtle is moving {_direction}");  //display what direction was selected
                        Console.WriteLine("Enter number of spaces to move: ");
                        int spaces;
                        if (int.TryParse(Console.ReadLine(), out spaces))
                        {
                            _turtle.Walk(_direction, spaces, _pen);
                        }
                        else
                        {
                            Messages.InvalidInput();
                        }
                    }
                    else if (_option == 7)
                    {
                        _quit = true;
                    }
                    else
                    {
                        Messages.InvalidInput();
                    }
                }
                else
                {
                    Messages.InvalidInput();
                }
            } while (!_quit);
        }
Esempio n. 6
0
 public void GameLoop()
 {
     _gameBoard.InitGameBoard();
     do
     {
         Console.Clear();
         Console.WriteLine(Messages.ErrorMessage);
         Messages.ErrorMessage = "";
         _gameBoard.DrawGameBoard(_turle.PositionX, _turle.PositionY, _turle.TurtleSymbol);
         Messages.Instructions();
         Console.WriteLine(_pen);
         Console.WriteLine("Select your option: ");
         if (int.TryParse(Console.ReadLine(), out _option))
         {
             if (_option > 0 && _option < 3)
             {
                 _pen.PenAction = (Pen.PenActions)_option;
             }
             else if (_option > 2 && _option < 7)
             {
                 Directions.TurtleDirections direction = (Directions.TurtleDirections)_option;
                 Console.WriteLine($"Turtle is moving {direction}");
                 Console.WriteLine("Enter number of spaces to move: ");
                 int spaces;
                 if (int.TryParse(Console.ReadLine(), out spaces))
                 {
                     _turle.Walk(direction, spaces, _pen.PenAction);
                 }
                 else
                 {
                     Messages.InvalidInput();
                 }
             }
             else if (_option == 7)
             {
                 _quit = true;
             }
             else
             {
                 Messages.InvalidInput();
             }
         }
         else
         {
             Messages.InvalidInput();
         }
     } while (!_quit);
 }
Esempio n. 7
0
        //walk is calculated based on selected direction, number of spaces, and pen action (up = no draw, down = to draw)
        public void WalkX(Directions.TurtleDirections direction, int step)
        {
            if (ValidateMove(direction, step))
            {
                switch (direction)
                {
                case Directions.TurtleDirections.NORTH:
                    PositionX -= step;
                    break;

                case Directions.TurtleDirections.SOUTH:
                    TurtleMovementArea.UpdateMovementAreaX(PositionX, step, +1, PositionY);
                    PositionX += step;
                    break;
                }
            }
        }
Esempio n. 8
0
        public void WalkY(Directions.TurtleDirections direction, int step)
        {
            if (ValidateMove(direction, step))
            {
                switch (direction)
                {
                case Directions.TurtleDirections.EAST:
                    TurtleMovementArea.UpdateMovementAreaY(PositionY, step, +1, PositionX);
                    PositionY += step;
                    break;

                case Directions.TurtleDirections.WEST:
                    TurtleMovementArea.UpdateMovementAreaY(PositionY, step, -1, PositionX);
                    PositionY -= step;
                    break;
                }
            }
        }
        internal void Walk(Directions.TurtleDirections direction, int spaces, Pen.PenActions pen)
        {
            if (ValidateMove(direction, spaces))
            {
                bool toDraw = (pen == Pen.PenActions.Down);

                switch (direction)
                {
                case Directions.TurtleDirections.North:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardX(PositionX, spaces, -1, PositionY);
                    }
                    PositionX -= spaces;
                    break;

                case Directions.TurtleDirections.South:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardX(PositionX, spaces, 1, PositionY);
                    }
                    PositionX += spaces;
                    break;

                case Directions.TurtleDirections.East:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardY(PositionY, spaces, 1, PositionX);
                    }
                    PositionY += spaces;
                    break;

                case Directions.TurtleDirections.West:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardY(PositionY, spaces, -1, PositionX);
                    }
                    PositionY -= spaces;
                    break;
                }
            }
        }
Esempio n. 10
0
 public static void InvalidMove(Directions.TurtleDirections direction, int spaces)
 {
     ErrorMessage = $"\nINVALID MOVE. You can only move {spaces} spaces to the {direction}\n";
 }
Esempio n. 11
0
 internal static void InvalidMove(Directions.TurtleDirections direction, int spaces)
 {
     ErrorMessage = $"\nInvalid move. You can only move {spaces} spaces to the {direction}.";
 }