Beispiel #1
0
        //initializes a random new game
        public static void Initialize(ref bool play, out Map cave, out Player player,
                                      out Wumpus wumpus, out SuperBats bats, out Pit pitA,
                                      out Pit pitB)
        {
            //will start the main game loop later
            play = true;

            //initialize object locations
            int[] locations = generateLocations();

            //creates a new map
            cave = new Map(20, locations[0], locations[1], locations[2],
                           locations[3], locations[4]);

            //creates the player
            player = new Player(cave.Oloc[0]);
            //creates the wumpus
            wumpus = new Wumpus(cave.Oloc[1]);
            //creates a group of super bats
            bats = new SuperBats(cave.Oloc[2]);
            //creates a pit
            pitA = new Pit(cave.Oloc[3]);
            //creates a pit
            pitB = new Pit(cave.Oloc[4]);

            Console.WriteLine("HUNT THE WUMPUS - A new cave has been generated");
        }
Beispiel #2
0
        public Map(GraphicsDevice graphicsDevice, bool isCheatMode = false)
        {
            _graphicsDevice = graphicsDevice;
            IsCheatMode     = isCheatMode;
            CreateRooms();
            var occupiedRooms = new HashSet <int>();

            Player = new Player(GetRandomAvailableRoom(occupiedRooms), this);
            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();
            }
        }
Beispiel #3
0
        //update on the character's status
        public static void Update(ref bool play, ref Map cave, ref Player player, ref Wumpus wumpus,
                                  ref SuperBats bats, ref Pit pitA, ref Pit pitB)
        {
            //wumpus logic
            if (wumpus.Awake)
            {
                wumpus.move(cave);

                if (wumpus.Room == player.Room)
                {
                    player.Alive = false;
                    play         = false;
                }
            }

            //player logic
            if (player.Alive)
            {
                bool turn = true;
                //continues checking input until it is valid
                while (turn)
                {
                    //gets input
                    String move = Console.ReadLine();

                    //parses input
                    //if the player chose to move
                    if (string.Compare(move, 0, "M", 0, 1, true) == 0)
                    {
                        //prompts for room number
                        Console.WriteLine("Tunnels connect to " + cave.Rooms[cave.Cloc[0]].Adj[0] + " " + cave.Rooms[cave.Cloc[0]].Adj[1] +
                                          " " + cave.Rooms[cave.Cloc[0]].Adj[2]);
                        Console.WriteLine("What room would you like to move to?");
                        move = Console.ReadLine();

                        //parses the room number
                        int room;
                        int.TryParse(move, out room);
                        bool valid = true;

                        //checks input against the adjacent rooms
                        for (int i = 0; i < 3; i++)
                        {
                            if (room == cave.Rooms[cave.Cloc[0]].Adj[i])
                            {
                                player.move(ref cave, room);
                                break;
                            }
                            else if (i == 2)
                            {
                                Console.WriteLine("Not possible");
                                Console.WriteLine("Please (S)hoot or (M)ove");
                                valid = false;
                            }
                        }
                        if (!valid)
                        {
                            continue;
                        }
                    }
                    else if (string.Compare(move, 0, "S", 0, 1, true) == 0)
                    {
                        player.shoot(ref cave, ref wumpus);
                    }
                    else
                    {
                        //invalid input, ask for reentry of input
                        Console.WriteLine("Invalid Input");
                        Console.WriteLine("Please (S)hoot or (M)ove");
                        continue;
                    }
                    turn = false;
                }
            }
            else
            {
                Console.WriteLine("The Wumpus ate you! Game Over!");
            }
        }