Example #1
0
 public bool hasNeighbor(Room neighbor)
 {
     if (neighbors.Contains(neighbor))
         return true;
     else
         return false;
 }
Example #2
0
 public Pit(int id)
 {
     this.id = id;
     this.Type = EntityType.pit;
     location = null;
     Debug.WriteLine("Pit " + id + " is born.");
 }
Example #3
0
 public Pit(int id, Room room)
 {
     this.id = id;
     this.Type = EntityType.pit;
     location = room;
     location.addOccupant(this);
     Debug.WriteLine("Pit " + id + " is born in Room " + (location.id + 1));
 }
Example #4
0
 public Bat(string name)
 {
     //isAlive = true;
     this.name = name;
     this.Type = EntityType.bat;
     location = null;
     Debug.WriteLine("Bat " + name + " is born .");
 }
Example #5
0
 //TODO: Change the bat name to int id...
 public Bat(string name, Room room)
 {
     //isAlive = true;
     this.name = name;
     this.Type = EntityType.bat;
     location = room;
     location.addOccupant(this);
     Debug.WriteLine("Bat " + name + " is born in Room " + (location.id + 1));
 }
Example #6
0
 public Wumpus(string name)
 {
     isAlive = true;
     this.name = name;
     this.Type = EntityType.wumpus;
     metPlayer = false;
     dice = new Random();
     location = null;
     Debug.WriteLine("Wumpus is born.");
 }
Example #7
0
 public Wumpus(string name, Room room)
 {
     isAlive = true;
     this.name = name;
     this.Type = EntityType.wumpus;
     metPlayer = false;
     location = room;
     location.addOccupant(this);
     dice = new Random();
     Debug.WriteLine("Wumpus is born in Room " + (location.id + 1));
 }
Example #8
0
 public void move(Room room)
 {
     if (location == null)
     {
         location = room;
         location.addOccupant(this);
     }
     else
     {
         location.removeOccupant(this);  //leave the current room
         location = room;
         location.addOccupant(this);         //enter the new Room.
     }
     Debug.WriteLine("Pit " + id + " is now in room " + (location.id + 1));
 }
Example #9
0
        public Player(string name, Room room)
        {
            this.name = name;
            isAlive = true;
            this.Type = EntityType.player;
            //set arrows

            initArrows();
            //set location
            location = room;
            location.addOccupant(this);
            move(location);

            Debug.WriteLine("Player() : " + name + " is born in Room " + (location.id +1));
        }
Example #10
0
 public void addNeighbor(Room room)
 {
     if (hasNeighbor(room))
     {
         Debug.WriteLine("Room " + this.id + "is already neighbors with Room " + room.id);
         return;
     }
     if (neighbors.Count < maxNeighbors)
     {
         neighbors.Add(room);
         room.neighbors.Add(this);
         Debug.WriteLine("Room " + this.id + " is now neighbors with Room " + room.id);
     }
     else
         Debug.WriteLine("addNeighbor : Can't add Room " + room.id + "to Room " + this.id + " neighbors."
                          + "Room " + this.id + " already has" + neighbors.Count + " neighbors!");
 }
        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;
        }
Example #12
0
 public void move(Room room)
 {
     if (location == null)
     {
         location = room;
         location.addOccupant(this);
     }
     else
     {
         location.removeOccupant(this);  //leave the current room
         location = room;
         location.addOccupant(this);         //enter the new Room.
     }
     Debug.WriteLine("Wumpus.move() : " + name + " has moved to Room " + (location.id + 1));
 }
Example #13
0
 public void connectRooms(Room rm1, Room rm2)
 {
     rm1.addNeighbor(rm2);   //Room class auto reciprocates neighbor-adding (rm2.addNeighbor(rm1);
 }
Example #14
0
 public void addRoom(Room room)
 {
     rooms.Add(room);
 }
Example #15
0
 public void addOccupant(IEntity occupant, Room room)
 {
     occupants.Add(occupant);
     room.addOccupant(occupant);
 }
Example #16
0
 public void move(Room room)
 {
     if (location == null)
     {
         location = room;
         location.addOccupant(this);
     }
     else
     {
         location.removeOccupant(this);  //leave the current room
         location = room;
         location.addOccupant(this);         //enter the new Room.
     }
     Console.WriteLine("You are now in Room " + (location.id + 1));
     this.sense();
 }
 public void move(Room room)
 {
     location.removeOccupant(this);  //leave the current room
     location = room;
     location.addOccupant(this);         //enter the new Room.
     Debug.WriteLine("Arrow.move(): The arrow is in Room " + (location.id + 1));
     Console.WriteLine("The arrow is in Room " + (location.id + 1));
 }
        public Room getRoomString(Room current)
        {
            Room room = null;
            bool valid = false;
            while (valid != true)
            {
                Console.WriteLine("You eye the rooms you can move into {0}, {1}, {2} and pick one :", current.neighbors[0].id + 1, current.neighbors[1].id + 1, current.neighbors[2].id + 1);
                input = Console.ReadLine();
                char[] delim = { ' ', ',', '.' };
                string[] rooms = input.Split(delim);

                //check amt of rooms
                if (rooms.Length > 1)
                {
                    Console.WriteLine("One step at a time! ");
                    continue;
                }

                int j;
                // if j is a valid int and is between 1-20, convert it into a room and return it
                if (Int32.TryParse(input, out j) && j - 1 >= 0 && j - 1 < 20)
                {
                    if (current.neighbors.Contains(caveRooms[j-1]))
                    {
                        room = caveRooms[j - 1];
                        valid = true;
                    }
                }
                else
                {
                    Console.WriteLine("Not a valid room! Try again!");
                }

            }

            return room;
        }
 public List<Room> CreateRoomsList()
 {
     List <Room>rooms = new List<Room>(20);
     for (int i = 0; i < rooms.Capacity; i++)
     {
         Room room = new Room(i, 3);
         rooms.Add(room);
     }
     return rooms;
 }