Beispiel #1
0
        ///////////////
        // Move Methods

        public void MoveMonkey(ConsoleKey input)
        {
            var direction  = ConvertInputToDirection(input);
            var coordinate = new Coordinate(Monkey.Coordinate.X, Monkey.Coordinate.Y);

            var nextField = Maze.GetNextField(coordinate, direction);

            if (nextField.Type == FieldType.Wall)
            {
                return;
            }

            var canMove = nextField.CanWalkOn;

            var nextFloor = (Floor)nextField;

            if (nextFloor.HasBanana)
            {
                canMove = MoveBanana(nextFloor.Coordinate, direction);
            }

            if (canMove)
            {
                ((Floor)Maze.Map[Monkey.Coordinate.ToString()]).HasMonkey = false;
                Monkey.Walk(direction);
                nextFloor.HasMonkey = true;
            }
        }
Beispiel #2
0
        public void MoveForklift(ConsoleKey input)
        {
            var direction  = ConvertInputToDirection(input);
            var coordinate = new Location(Forklift.Coordinate.X, Forklift.Coordinate.Y);

            var nextField = Maze.GetNextField(coordinate, direction);

            if (nextField.Type == FieldType.Wall)
            {
                return;
            }

            var canMove = nextField.CanWalkOn;

            if (nextField.Type != FieldType.PitFall)
            {
                var nextFloor = (Floor)nextField;
                if (nextFloor.HasCrate)
                {
                    canMove = MoveCrate(nextFloor.Coordinate, direction);
                }

                if (canMove)
                {
                    if (Maze.Map[Forklift.Coordinate.ToString()].Type == FieldType.PitFall)
                    {
                        ((Pitfall)Maze.Map[Forklift.Coordinate.ToString()]).HasForklift = false;
                    }
                    else
                    {
                        ((Floor)Maze.Map[Forklift.Coordinate.ToString()]).HasForklift = false;
                    }
                    Forklift.Walk(direction);
                    nextFloor.HasForklift = true;
                }
            }
            else
            {
                var nextFloor = (Pitfall)nextField;
                if (nextFloor.HasCrate)
                {
                    canMove = MoveCrate(nextFloor.Coordinate, direction);
                }
                if (canMove)
                {
                    if (Maze.Map[Forklift.Coordinate.ToString()].Type == FieldType.PitFall)
                    {
                        ((Pitfall)Maze.Map[Forklift.Coordinate.ToString()]).HasForklift = false;
                    }
                    else
                    {
                        ((Floor)Maze.Map[Forklift.Coordinate.ToString()]).HasForklift = false;
                    }
                    if (((Pitfall)Maze.Map[nextField.Coordinate.ToString()]).GetLives() == 0)
                    {
                        IsPlaying  = false;
                        IsGameOver = true;
                    }
                    Forklift.Walk(direction);
                    nextFloor.HasForklift = true;
                }
            }
        }