Beispiel #1
0
 public void setVisited(Room room)
 {
     if (!room.isExit())
     {
         bool wasVisited = sVisitedRooms[fRoom.getRoomNumber() - 1];
         sVisitedRooms[fRoom.getRoomNumber() - 1] = true;
         if (!wasVisited)
         {
             GameEngine.instance.fMaze.setExplored(room);
         }
     }
 }
Beispiel #2
0
 public bool isExplored(Room room)
 {
     Utility.Assert(room.getRoomNumber() <= sExploredRooms.Length, "Maze.isExplored - room.getRoomNumber() < sExploredRooms.length");
     if (room.getRoomNumber() > sExploredRooms.Length)
     {
         return(false);
     }
     if (room.isExit())
     {
         return(false);
     }
     return(sExploredRooms[room.getRoomNumber() - 1]);
 }
Beispiel #3
0
 public static bool hasVisited(Room room)
 {
     Utility.Assert(room.getRoomNumber() <= sVisitedRooms.Length, "Player.hasVisited - room.getRoomNumber() < sVisitedRooms.length");
     if (room.getRoomNumber() > sVisitedRooms.Length)
     {
         return(false);
     }
     if (room.isExit())
     {
         return(false);
     }
     return(sVisitedRooms[room.getRoomNumber() - 1]);
 }
Beispiel #4
0
        public String getShortDescription()
        {
            String str = Convert.ToString(this.getRoomNumber()) + ":";

            for (int iPassage = 1; iPassage <= this.getNumPassages(); iPassage++)
            {
                str = str + " " + this.getPassage(iPassage).getRoomNumber();
            }
            if (this.hasDoor())
            {
                str += " (";
                if (!this.isDoorLocked())
                {
                    Room door = this.fDoor;
                    if (door.isExit())
                    {
                        str += "exit";
                    }
                    else
                    {
                        str += door.getRoomNumber();
                    }
                }
                str += ")";
            }
            return(str);
        }
Beispiel #5
0
        public void addPassage(Room room)
        {
            Utility.Assert(room != this, "Room.addPassage - room != this");
            Utility.Assert(!this.hasPassage(room), "Room.addPassage - !this.hasPassage(room)");
            Utility.Assert(fNumPassages < kMaxPassages, "Room.addPassage - fNumPassages < kMaxPassages");
            // find insertion point
            int ins;

            for (ins = 0; ins < fNumPassages; ins++)
            {
                if (fPassages[ins].getRoomNumber() > room.getRoomNumber())
                {
                    break;
                }
            }
            Utility.Assert(ins >= 0, "Room.addPassage - ins >= 0");
            Utility.Assert(ins <= fNumPassages, "Room.addPassage - ins <= fNumPassages");
            for (int i = fNumPassages; i > ins; i--)
            {
                fPassages[i] = fPassages[i - 1];
            }

            fPassages[ins] = room;
            fNumPassages++;
//		System.Array.Sort(fPassages, 0, fNumPassages);
        }
Beispiel #6
0
        public String toString()
        {
            String str = "Room " + this.getRoomNumber() + " Exits (";

            for (int iPassage = 1; iPassage <= this.getNumPassages(); iPassage++)
            {
                if (iPassage > 1)
                {
                    str = str + ", ";
                }
                str = str + this.getPassage(iPassage).getRoomNumber();
            }
            str = str + ")";
            if (this.hasDoor())
            {
                str += " door: ";
                Room door = this.fDoor;
                if (door == null)
                {
                    str += "exit";
                }
                else
                {
                    str += door.getRoomNumber();
                }
            }
//		str += "\n";
            return(str);
        }
Beispiel #7
0
        //	public int getHearing()
        //	{
        //		return 1;
        //	}
        override public void process()
        {
            base.process();

            Room room = this.huntPrey();

            if (room != null)
            {
                // move three times in five
                if (GameEngine.rand.range(1, 5) <= 3)
                {
                    this.move(room);
                }
                else
                {
                    this.rest();
                }
                return;
            }

            // No one to hunt, rest three times in five
            if (GameEngine.rand.range(1, 5) <= 3)
            {
                this.rest();
                return;
            }

            if (this.fRoom == fTarget)
            {
                // find another target
                do
                {
                    room = GameEngine.instance.fMaze.getRoom(GameEngine.rand.range(1, GameEngine.instance.fMaze.getNumRooms()));
                } while (room == fTarget);
                fTarget = room;
            }

            Room[] path = GameEngine.instance.fMaze.findRoute(fRoom, fTarget, null, Maze.USE_OPEN_DOORS);
            //		Utility.Assert(path.length > 0, "Balrog.process - path.length > 0");
            if (path.Length > 0)
            {
                Utility.Trace("The Balrog is going to room " + fTarget.getRoomNumber() + " via " + path[0].getRoomNumber());
                this.move(path[0]);
            }
            else
            {
                room = this.fRoom.getRandomPassage();
                if (room != null)
                {
                    Utility.Trace("The Balrog is moving randomly to cavern " + room.getRoomNumber());
                    this.move(room);
                }
            }
        }
