Example #1
0
        public int getNumUnvisited(Room room)
        {
            int unvisited = 0;

            for (int i = 1; i <= room.getNumPassages(); i++)
            {
                Room otherRoom = room.getPassage(i);
                if (!Player.hasVisited(otherRoom))
                {
                    unvisited++;
                }
            }
            if (room.hasDoor())
            {
                if (room.isDoorLocked() || (!room.isExitDoor() && !Player.hasVisited(room.fDoor)))
                {
                    unvisited++;
                }
            }
            return(unvisited);
        }
Example #2
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");
        }
Example #3
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);
        }
Example #4
0
        override public void displayRoom(Room room)
        {
            fShotsFired = 0;

            Player player = fEngine.getCurrentPlayer();

            String str = fEngine.getAdjacentMonsterDescription(room);

            str += room.getAdjacentMonsterDescription();
            str += room.getAdjacentPlayerDescription();
            str  = str + room.getDescription();
            str += "The room contains:\n";
            String content = room.getContentDescription();

            content += fEngine.getMonsterContentDescription(room);
            if (content.Length == 0)
            {
                content = "Nothing";
            }
            str += content;

            //		str = str + "\n" + "You are in cavern " + room.getRoomNumber();
            System.Console.WriteLine(str);
            System.Console.WriteLine("What do you wish to do?");
            if (player.canMove())
            {
                System.Console.WriteLine("1   Move");
            }
            if (fEngine.hasAdjacentMonster(room) && player.canShoot())
            {
                System.Console.WriteLine("2   Shoot");
            }
            if (room.hasTakeableContent() && player.needsContent(room))
            {
                System.Console.WriteLine("3   Take");
            }
            if (room.hasDoor())
            {
                if (!room.isDoorLocked())
                {
                    System.Console.WriteLine("4   Open/close door");
                }
                else if (player.hasKey())
                {
                    System.Console.WriteLine("4   Unlock/lock door");
                }
            }
            System.Console.WriteLine("5   Inventory");
            if (fEngine.hasAdjacentMonster(room) && player.hasChargedStaff())
            {
                System.Console.WriteLine("6   Cast Bolt");
            }
            if (fEngine.hasMonster(room) && player.canAttack())
            {
                System.Console.WriteLine("7   Fight");
            }
            if (fEngine.hasMonster(room) && player.hasChargedStaff())
            {
                System.Console.WriteLine("8   Cast Fireball");
            }
            System.Console.WriteLine("9   Wait");
            System.Console.WriteLine("10   Map");

            while (true)
            {
                for (int i = Player.kNumCommands - 1; i > 0; --i)
                {
                    player.fCommands[i] = player.fCommands[i - 1];
                }
                player.fCommands[0] = "";

                int no = this.readNumber();
                if (no == 1)
                {
                    player.fCommands[0] = "Move";
                    fEngine.doCommandMove();
                    break;
                }
                if (no == 2)
                {
                    fEngine.doCommandShootArrow();
                    break;
                }
                if (no == 3)
                {
                    fEngine.doCommandTake();
                    break;
                }
                if (no == 4)
                {
                    fEngine.doCommandDoor(true);
                    break;
                }
                if (no == 5)
                {
                    this.displayInventory();
                    break;
                }
                if (no == 6)
                {
                    fEngine.doCommandCastLightningBolt();
                    break;
                }
                if (no == 7)
                {
                    fEngine.doCommandFight();
                    break;
                }
                if (no == 8)
                {
                    fEngine.doCommandCastFireball();
                    break;
                }
                if (no == 9)
                {
                    fEngine.processNextPlayer();
                    break;
                }
                if (no == 10)
                {
                    this.displayMap();
                    break;
                }
            }
        }