Beispiel #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;
        }
 public void InvalidDirection(Command.Directions command)
 {
     var message = String.Format("You can't go {0} from here.", ConvertDirectionToString(command));
     console.WriteMessage(message);
 }
        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;
        }
 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");
     }
 }
Beispiel #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();
            }
        }
Beispiel #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;
        }
Beispiel #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;
        }
Beispiel #8
0
        protected bool MoveRunsIntoWumpus(Command.Directions command)
        {
            var potentialCavern = map.GetCavernForMove((int) PlayersCurrentCavern, command);

            return map.HasWumpusIn(potentialCavern);
        }
Beispiel #9
0
 public int GetCavernForMove(int cavern, Command.Directions direction)
 {
     return CavePathsFor(cavern)[direction];
 }
Beispiel #10
0
 public bool CanMove(int cavern, Command.Directions direction)
 {
     return CavePathsFor(cavern).ContainsKey(direction);
 }
Beispiel #11
0
 public void AddPath(int start, int end, Command.Directions direction)
 {
     CavePathsFor(start)[direction] = end;
     CavePathsFor(end)[OppositeDirectionOf(direction)] = start;
 }
Beispiel #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;
     }
 }
Beispiel #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);
                }
            }
        }