Beispiel #8
0
 public void openPortcullis(Room toRoom)
 {
     Utility.Trace("Room " + this.getRoomNumber() + ".openPortcullis(room " + toRoom.getRoomNumber() + ")");
     for (int i = 0; i < fNumPassages; ++i)
     {
         if (fPassages[i] == toRoom)
         {
             Utility.Assert(fPortcullis[i] == kPortcullisClosed, "Room.openPortcullis - opening portcullis that is not closed");
             fPortcullis[i] = kPortcullisOpen;
             return;
         }
     }
     Utility.Assert(false, "Room.openPortcullis - opening portcullis that does not exist");
 }
Beispiel #9
0
        public String getAdjacentPlayerDescription()
        {
            String str = "";

            for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++)
            {
                Room room = null;
                if (iPassage == 0)
                {
                    if (!this.hasDoor() || !this.isDoorOpen())
                    {
                        continue;
                    }
                    room = this.fDoor;
                }
                else
                {
                    room = this.getPassage(iPassage);
                }
                if (!room.isExit())
                {
                    String strPlayers = "";
                    Player player     = GameEngine.instance.getCurrentPlayer();
                    for (int iPlayer = 1; iPlayer <= GameEngine.instance.fNumPlayers; iPlayer++)
                    {
                        Player pl = GameEngine.instance.getPlayer(iPlayer);
                        if (pl != player && pl.isAlive() && pl.fRoom == room)
                        {
                            if (strPlayers != "")
                            {
                                strPlayers += " ";
                            }
                            strPlayers += pl.fName;
                        }
                    }

                    if (strPlayers != "")
                    {
                        str += room.getRoomNumber() + ": " + strPlayers + "\n";
                    }
                }
            }

            return(str);
        }
Beispiel #10
0
        public void setExplored(Room room)
        {
            if (!room.isExit())
            {
//          bool wasExplored = sExploredRooms[room.getRoomNumber() - 1];
                sExploredRooms[room.getRoomNumber() - 1] = true;
//          if (!wasExplored)
//          {
//              bool done = true;
//              for (int i = 0; i < this.getNumRooms(); i++)
//              {
//                  if (!sExploredRooms[i])
//                  {
//                      done = false;
//                      break;
//                  }
//              }
//              if (done)
//              {
//                  fExplored = true;
//              }
//          }
            }
        }
Beispiel #11
0
        override public void displayMove(Room room)
        {
            fShooting = false;
            String str = "There are passages leading to:";

            System.Console.WriteLine(str);
            for (int i = 1; i <= room.getNumPassages(); i++)
            {
                if (room.isPassable(i))
                {
                    Room otherRoom = room.getPassage(i);
                    str = "(" + otherRoom.getRoomNumber() + ")";
                    Player player = fEngine.getCurrentPlayer();
                    if (Player.hasVisited(otherRoom))
                    {
                        if (player.fLastRoom == otherRoom)
                        {
                            str = "[" + Convert.ToString(otherRoom.getRoomNumber()) + "]";
                        }
                        else
                        {
                            str = Convert.ToString(otherRoom.getRoomNumber());
                        }
                    }
                    str = str + " ";
                    System.Console.Write(str);
                }
            }
            if (room.hasDoor() && room.isDoorOpen())
            {
                str = "Door: ";
                System.Console.Write(str);
                Room otherRoom = room.fDoor;
                str = "(" + otherRoom.getRoomNumber() + ")";
                Player player = fEngine.getCurrentPlayer();
                if (otherRoom.isExit())
                {
                    str = "exit";
                }
                else if (Player.hasVisited(otherRoom))
                {
                    if (player.fLastRoom == otherRoom)
                    {
                        str = "<" + Convert.ToString(otherRoom.getRoomNumber()) + ">";
                    }
                    else
                    {
                        str = Convert.ToString(otherRoom.getRoomNumber());
                    }
                }
                str = str + " ";
                System.Console.Write(str);
            }

            System.Console.WriteLine();
            int  no     = 0;
            Room toRoom = null;

            while (true)
            {
                no     = this.readNumber();
                toRoom = fMaze.getRoom(no);
                if (room.hasPassage(toRoom) || room.fDoor == toRoom)
                {
                    break;
                }
                else
                {
                    System.Console.WriteLine("No passage leads to " + no);
                }
            }
            fEngine.doMove(toRoom);
        }
Beispiel #12
0
        override public void displayKill(Monster[] monsters, Room room, Staff staff, bool splinter)
        {
            fShotsFired++;
            bool magic = false;

            if (staff != null)
            {
                magic = true;
            }
            Player player = fEngine.getCurrentPlayer();
            String str    = "";

            if (player.fRoom == room)
            {
                if (magic)
                {
                    str = "You fire a lightning bolt with your " + Staff.TYPE_STRING[staff.getType()] + " staff!\n";
                }
            }
            else
            {
                if (magic)
                {
                    str = "You fire a lightning bolt to cavern " + room.getRoomNumber() + ".\n";
                }
                else
                {
                    str = "You fire an arrow to cavern " + room.getRoomNumber() + ".\n";
                }
            }

            if (splinter)
            {
                str += "Your " + Staff.TYPE_STRING[staff.getType()] + " staff splintered!\n";
                if (fShooting)
                {
                    fShotsFired = player.getNumBolts();
                }
                else
                {
                    fShotsFired = player.getNumBalls();
                }
                int damage = GameEngine.rand.range(0, 2);
                player.applyDamage(damage);
                if (!player.isAlive())
                {
                    str += "\nYou're dead.\n";
                }
                player.makeNoise(Player.kFightNoise);
            }

            if (monsters.Length == 0)
            {
                str += "That wasn't very clever, was it?";
            }

            for (int i = 0; i < monsters.Length; i++)
            {
                Monster monster = monsters[i];
                if (monster.isAlive())
                {
                    str += "You wounded ";
                }
                else
                {
                    str += "You killed ";
                }
                str += monster.getMonsterDescription() + "\n";
            }
            System.Console.WriteLine(str);

            if (fShooting)
            {
                if (fEngine.hasAdjacentMonster(player.fRoom))
                {
                    if (!magic && fShotsFired < player.getMaxNumShots() && player.fArrows > 0)
                    {
                        fEngine.doCommandShootArrow();
                        return;
                    }
                    if (magic && fShotsFired < player.getNumBolts() && player.hasChargedStaff())
                    {
                        fEngine.doCommandCastLightningBolt();
                        return;
                    }
                }
            }
            else
            {
                if (fEngine.hasMonster(player.fRoom))
                {
                    if (magic && fShotsFired < player.getNumBalls() && player.hasChargedStaff())
                    {
                        fEngine.doCommandCastFireball();
                        return;
                    }
                }
            }

            fEngine.processNextPlayer();
        }
