Ejemplo n.º 1
0
        public bool Command(Command command)
        {
            if (command.Order != HuntTheWumpusDotNet.Command.Commands.Invalid)
            {
                if (command.Order == HuntTheWumpusDotNet.Command.Commands.Shoot)
                {
                    TryToShootArrow(command.Direction);
                }
                else if (command.Order == HuntTheWumpusDotNet.Command.Commands.Go)
                {
                    return MovePlayer(command.Direction);
                }
                else if (command.Order == HuntTheWumpusDotNet.Command.Commands.Rest)
                {
                    Rest();
                }

                if (gameRunning && map.WumpusCavern != null)
                    map.PlaceItem(Mover.Move(map), MapItems.Wumpus);

                return true;
            }

            return false;
        }
Ejemplo n.º 2
0
 public void InvalidDirection(Command.Directions command)
 {
     var message = String.Format("You can't go {0} from here.", ConvertDirectionToString(command));
     console.WriteMessage(message);
 }
Ejemplo n.º 3
0
        private static Command ConvertStringToCommand(String direction)
        {
            var command = new Command();
            var convertedString = direction.Trim().ToUpperInvariant();
            if (convertedString.StartsWith("GO "))
            {
                command.Order = Command.Commands.Go;
                var directionString = convertedString.Substring(3);
                var convertedChar = directionString[0];
                command.Direction = ConvertCharToDirection(convertedChar);
                return command;
            }

            if (convertedString.StartsWith("SHOOT "))
            {
                command.Order = Command.Commands.Shoot;
                var directionString = convertedString.Substring(6);
                var convertedChar = directionString[0];
                command.Direction = ConvertCharToDirection(convertedChar);
                return command;
            }

            if (convertedString.StartsWith("S ") && convertedString.Substring(2).Length > 0)
            {
                command.Order = Command.Commands.Shoot;
                var directionString = convertedString.Substring(2);
                var convertedChar = directionString[0];
                command.Direction = ConvertCharToDirection(convertedChar);
                return command;
            }

            if (convertedString.StartsWith("S")
                && convertedString.Length > 1
                && convertedString[1] != 'O')
            {
                command.Order = Command.Commands.Shoot;
                var convertedChar = convertedString[1];
                command.Direction = ConvertCharToDirection(convertedChar);
                return command;
            }

            if ( convertedString.StartsWith("S") ||
                convertedString.StartsWith("W") ||
                convertedString.StartsWith("N") ||
                convertedString.StartsWith("E"))
            {
               command.Order = Command.Commands.Go;
               command.Direction = ConvertCharToDirection(convertedString[0]);
            }

            if (convertedString.StartsWith("R"))
            {
                command.Order = Command.Commands.Rest;
            }

            return command;
        }
Ejemplo n.º 4
0
 private static String ConvertDirectionToString(Command.Directions direction)
 {
     switch (direction)
     {
         case Command.Directions.East:
             return "east";
         case Command.Directions.West:
             return "west";
         case Command.Directions.North:
             return "north";
         case Command.Directions.South:
             return "south";
         default:
             throw new ArgumentException("Invalid Direction");
     }
 }
Ejemplo n.º 5
0
        protected void TryToShootArrow(Command.Directions direction)
        {
            if (player.OutOfArrows())
            {
                presenter.OutOfArrows();
                return;
            }

            if (PlayerIsPlaced())
            {
                player.Shoot();
                var arrowsCavern = FlyArrowToCavern(direction);

                if (arrowsCavern == PlayersCurrentCavern)
                {
                    presenter.Suicide();
                    GameOver();
                }
                else if (map.HasWumpusIn(arrowsCavern))
                {
                    presenter.WumpusHasBeenShot();
                    GameOver();
                }
                else
                    presenter.ArrowWasFired();
            }
        }
Ejemplo n.º 6
0
        private int FlyArrowToCavern(Command.Directions direction)
        {
            var arrowsCavern = (int) PlayersCurrentCavern;

            while (map.AvailableMoves(arrowsCavern).Contains(direction) &&
                   !map.HasWumpusIn(arrowsCavern))
            {
                arrowsCavern = map.GetCavernForMove(arrowsCavern, direction);
            }
            map.PlaceItem(arrowsCavern, MapItems.Arrow);
            return arrowsCavern;
        }
Ejemplo n.º 7
0
        protected bool MovePlayer(Command.Directions command)
        {
            if (PlayersCurrentCavern != null)
            {
                if (map.CanMove((int) PlayersCurrentCavern, command))
                {
                    map.MovePlayer(command);
                }
                else
                {
                    presenter.InvalidDirection(command);
                    return false;
                }
            }

            DisplayAvailableDirections();

            if (CanSmellTheWumpus())
            {
                presenter.WumpusCanSeeYou();
            }

            PickUpAnyArrows();
            DisplayArrowStatus();

            return true;
        }
Ejemplo n.º 8
0
        protected bool MoveRunsIntoWumpus(Command.Directions command)
        {
            var potentialCavern = map.GetCavernForMove((int) PlayersCurrentCavern, command);

            return map.HasWumpusIn(potentialCavern);
        }
Ejemplo n.º 9
0
 public int GetCavernForMove(int cavern, Command.Directions direction)
 {
     return CavePathsFor(cavern)[direction];
 }
Ejemplo n.º 10
0
 public bool CanMove(int cavern, Command.Directions direction)
 {
     return CavePathsFor(cavern).ContainsKey(direction);
 }
Ejemplo n.º 11
0
 public void AddPath(int start, int end, Command.Directions direction)
 {
     CavePathsFor(start)[direction] = end;
     CavePathsFor(end)[OppositeDirectionOf(direction)] = start;
 }
Ejemplo n.º 12
0
 protected Command.Directions OppositeDirectionOf(Command.Directions direction)
 {
     switch (direction)
     {
         case Command.Directions.West:
             return Command.Directions.East;
         case Command.Directions.East:
             return Command.Directions.West;
         case Command.Directions.South:
             return Command.Directions.North;
         case Command.Directions.North:
             return Command.Directions.South;
         default:
             return Command.Directions.East;
     }
 }
Ejemplo n.º 13
0
        public void MovePlayer(Command.Directions cavern)
        {
            if (HasPlayer())
            {
                var originalCavern = (int) PlayersCurrentCavern();

                if (cave[originalCavern].Paths.ContainsKey(cavern))
                {
                    var newCavern = cave[originalCavern].Paths[cavern];

                    cave[originalCavern].MapItems.Remove(MapItems.Player);
                    cave[newCavern].MapItems.Add(MapItems.Player);
                }
            }
        }