Пример #1
0
        public void Init(ContentManager content)
        {
            rand = new Random();

            this.content = content;

            currentRoom = rooms[0];

            player = new PlayerObject();
            player.destroyMe += new destroyMeEventHandler(player_destroyMe);

            player.position = new Vector2(300, 400);

            player.position = new Vector2(400, 400);

            Game1.hacks = player;

            currentRoom.objects.Add(player);

            foreach (Room room in rooms)
            {
                room.Init(content);

                foreach (WorldObject worldObject in room.objects)
                {
                    if (worldObject.type == "Door")
                    {
                        DoorObject door = (DoorObject)worldObject;
                        if (door.props["direction"] == "left")
                        {
                            leftRooms.Add(room);
                        }
                        if (door.props["direction"] == "right")
                        {
                            rightRooms.Add(room);
                        }
                        if (door.props["direction"] == "up")
                        {
                            upRooms.Add(room);
                        }
                        if (door.props["direction"] == "down")
                        {
                            downRooms.Add(room);
                        }
                    }
                }
            }
        }
Пример #2
0
 public override void Init(ContentManager content, Room room)
 {
     string direction = this.props["direction"];
     this.room = room;
 }
Пример #3
0
 public virtual void Init(ContentManager content, Room room)
 {
     //Must set/have by this point a: collider, animTexture.
 }
Пример #4
0
 public Room createRoom(Room room)
 {
     room.lootEvent += new lootEvenDelegate(room_lootEvent);
     return room;
 }
Пример #5
0
        public void Update(GameTime gameTime)
        {
            DoorObject previousDoor = null;
            DoorObject newDoor = null;

            Room previousRoom = currentRoom;

            String directionFrom = player.transition;
            String directionTo = "";

            List<Room> fromRooms = null;
            List<Room> toRooms = null;

            if (directionFrom != "none")
            {

                if (directionFrom == "right")
                {
                    directionTo = "left";
                    fromRooms = rightRooms;
                    toRooms = leftRooms;
                }
                if (directionFrom == "left")
                {
                    directionTo = "right";
                    fromRooms = leftRooms;
                    toRooms = rightRooms;
                }
                if (directionFrom == "up")
                {
                    directionTo = "down";
                    fromRooms = upRooms;
                    toRooms = downRooms;
                }
                if (directionFrom == "down")
                {
                    directionTo = "up";
                    fromRooms = downRooms;
                    toRooms = upRooms;
                }

                //We need a new link
                player.onDestroyMe();

                foreach (WorldObject worldObject in previousRoom.objects)
                {
                    if (worldObject.type == "Door")
                    {
                        DoorObject door = (DoorObject)worldObject;
                        if (door.props["direction"] == directionFrom)
                        {
                            previousDoor = door;

                            if (doorLinks.ContainsKey(previousDoor))
                            {
                                newDoor = doorLinks[previousDoor];
                                currentRoom = newDoor.room;
                                player.position = newDoor.position;
                            }
                            else //We need to select a new room as the door is not linked
                            {
                                while (true)
                                {
                                    if (toRooms.Count > 0)
                                    {
                                        int index = (int)rand.Next(toRooms.Count);
                                        List<Room> possibleRooms = toRooms;
                                        Room possibleRoom = possibleRooms[index];

                                        if (possibleRoom != previousRoom)
                                        {
                                            currentRoom = createRoom(possibleRoom);
                                            toRooms.Remove(currentRoom);
                                            fromRooms.Remove(previousRoom);
                                            break;
                                        }
                                        else
                                        {
                                            possibleRooms.Remove(possibleRoom);
                                        }
                                    }
                                    else //Need to fix possible fail on way back - THIS CODE IS NOT DONE FORGIVE THE UGLY
                                    {
                                        if (toRooms.Count + fromRooms.Count >= 4)
                                        {
                                            currentRoom = createRoom(loadDeadend(directionTo));
                                            fromRooms.Remove(previousRoom);
                                            break;
                                        }
                                        else if (!foundBridge)
                                        {
                                            currentRoom = createRoom(loadBridge(directionTo));
                                            currentRoom.redButtonEvent += new RedButtonEventDelegate(currentRoom_redButtonEvent);
                                            fromRooms.Remove(previousRoom);
                                            foundBridge = true;
                                            break;
                                        }
                                        else
                                        {
                                            currentRoom = createRoom(loadDeadend(directionTo));
                                            fromRooms.Remove(previousRoom);
                                            break;
                                        }
                                    }
                                }

                                foreach (WorldObject anotherWorldObject in currentRoom.objects) //Conntect to the correct door in the new room and add the links to the dictionary
                                {
                                    if (anotherWorldObject.type == "Door")
                                    {
                                        DoorObject anotherDoor = (DoorObject)anotherWorldObject;
                                        if (anotherDoor.props["direction"] == directionTo)
                                        {
                                            newDoor = anotherDoor;
                                            player.position = anotherDoor.position;
                                            doorLinks.Add(previousDoor, newDoor);
                                            doorLinks.Add(newDoor, previousDoor);
                                        }
                                    }
                                }
                            }

                        }
                    }

                }
                currentRoom.addWO(player);
            }
            currentRoom.Update(gameTime);
        }