Beispiel #13
0
        public Room[] findRoute(Room fromRoom, Room toRoom, Player player, int useDoors)
        {
//      Utility.Assert(player == null || useDoors != USE_LOCKED_DOORS, "player == null || useDoors != USE_LOCKED_DOORS");
            Utility.Assert(fromRoom != null, "Maze.findRoute - fromRoom != null");
            Utility.Assert(toRoom != null, "Maze.findRoute - toRoom != null");
            String str = "null";

            if (player != null)
            {
                str = player.fName;
            }
            Utility.Trace("Maze.findRoute: " + fromRoom.toString() + ", " + toRoom.toString() + ", " + str + ", " + useDoors);

            if (fromRoom == toRoom)
            {
                Utility.Trace("from equals to, return empty path");
                Room[] path = new Room[0];
                return(path);
            }

            int[] room_path = new int[fNumRooms + 1];
            for (int i = 0; i <= fNumRooms; i++)
            {
                room_path[i] = 999;
            }
            room_path[fromRoom.getRoomNumber()] = 1000 + fromRoom.getRoomNumber();

            Utility.Trace("Maze.findRoute: searching maze...");

            bool done = false;

            while (!done)
            {
                bool exhausted = true;
                for (int iRoom = 0; iRoom <= fNumRooms; iRoom++)
                {
                    if (room_path[iRoom] >= 1000)
                    {
                        room_path[iRoom] = room_path[iRoom] - 1000;
                        if (iRoom == toRoom.getRoomNumber())
                        {
                            done      = true;
                            exhausted = false;
                            break;
                        }
                        Room room = this.getRoom(iRoom);
//					if (player == null && room.hasMuck())
//						continue;
                        for (int iPassage = 1; iPassage <= room.getNumPassages(); iPassage++)
                        {
                            if (room.isPassable(iPassage) || useDoors >= USE_PORTCULLIS)
                            {
                                Room tmpRoom = room.getPassage(iPassage);
                                if (player == null || Player.hasExplored(room) || Player.hasExplored(tmpRoom))
                                {
                                    if (room_path[tmpRoom.getRoomNumber()] == 999)
                                    {
                                        room_path[tmpRoom.getRoomNumber()] = -iRoom;
                                    }
                                }
                            }
                        }
                        if (room.hasDoor())
                        {
                            bool allowDoor = true;
                            if (player != null)
                            {
                                if (room.isDoorLocked())
                                {
                                    if (useDoors < Maze.USE_LOCKED_DOORS)
                                    {
                                        allowDoor = false;
                                    }
                                }
                            }
                            else
                            {
                                if (room.isDoorLocked())
                                {
                                    if (useDoors < Maze.USE_LOCKED_DOORS)
                                    {
                                        allowDoor = false;
                                    }
                                }
                                else if (!room.isDoorOpen())
                                {
                                    if (useDoors < Maze.USE_CLOSED_DOORS)
                                    {
                                        allowDoor = false;
                                    }
                                }
                                else
                                {
                                    if (useDoors < Maze.USE_OPEN_DOORS)
                                    {
                                        allowDoor = false;
                                    }
                                }
                            }
//						if ((player == null && useLockedDoors) || !room.isDoorLocked())
                            if (allowDoor)
                            {
                                Room door = room.fDoor;
//							Utility.Assert(player == null || player.hasVisited(room) || player.hasVisited(door), "Maze.findRoute - player == null || player.hasVisited(room) || player.hasVisited(door)");
                                if (player == null || Player.hasExplored(room) || Player.hasExplored(door))
                                {
                                    if (room_path[door.getRoomNumber()] == 999 && !door.isExit())
                                    {
                                        room_path[door.getRoomNumber()] = -iRoom;
                                    }
                                }
                            }
                        }
                        exhausted = false;
                    }
                }
                for (int iRoom = 0; iRoom <= fNumRooms; iRoom++)
                {
                    if (room_path[iRoom] <= 0)
                    {
                        room_path[iRoom] = 1000 - room_path[iRoom];
                    }
                }

                if (exhausted)
                {
                    done = true;
                }
            }

            if (room_path[toRoom.getRoomNumber()] == 999)
            {
                Utility.Trace("Maze.findRoute: found no path, return empty path");
                Room[] aRoom = new Room[0];
                return(aRoom);
            }

            Utility.Trace("Maze.findRoute: found path, backtracking...");

            int count   = 0;
            int current = toRoom.getRoomNumber();

            while (current != fromRoom.getRoomNumber())
            {
                count++;
                current = room_path[current];
                Utility.Assert(current > 0, "Maze.findRoute - current > 0");
                Utility.Assert(current < 999, "Maze.findRoute - current < 999");
            }

            Utility.Trace("Maze.findRoute: path is " + count + " rooms");

            Room[] rooms = new Room[count];
            current = toRoom.getRoomNumber();
            for (int i = count; i > 0; i--)
            {
                rooms[i - 1] = this.getRoom(current);
                current      = room_path[current];
            }
            Utility.Assert(current == fromRoom.getRoomNumber(), "Maze.findRoute - current == fromRoom.getRoomNumber()");
            // Remove this code! Causes a crash...
//		if (GameEngine.rand.range(1, 5) == 1)
//		{
//			rooms[0] = null;
//			rooms[1] = null;
//		}

            str = "" + rooms[0].getRoomNumber();
            for (int j = 1; j < rooms.Length; j++)
            {
                str += "-" + rooms[j].getRoomNumber();
            }
            Utility.Trace("Maze.findRoute: returning path: " + str);

            return(rooms);
        }
