private void GenerateSwitchPuzzle() { // Generate a puzzle with N switches, each of which toggles one set of alternating doors. // Eg. half the doors are blue, and half are purple; switches toggle between the two, // eg. blue open purple closed, purple open blue closed. int doorsToGenerate = Config.Instance.Get <int>("SwitchDoors"); int generated = 0; var doorColours = new ColourTuple[] { ColourTuple.Cyan, ColourTuple.Purple }; while (generated < doorsToGenerate) { var spot = this.FindEmptyPosition(); if (this.IsInHallway(spot.X, spot.Y)) { var door = new SwitchDoor(generated % 2 == 0 ? doorColours[0] : doorColours[1]); if (door.Colour == doorColours[1]) { door.IsOpen = true; } door.Move(spot.X, spot.Y); this.entities.Add(door); generated++; } } for (var i = 0; i < Config.Instance.Get <int>("Switches"); i++) { var spot = this.FindEmptyPosition(); var s = new Switch(doorColours); s.Move(spot.X, spot.Y); this.entities.Add(s); } }
private void SetupSwitchRoom(Room mainRoom, Room switchRoom) { // door for (int i = 1; i < mainRoom.Connectors.Count; i++) { // need to block main path door Connector c = mainRoom.Connectors[i]; if (c.IsOnMainPath) { GameObject doorObj = (GameObject)Instantiate(ObjectFactory.Instance.GetObjectPrefab(ObjectFactory.eObject.SwitchDoor), c.ObjTransform.position, c.ObjTransform.rotation); SwitchDoor door = doorObj.GetComponent <SwitchDoor>(); door.SetRoomID(mainRoom.RoomID); door.IsOnMainPath = c.IsOnMainPath; } } // switch GameObject switchObj = (GameObject)Instantiate(ObjectFactory.Instance.GetObjectPrefab(ObjectFactory.eObject.Switch), switchRoom.FloorCenter.position, Quaternion.identity); Switch s = switchObj.GetComponent <Switch>(); s.SetRoomID(switchRoom.RoomID); s.SetDoorRoomID(mainRoom.RoomID); // mark that there is something important here switchRoom.ContainsImportantObject = true; }