コード例 #1
0
ファイル: Maze.cs プロジェクト: walleball/dungeons.cs
        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;
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        protected bool move(Room room)
        {
            Utility.Assert(room != null, "Monster.move - room != null");
            fMoving = false;
            if (fStationary)
            {
                Utility.Assert(!fHunting, "Monster.move - !fHunting");
                //			if (GameEngine.rand.range(1, 25) == 1)
                int interval = Room.kLairProduction * this.getKillScore();
                if (GameEngine.rand.range(1, interval) == 1)
                {
                    if (GameEngine.fDisplayDebugInfo)
                    {
                        Utility.Assert(false, this.getMonsterDescription() + " is no longer stationary.");
                    }
                    Utility.Trace(this.getMonsterDescription() + " is no longer stationary.");
                    fStationary = false;
                }
                else
                {
                    return(false);
                }
            }

            if (fEndurance <= 0)
            {
                Utility.Trace(this.getMonsterDescription() + " is too tired to move.");
                fEndurance = 3;
                return(false);
            }

            if (!fHunting && room == fRoom)
            {
                //			fEndurance = fEndurance - 1;
                return(false);
            }
            if (fRoom.hasPassage(room))
            {
                if (!fRoom.isPassable(room))
                {
                    room = null;
                }
            }
            else
            {
                if (!fRoom.hasDoor() || !fRoom.isDoorOpen() || fRoom.fDoor != room)
                {
                    // Can happen if the player closes a door...
                    //					Utility.Assert(false);
                    room = null;
                }
            }

            if (room != null)
            {
                // get tired...
                fEndurance = fEndurance - 1;
                fLastRoom  = fRoom;
                fRoom      = room;
                if (fTargetRoom == room)
                {
                    fTargetRoom = null;
                }
                fMoving = true;
                return(true);
            }
            return(false);
        }
コード例 #4
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);
        }