Beispiel #14
0
        public String getAdjacentMonsterDescription()
        {
            String str = "";

            for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++)
            {
                Room room = null;
                if (iPassage == 0)
                {
                    if (!this.hasDoor() || !this.isDoorOpen())
                    {
                        continue;
                    }
                    room = this.fDoor;
                }
                else
                {
                    room = this.getPassage(iPassage);
                }
                Utility.Assert(room != null, "Room.getAdjacentDescription - room != null");
                if (room.fPit)
                {
                    str += "You can feel a draft.\n";
                }
            }
            for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++)
            {
                Room room = null;
                if (iPassage == 0)
                {
                    if (!this.hasDoor() || !this.isDoorOpen())
                    {
                        continue;
                    }
                    room = this.fDoor;
                }
                else
                {
                    room = this.getPassage(iPassage);
                }
                Utility.Assert(room != null, "Room.getAdjacentDescription - room != null (2)");
                if (room.hasMuck())
                {
//				str += "It stinks of serpent-muck.\n";
                    str += "It stinks in here.\n";
                }
            }
            for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++)
            {
                Room room = null;
                if (iPassage == 0)
                {
                    if (!this.hasDoor() || !this.isDoorOpen())
                    {
                        continue;
                    }
                    room = this.fDoor;
                }
                else
                {
                    room = this.getPassage(iPassage);
                }
                Utility.Assert(room != null, "Room.getAdjacentDescription - room != null (5)");
                if (GameEngine.instance.fMaze.isJanitor(room) && (room.hasMuck() || room.fPit))
                {
                    //				str += "Someone is cleaning in cavern " + room.getRoomNumber() + ".\n";
                    str += "Someone is cleaning nearby.\n";
                }
            }
            for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++)
            {
                Room room = null;
                if (iPassage == 0)
                {
                    if (!this.hasDoor() || !this.isDoorOpen())
                    {
                        continue;
                    }
                    room = this.fDoor;
                }
                else
                {
                    room = this.getPassage(iPassage);
                }
                Utility.Assert(room != null, "Room.getAdjacentDescription - room != null (3)");
                if (room.fDragonSwords > 0 || room.fSerpentShields > 0 || room.fSandals > 0 || room.hasStaffs() || room.fRing != 0)
                {
                    if (Player.fKnowsItems || Player.hasExplored(room))
                    {
                        // Check if the player really wants the item
                        //
                        bool   wants  = false;
                        Player player = GameEngine.instance.getCurrentPlayer();
                        if (room.fDragonSwords > 0 && player.fDragonSwords < player.getMaxNumDragonSwords())
                        {
                            wants = true;
                        }
                        else if (room.fSerpentShields > 0 && player.fSerpentShields < player.getMaxNumSerpentShields())
                        {
                            wants = true;
                        }
                        else if (room.fSandals > 0 && (player.fSandals == 0))
                        {
                            wants = true;
                        }
                        if ((room.fRing | player.fRing) != player.fRing)
                        {
                            wants = true;
                        }
                        else if (room.hasStaffs() && player.getMaxNumStaffs() > 0)
                        {
                            Staff best = room.fStaffs.getBestStaff();
                            if (player.wantsStaff(best))
                            {
                                wants = true;
                            }
                        }

                        if (wants)
                        {
                            str += "You feel a potent power from cavern " + room.getRoomNumber() + ".\n";
                        }
                    }
                    else
                    {
                        str += "You feel a potent power.\n";
                    }
                }
            }
            for (int iPassage = 0; iPassage <= this.getNumPassages(); iPassage++)
            {
                Room room = null;
                if (iPassage == 0)
                {
                    if (!this.hasDoor() || !this.isDoorOpen())
                    {
                        continue;
                    }
                    room = this.fDoor;
                }
                else
                {
                    room = this.getPassage(iPassage);
                }
                Utility.Assert(room != null, "Room.getAdjacentDescription - room != null (4)");
            }
            return(str);
        }
