コード例 #1
0
ファイル: Map.cs プロジェクト: willbush/hunt-the-wumpus
        public Map(bool isCheatMode)
        {
            IsCheatMode = isCheatMode;
            var occupiedRooms = new HashSet <int>();

            Player = new Player(GetRandomAvailableRoom(occupiedRooms));
            Wumpus = new Wumpus(GetRandomAvailableRoom(occupiedRooms));

            var bottomlessPit1 = new BottomlessPit(GetRandomAvailableRoom(occupiedRooms));
            var bottomlessPit2 = new BottomlessPit(GetRandomAvailableRoom(occupiedRooms));
            var superbats1     = new SuperBats(GetRandomAvailableRoom(occupiedRooms));
            var superbats2     = new SuperBats(GetRandomAvailableRoom(occupiedRooms));

            _hazards = new List <Hazard> {
                Wumpus, bottomlessPit1, bottomlessPit2, superbats1, superbats2
            };
            _deadlyHazards = new List <DeadlyHazard> {
                Wumpus, bottomlessPit1, bottomlessPit2
            };
            _superBats = new List <SuperBats> {
                superbats1, superbats2
            };

            _roomsWithStaticHazards = new HashSet <int> {
                superbats1.RoomNumber,
                superbats2.RoomNumber,
                bottomlessPit1.RoomNumber,
                bottomlessPit2.RoomNumber
            };

            if (IsCheatMode)
            {
                PrintHazards();
            }
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: willbush/hunt-the-wumpus
        /// <summary>
        ///     Reset map state to its initial state.
        /// </summary>
        public void Reset()
        {
            Player.Reset();
            Wumpus.Reset();

            if (IsCheatMode)
            {
                PrintHazards();
            }
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: willbush/hunt-the-wumpus
        /// <summary>
        ///     Updates the state of the game on the map.
        /// </summary>
        public void Update()
        {
            Console.WriteLine();
            Wumpus.Update(this);

            HashSet <int> roomsAdjacentToPlayer = Rooms[Player.RoomNumber];

            _hazards.ForEach(
                h => {
                if (roomsAdjacentToPlayer.Contains(h.RoomNumber))
                {
                    h.PrintHazardWarning();
                }
            });
            Player.PrintLocation();
        }
コード例 #4
0
        public void fly(List<Room> path, Room current, Wumpus target)
        {
            Random rand = new Random();

            location = current;
            location.addOccupant(this);
            int flightLength = 0;

            //TODO: this is ugly, clean up later
            foreach (Room room in path)
            {   //check current length of flight
                if (flightLength < maxFlight)
                {
                    if (location.hasOccupant(target))
                    {
                        target.die();
                        Console.WriteLine("Aha! You got the Wumpus!");
                        return;
                    }
                    //check if rooms are connected
                    if (location.hasNeighbor(room))
                    {
                        move(room);
                    }
                    else
                    {
                        Console.WriteLine("Room " + (location.id + 1) + " is not neighbors with Room " + (room.id + 1)
                                            + "! Picking another room...");
                        int i = rand.Next(0, location.neighbors.Count - 1);
                        move(location.neighbors[i]);
                    }
                    if (location == current)
                    {
                        Console.WriteLine("Ouch! The arrow got you!");
                        break;
                    }
                    flightLength++;
                }
                else
                    Console.WriteLine(" The arrow can only traverse up to 5 rooms!");
            }
            Console.WriteLine("Missed!");
            target.wake();  //wake the wumpus if you miss
            used = true;
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: imperialsoup/HuntTheWumpus
 public void shootArrow(List<Room> path, Wumpus target)
 {
     if (arrowCount > 0)
     {
         Console.WriteLine(name + " has shot a crooked arrow. " + arrowCount + " crooked arrows are left.");
         arrows[0].fly(path, location, target);
         arrows.Remove(arrows[0]);
         arrowCount--;
     }
     if (arrowCount <= 0)
     {
         Console.WriteLine("Out of arrows!");
     }
 }
コード例 #6
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //TestCave testCave = new TestCave();
            //TestPlayer testplayer = new TestPlayer();
            //TestPlayerRoom testplayerroom = new TestPlayerRoom();
            //TestArrow testarrow = new TestArrow();
            //TestRoom testroom = new TestRoom();

            /*real gameplay stuff */
            numBats = numPits = 2;

            initCave();
            input = new InputProcessor(rooms);
            player = new Player("Hunter");
            wumpus = new Wumpus("Wumpy");
            bats = new List<Bat>(numBats);
            pits = new List<Pit>(numPits);
            //init bats & pits
            for (int i = 0; i < numPits;i++ )
            {
                Bat bat = new Bat(i.ToString());
                bats.Add(bat);
                Pit pit = new Pit(i);
                pits.Add(pit);
            }

            positions = new int[6]; //hard coded 6 entities... >_<
            setup(1);

            base.Initialize();
        }
コード例 #7
0
        public Map(int seed)
        {
            // Seeding allows us to play the same map
            random = new Random(seed);
            // Create list of rooms and their adjacent rooms
            // Start at index 1 to make life easy
            Rooms = new int[21][] {
                new int [] { -1, -1, -1 }, // 0 not an actual room
                new int [] { 2, 5, 8 },
                new int [] { 1, 3, 10 },
                new int [] { 2, 4, 12 },
                new int [] { 3, 5, 14 },
                new int [] { 1, 4, 6 },
                new int [] { 5, 7, 15 },
                new int [] { 6, 8, 17 },
                new int [] { 1, 7, 9 },
                new int [] { 8, 10, 18 },
                new int [] { 2, 9, 11 },
                new int [] { 10, 12, 19 },
                new int [] { 3, 11, 13 },
                new int [] { 12, 14, 20 },
                new int [] { 4, 13, 15 },
                new int [] { 6, 14, 16 },
                new int [] { 15, 17, 20 },
                new int [] { 7, 16, 18 },
                new int [] { 9, 17, 19 },
                new int [] { 11, 18, 20 },
                new int [] { 13, 16, 19 }
            };

            Entities = new List <Entity>();

            // Generate a list of random rooms by shuffling
            // a list of numbers from 1 to number of rooms
            // We skip room 1 because that's for the Player
            var randomRooms = new int[19];

            for (int k = 2; k <= 20; k++)
            {
                randomRooms[k - 2] = k;
            }
            randomRooms = randomRooms.OrderBy(x => random.Next()).ToArray();

            // Create all the entities reading off the random positions one by one
            // This makes sure nothing is initially in the same room
            int randCount = 0;

            for (int k = 0; k < NumBats; k++)
            {
                Entities.Add(new Bat(this, randomRooms[randCount++]));
            }
            for (int k = 0; k < NumPits; k++)
            {
                Entities.Add(new Pit(this, randomRooms[randCount++]));
            }

            // Wumpus and Player are special, so they're not in the entity list
            Wumpus = new Wumpus(this, randomRooms[randCount++]);
            Player = new Player(this, 1);

            playing = true;
        }
コード例 #8
0
        public static void PlayHuntTheWumpus(StreamReader reader, StreamWriter writer)
        {
            //Creating a player and a wumpus.
            Player player1 = new Player();
            Wumpus wumpus = new Wumpus();

            //Player initially starts in cave 1.
            EnterCave(player1, 1, writer);

            //Player is prompted for a next action.
            ChooseNextAction(player1, reader, writer);
        }