Beispiel #15
0
        public void process()
        {
            Utility.Trace("Maze.process");
            for (int iRoom = 1; iRoom <= fNumRooms; iRoom++)
            {
                Room room = this.getRoom(iRoom);
                room.process();
            }

            // Wizard
            //
            Room aRoom = fWizard;

            while (aRoom == fWizard && fWizard != null)
            {
                int no = GameEngine.rand.range(1, this.getNumRooms());
                aRoom = this.getRoom(no);
                if (aRoom.hasMuck())
                {
                    Utility.Trace("The wizard disposed of muck in cavern " + aRoom.getRoomNumber());
                    aRoom.removeMuck();
                }
                break;
            }
            fWizard = aRoom;

            Utility.Trace("Maze.process - janitor");
            // Janitor
            //
            if (fJanitor != null)
            {
                Utility.Trace("Janitor path: " + this.getJanitorPath());
                if (fJanitor.fWeb)
                {
                    Utility.Trace("The janitor is removing a web in cavern " + fJanitor.getRoomNumber());
                    if (GameEngine.rand.range(1, 2) == 1)
                    {
                        Utility.Trace("The janitor removed a web in cavern " + fJanitor.getRoomNumber());
                        fJanitor.fWeb = false;
                    }
                }
                else if (fJanitor.fPit)
                {
                    Utility.Trace("The janitor is filling in pit in cavern " + fJanitor.getRoomNumber());
                    if (GameEngine.rand.range(1, 2) == 1)
                    {
                        Utility.Trace("The janitor filled in pit in cavern " + fJanitor.getRoomNumber());
                        fJanitor.fPit = false;
                    }
                }
                else if (fJanitor.hasMuck())
                {
                    Utility.Trace("The janitor is cleaning up muck in cavern " + fJanitor.getRoomNumber());
                    if (GameEngine.rand.range(1, 3) == 1)
                    {
                        Utility.Trace("The janitor cleaned up muck in cavern " + fJanitor.getRoomNumber());
                        fJanitor.removeMuck();
                    }
                }
                else
                {
                    if (fJanitor.getRoomNumber() == fJanitorTarget.getRoomNumber())
                    {
                        while (fJanitor.getRoomNumber() == fJanitorTarget.getRoomNumber())
                        {
                            int no = GameEngine.rand.range(1, this.getNumRooms());
                            if (!this.getRoom(no).isLair())
                            {
                                no = GameEngine.rand.range(1, this.getNumRooms());
                            }
                            fJanitorTarget = this.getRoom(no);
                        }

                        // Set new target! Help adventurer if any.
                        Room target = null;
                        int  thirst = GameEngine.rand.range(0, 20);
                        for (int iPlayer = 1; iPlayer <= GameEngine.instance.fNumPlayers; iPlayer++)
                        {
                            Player player = GameEngine.instance.getPlayer(iPlayer);
                            if (player.isAlive() && !player.hasEscaped() && player.fWater <= thirst)
                            {
                                target = player.fRoom;
                                thirst = player.fWater;
                                Utility.Trace("The janitor detects a thirsty player in cavern " + player.fRoom.getRoomNumber());
                            }
                        }

                        if (target != null && target != fJanitor)
                        {
                            fJanitorTarget = target;
                            Utility.Trace("The janitor is rescuing a thirsty player in cavern " + target.getRoomNumber());
                        }
                    }

                    // take one step towards the target
                    Room[] path = GameEngine.instance.fMaze.findRoute(fJanitor, fJanitorTarget, null, Maze.USE_EVERYTHING);
                    Utility.Assert(path.Length > 0, "Maze.process - path.length > 0");
                    Utility.Trace("The janitor is moving towards " + fJanitorTarget.getRoomNumber() + " via " + path[0].getRoomNumber());
                    aRoom = path[0];

                    int num = fJanitor.getNumPassages();
                    if (fJanitor.hasDoor() && !fJanitor.isExitDoor() /* && !fJanitor.isDoorLocked() */)
                    {
                        num++;
                    }
                    Room tmp = aRoom;
                    for (int i = 0; i < num; i++)
                    {
                        if (tmp.hasMuck())
                        {
                            aRoom = tmp;
                            Utility.Trace("The janitor smells muck in cavern " + aRoom.getRoomNumber());
                            break;
                        }
                        if (tmp.fPit)
                        {
                            aRoom = tmp;
                            Utility.Trace("The janitor feels a draft from cavern " + aRoom.getRoomNumber());
                            break;
                        }
                        if (tmp.fWeb)
                        {
                            aRoom = tmp;
                            Utility.Trace("The janitor sees a web in cavern " + aRoom.getRoomNumber());
                            break;
                        }
                        if (fJanitor.isBlockedByPortcullis(tmp))
                        {
                            Utility.Trace("The janitor raises the portcullis between cavern " + fJanitor.getRoomNumber() + " and " + tmp.getRoomNumber());
                            fJanitor.openPortcullis(tmp);
                            tmp.openPortcullis(fJanitor);
                        }
                        int no = GameEngine.rand.range(1, num);
                        if (no > fJanitor.getNumPassages())
                        {
                            tmp = fJanitor.fDoor;
                        }
                        else
                        {
                            tmp = fJanitor.getPassage(no);
                        }
                    }

                    if (fJanitorUnlockedDoor != null)
                    {
                        if (!fJanitorUnlockedDoor.isDoorJammed())
                        {
                            if (fJanitorUnlockedDoor.isDoorOpen())
                            {
                                Utility.Trace("The janitor closes the door between cavern " + fJanitor.getRoomNumber() + " and " + fJanitorUnlockedDoor.getRoomNumber());
                                fJanitorUnlockedDoor.closeDoor();
                                fJanitor.closeDoor();
                            }
                            if (!fJanitorUnlockedDoor.isDoorLocked())
                            {
                                Utility.Trace("The janitor locks the door between cavern " + fJanitor.getRoomNumber() + " and " + fJanitorUnlockedDoor.getRoomNumber());
                                fJanitorUnlockedDoor.lockDoor();
                                fJanitor.lockDoor();
                            }
                        }
                        fJanitorUnlockedDoor = null;
                    }
//				if (fJanitorRaisedPortcullis != null)
//				{
//					Utility.Trace("The janitor lowers the portcullis between cavern " + fJanitor.getRoomNumber() + " and " + fJanitorRaisedPortcullis.getRoomNumber());
//					fJanitor.closePortcullis();
//					fJanitorRaisedPortcullis.closePortcullis();
//				}
                    if (fJanitor.hasDoor() && fJanitor.fDoor == aRoom)
                    {
                        if (fJanitor.isDoorLocked())
                        {
                            Utility.Trace("The janitor unlocks the door between cavern " + fJanitor.getRoomNumber() + " and " + aRoom.getRoomNumber());
                            fJanitor.unlockDoor();
                            aRoom.unlockDoor();
                            fJanitorUnlockedDoor = fJanitor;
                        }
                        if (!fJanitor.isDoorOpen())
                        {
                            Utility.Trace("The janitor opens the door between cavern " + fJanitor.getRoomNumber() + " and " + aRoom.getRoomNumber());
                            fJanitor.openDoor();
                            aRoom.openDoor();
                        }
                    }
                    if (fJanitor.isBlockedByPortcullis(aRoom))
                    {
                        Utility.Trace("The janitor raises the portcullis between cavern " + fJanitor.getRoomNumber() + " and " + aRoom.getRoomNumber());
                        fJanitor.openPortcullis(aRoom);
                        aRoom.openPortcullis(fJanitor);
                    }
                    Utility.Trace("The janitor moves to cavern " + aRoom.getRoomNumber());
                    fJanitor = aRoom;
                }
            }
            fPlayerInWeb = false;
            Utility.Trace("Maze.process - done");
        }
Beispiel #16
0
//	public Room getLair()
//	{
//		return fLair;
//	}
        public Room getRandomLair(bool force_create)
        {
            // Find room without door and only one entrance
            int  passages   = 1;
            bool allow_door = false;

            while (true)
            {
                Sequence seq = new Sequence(2, this.getNumRooms());
                //seq.remove(fHermit.getRoomNumber());
                seq.remove(this.getRoom(1).getPassage(1).getRoomNumber());
                seq.remove(this.getRoom(1).getPassage(2).getRoomNumber());
                while (seq.count() > 0)
                {
                    int  no   = seq.remove();
                    Room room = this.getRoom(no);
                    if (room.isLair())
                    {
                        continue;
                    }
                    if ((allow_door || !room.hasDoor()) && room.getNumPassages() <= passages)
                    {
                        while (room.getNumPassages() > 1)
                        {
                            Room other = room.getRandomPassage();
                            if (other != null && other.getRoomNumber() != 1)
                            {
                                room.removePassage(other);
                                other.removePassage(room);
                                Room[] path = this.findRoute(room, other, null, USE_LOCKED_DOORS);
                                if (path.Length == 0)
                                {
                                    room.addPassage(other);
                                    other.addPassage(room);
                                    // try another room
                                    break;
                                }
                            }
                        }
                        if (room.getNumPassages() <= 1)
                        {
                            return(room);
                        }
                    }
                }
                if (allow_door)
                {
                    if (force_create)
                    {
                        passages++;
                        if (passages > 3)
                        {
                            return(null);
                        }
                        allow_door = false;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    allow_door = true;
                }
            }
            return(null);    // uncomment
//		return this.getRoom(1);
        }
Beispiel #17
0
        public void initialize()
        {
            Utility.Trace("Maze - initialize");

            if (GameEngine.instance.fDungeon.fCompleted)
            {
                sExploredRooms = new bool[GameEngine.kMaxNumRooms];
                for (int i = 0; i < GameEngine.kMaxNumRooms; i++)
                {
                    sExploredRooms[i] = true;
                }
            }
            else
            {
                sExploredRooms = new bool[GameEngine.kMaxNumRooms];

                for (int i = 0; i < GameEngine.kMaxNumRooms; i++)
                {
                    sExploredRooms[i] = false;
                }
            }

            int no;     // = GameEngine.rand.range(2, fNumRooms);

            // each room should have at least two exits
            for (int iRoom = 1; iRoom <= fNumRooms; iRoom++)
            {
                Room room = this.getRoom(iRoom);

                // each room shall have two exits
                for (int iPassage = 1; iPassage <= 2; iPassage++)
                {
                    Sequence seq = new Sequence(2, fNumRooms);
                    seq.remove(iRoom);
                    bool hasPassage = false;
                    do
                    {
                        no         = seq.remove();
                        hasPassage = false;
                        if (room.hasPassage(this.getRoom(no)))
                        {
                            hasPassage = true;
                        }
                        Room tmpRoom = this.getRoom(no);
                        if (tmpRoom.hasPassage(this.getRoom(iRoom)))
                        {
                            hasPassage = true;
                        }
                    } while (seq.count() > 0 && hasPassage);
                    if (!hasPassage)
                    {
                        room.addPassage(this.getRoom(no));
                    }
                }
            }

            // normalize passages, i.e. make sure they "double-back"
            for (int iRoom = 1; iRoom <= fNumRooms; iRoom++)
            {
                Room room = this.getRoom(iRoom);

                // each room shall have two exits
                for (int iPassage = 1; iPassage <= room.getNumPassages(); iPassage++)
                {
                    Room otherRoom = room.getPassage(iPassage);
                    if (!otherRoom.hasPassage(room))
                    {
                        otherRoom.addPassage(room);
                    }
                }
            }

            if (debug)
            {
                Room room = this.getRoom(1);
                room.addStaff(new Staff(null, Staff.BRONZE));
                room.fDragonSwords   = room.fDragonSwords + 1;
                room.fSerpentShields = room.fSerpentShields + 1;
                room.fPit            = true;
                room.addPassage(fExit);
                room.createDoor(fExit);
                fExit.addPassage(room);
            }

            // Create normal doors
            Room fromRoom  = null;
            Room toRoom    = null;
            int  num_doors = this.getNumRooms() / 10;

            for (int iDoor = 1; iDoor <= num_doors + 1; iDoor++)
            {
                bool proceed = false;
                bool done    = false;

                do
                {
                    proceed = false;

                    // Find a room with no door
                    do
                    {
                        done     = true;
                        no       = GameEngine.rand.range(2, fNumRooms);
                        fromRoom = this.getRoom(no);
                        if (fromRoom.hasDoor())
                        {
                            done = false;
                        }
                    } while (!done);

                    // Find a passage to a room without a door
                    for (int i = 0; i < 10; i++)
                    {
                        int index = GameEngine.rand.range(1, fromRoom.getNumPassages());
                        toRoom = fromRoom.getPassage(index);
                        if (!toRoom.hasDoor() && toRoom.getRoomNumber() != 1)
                        {
                            proceed = true;
                            break;
                        }
                    }
                } while (!proceed);

                // Convert the passage to a doorway
                if (iDoor <= num_doors)
                {
                    Utility.Trace("Create door from " + fromRoom.getRoomNumber() + " to " + toRoom.getRoomNumber());
                    fromRoom.createDoor(toRoom);
                    toRoom.createDoor(fromRoom);
                    if (GameEngine.rand.range(1, 2) == 1)
                    {
                        fromRoom.fPoisoned = true;
                        toRoom.fPoisoned   = true;
                    }
                }
                else
                {
                    // Convert the last door to two exit-doors
                    Utility.Trace("Create exit doors in rooms " + fromRoom.getRoomNumber() + " and " + toRoom.getRoomNumber());
                    fromRoom.removePassage(toRoom);
                    fromRoom.addPassage(fExit);
                    fromRoom.createDoor(fExit);
                    fExit.addPassage(fromRoom);
                    toRoom.removePassage(fromRoom);
                    toRoom.addPassage(fExit);
                    toRoom.createDoor(fExit);
                    fExit.addPassage(toRoom);
                    if (GameEngine.rand.range(1, 2) == 1)
                    {
                        fromRoom.fPoisoned = true;
                        toRoom.fPoisoned   = true;
                    }
                }
            }

            Utility.Trace("Removing passages...");

            // Go through the maze and remove one passage from each room
            for (int iRoom = 2; iRoom <= this.getNumRooms(); iRoom++)
            {
                int rnd = GameEngine.rand.range(0, 100);
                if (rnd >= GameEngine.instance.fSparseFactor)
                {
                    continue;
                }
                Room room     = this.getRoom(iRoom);
                int  passages = room.getNumPassages();
                if (room.hasDoor() && !room.isExitDoor())
                {
                    passages++;
                }
                if (passages > 1)
                {
                    Room other = room.getRandomPassage();
                    if (other != null && other.getRoomNumber() != 1)
                    {
                        Utility.Trace("Removing passage between room " + room.getRoomNumber() + " and " + other.getRoomNumber());
                        room.removePassage(other);
                        other.removePassage(room);
                        // Since the janitor can pass through doors,
                        // it should be allowed to have rooms with only
                        // a single door and no passages!
                        // USE_LOCKED_DOORS
                        // However, make sure there are at least one or two keys within reach
                        // from the initial room (1)
                        Room[] path = this.findRoute(room, other, null, USE_LOCKED_DOORS);
                        if (path.Length == 0)
                        {
                            Utility.Trace("Reinserting passage between room " + room.getRoomNumber() + " and " + other.getRoomNumber());
                            room.addPassage(other);
                            other.addPassage(room);
                        }
                    }
                }
            }

            Utility.Trace("Creating portcullises...");

            int num_portcullis = this.getNumRooms() / 5;

            num_portcullis = GameEngine.rand.range(0, num_portcullis);
            int      iPortcullis = 0;
            Sequence sRooms      = new Sequence(1, this.getNumRooms());

            while (sRooms.count() > 0)
            {
                no = sRooms.remove();
                Room from = this.getRoom(no);
                if (from.getNumPassages() > 0)
                {
                    no = GameEngine.rand.range(1, from.getNumPassages());
                    if (from.fPortcullis[no - 1] == Room.kPortcullisNone)
                    {
                        Room to = from.getPassage(no);
                        Utility.Trace("Creating portcullis in passage between room " + from.getRoomNumber() + " and " + to.getRoomNumber());
                        from.fPortcullis[no - 1] = Room.kPortcullisOpen;
                        to.createPortcullis(from);
                        ++iPortcullis;
                    }
                }
                if (iPortcullis >= num_portcullis)
                {
                    break;
                }
            }

            Utility.Trace("Janitor...");
//      int numPassages = 3;
//         if (fNumRooms < 10)
//             numPassages = 0;
            fJanitor = this.getRoom(GameEngine.rand.range(2, fNumRooms));

            fJanitorTarget       = fJanitor;
            fJanitorUnlockedDoor = null;
//      fJanitorRaisedPortcullis = null;
        }
Beispiel #18
0
        protected Room huntPrey()
        {
            //		if (fLastHunt != null)
            //			fHunting = true;

            // if alive player in room, stay and fight
            //		if (GameEngine.instance.hasPlayer(fRoom))
            //			return fRoom;

            // else follow trail (if present)
            Room room = fRoom.getHearCandidate(this.getHearing());

            if (room != null)
            {
                Utility.Trace(this.getMonsterDescription() + " is following hearing from room " + fRoom.getRoomNumber() + " to " + room.getRoomNumber());
                //                  + " and makes noise");
                //             this.makeNoise(Player.kFightNoise, fRoom);
            }
            else
            {
                room = fRoom.getScentCandidate();
                if (room != null)
                {
                    Utility.Trace(this.getMonsterDescription() + " is following scent from room " + fRoom.getRoomNumber() + " to " + room.getRoomNumber());
                }
            }

            // if alive player in room, stay and fight,
            // unless there is another player in the next room!
            // if alive player in room, stay and fight, unless there is fighting to be had in another room, in which
            // case the monster has a hard time deciding...
            if (room != null)
            {
                if (fTargetRoom == null)
                {
                    fTargetRoom = room.getRandomPassage(fRoom);
                    if (fTargetRoom == fRoom)
                    {
                        fTargetRoom = room;
                    }
                }
                if (GameEngine.instance.hasPlayer(fRoom))
                {
                    if (GameEngine.rand.range(0, 1) == 0)
                    {
                        return(fRoom);
                    }
                }
            }
            //      if (GameEngine.instance.hasPlayer(fRoom))
            //      {
            //          if (room != null && !GameEngine.instance.hasPlayer(room))
            //          {
            //              return fRoom;
            //          }
            //      }

            fHunting = true;

            if (room == null && fTargetRoom != null)
            {
                Room[] path = GameEngine.instance.fMaze.findRoute(fRoom, fTargetRoom, null, Maze.USE_OPEN_DOORS);
                if (path.Length > 0)
                {
                    room = path[0];
                }
            }
            else if (room != null)
            {
                if (!fRoom.isPassable(room))
                {
                    room = fRoom.getRandomPassage(fLastRoom);
                }
            }

            if (room == null)
            {
                fHunting = false;
            }
            else
            {
                fStationary = false;
            }

            if (fHunting)
            {
                //          Utility.Trace(this.getMonsterDescription() + " hunts prey and makes noise");
                //          this.makeNoise(Player.kFightNoise);
            }
            return(room);
        }
Beispiel #19
0
        override public void displayShoot(Room room, Staff staff)
        {
            fShooting = true;
            String str = "There are passages leading to:";

            System.Console.WriteLine(str);
            for (int i = 1; i <= room.getNumPassages(); i++)
            {
                Room otherRoom = room.getPassage(i);
                str = "(" + otherRoom.getRoomNumber() + ")";
                Player player = fEngine.getCurrentPlayer();
                if (Player.hasVisited(otherRoom))
                {
                    if (player.fLastRoom == otherRoom)
                    {
                        str = "<" + Convert.ToString(otherRoom.getRoomNumber()) + ">";
                    }
                    else
                    {
                        str = Convert.ToString(otherRoom.getRoomNumber());
                    }
                }
                str = str + " ";
                System.Console.Write(str);
            }
            if (room.hasDoor() && room.isDoorOpen())
            {
                str = "Door: ";
                System.Console.Write(str);
                Room otherRoom = room.fDoor;
                str = "(" + otherRoom.getRoomNumber() + ")";
                Player player = fEngine.getCurrentPlayer();
                if (Player.hasVisited(otherRoom))
                {
                    if (player.fLastRoom == otherRoom)
                    {
                        str = "<" + Convert.ToString(otherRoom.getRoomNumber()) + ">";
                    }
                    else
                    {
                        str = Convert.ToString(otherRoom.getRoomNumber());
                    }
                }
                str = str + " ";
                System.Console.Write(str);
            }

            System.Console.WriteLine();
            int  no     = 0;
            Room toRoom = null;

            while (true)
            {
                no = this.readNumber();
                if (no == 0)
                {
                    return;
                }
                toRoom = fMaze.getRoom(no);
                if (room.hasPassage(toRoom) || room.fDoor == toRoom)
                {
                    break;
                }
                else
                {
                    System.Console.WriteLine("No passage leads to " + no);
                }
            }
            if (staff != null)
            {
                fEngine.doCastLightningBolt(toRoom);
            }
            else
            {
                fEngine.doShootArrow(toRoom);
            }
        }