public void TryKillMonsterAt(int x, int y) { int toKillX = (int)startPosition.x + x; int toKillY = (int)startPosition.y + y; if (level[toKillX, toKillY] is Monster) { DestroyImmediate(levelObjects [toKillX, toKillY]); levelObjects[toKillX, toKillY] = Instantiate(emptyRoomObj, new Vector3(toKillX * roomSize, toKillY * roomSize, 0), Quaternion.identity, transform.parent); levelObjects[toKillX, toKillY].transform.localScale = new Vector3(roomSize, roomSize, 1); for (int i = -1; i < 2; i += 2) { for (int j = -1; j < 2; j += 2) { if (toKillX + i > 0 && toKillX + i < levelSize && toKillY + j > 0 && toKillY + j < levelSize) { level [toKillX + i, toKillY + j].hasPoop = false; } } } EmptyRoom temp = new EmptyRoom(); temp.hasPoop = level [toKillX, toKillY].hasPoop; temp.hasWind = level [toKillX, toKillY].hasWind; level [toKillX, toKillY] = temp; } }
private void AddStartAndExit(int levelSize) { int instantiatedObject = 0; while (instantiatedObject < 2) { int x = Random.Range(0, levelSize); int y = Random.Range(0, levelSize); if (level[x, y] == null) { Room toAdd; if (instantiatedObject == 0) { toAdd = new EmptyRoom(); } else { toAdd = new Exit(); } GameObject toInstantiate = instantiatedObject == 0 ? startObj : exitObj /*Exit*/; if (instantiatedObject == 0) { startPosition = new Vector2(x, y); GameObject pTemp = Instantiate(AIObj, new Vector3(x * roomSize, y * roomSize, -1), transform.rotation, transform.parent); pTemp.transform.localScale = new Vector3(roomSize, roomSize, 1); PlayButton.onClick.AddListener(() => pTemp.GetComponent <AI>().Play()); AutoButton.onClick.AddListener(() => pTemp.GetComponent <AI>().AutoPlay()); } level[x, y] = toAdd; Instantiate(toInstantiate, new Vector3(x * roomSize, y * roomSize, 0), transform.rotation, transform.parent).transform.localScale = new Vector3(roomSize, roomSize, 1); instantiatedObject++; } } }
/// <summary> /// Generates specific values for the DungeonType. /// </summary> /// <param name="room">The current room.</param> /// <param name="dungeonRoomObject">The gameobject to which the room should be generate don.</param> /// <param name="levelNumber">The number of the level.</param> /// <returns>The fully generated DungeonRoom.</returns> private DungeonRoom SetRoomType(Room room, GameObject dungeonRoomObject, int levelNumber, DungeonConfig config) { switch (room.Type) { case RoomType.Start: StartRoom startRoom = dungeonRoomObject.AddComponent <StartRoom>(); if (Player.LocalPlayer.isServer && levelNumber == 0) { startRoom.SpawnItems(RegionDict.Instance.StartingRoomPickables, DungeonCreator.Instance.TilePositionToWorldPosition(room.Position + (room.Layout.Size / 2))); } return(startRoom); case RoomType.Combat: CombatRoom combatRoom = dungeonRoomObject.AddComponent <CombatRoom>(); combatRoom.ThreatLevel = room.TileCount; combatRoom.enemiesToSpawn = new EnemyObject[combatRoom.ThreatLevel / 48]; for (int j = 0; j < combatRoom.enemiesToSpawn.Length; j++) { combatRoom.enemiesToSpawn[j] = RandomUtil.Element(RegionDict.Instance.EnemiesToSpawn); } return(combatRoom); case RoomType.Loot: LootRoom lootRoom = dungeonRoomObject.AddComponent <LootRoom>(); lootRoom.pickables = new Pickable[room.TileCount / 48]; for (int j = 0; j < lootRoom.pickables.Length; j++) { lootRoom.pickables[j] = RandomUtil.Element(RegionDict.Instance.LootingRoomPickables); } return(lootRoom); case RoomType.Shop: ShopRoom shopRoom = dungeonRoomObject.AddComponent <ShopRoom>(); const int numItems = 4; shopRoom.shopItems = new Pickable[numItems]; shopRoom.locations = new Vector2[numItems]; // TODO: Replace Pickabledict with dungeon config shop pickables. for (int j = 0; j < numItems; j++) { int rnd = Random.Range(0, config.shopItems.Length); shopRoom.shopItems[j] = config.shopItems[rnd]; shopRoom.locations[j] = room.Position + new Vector2Int((int)room.GameObjects[j + 4].Position.x, (int)room.GameObjects[j + 4].Position.y); } shopRoom.SpawnItems(); return(shopRoom); case RoomType.Boss: BossRoom bossRoom = dungeonRoomObject.AddComponent <BossRoom>(); bossRoom.bossObjects = new BossObject[] { RandomUtil.Element(RegionDict.Instance.BossesToSpawn) }; DungeonDict.Instance.SetBossRoom(bossRoom); return(bossRoom); case RoomType.Empty: EmptyRoom emptyRoom = dungeonRoomObject.AddComponent <EmptyRoom>(); return(emptyRoom); default: throw new System.Exception("Unknown room type! (" + room.Type + ")"); } }
public List <PivotTable> GetDayProgram(int day, DateTime?date) { if (!date.HasValue) { date = DateTime.Now; } List <WeeklyProgram> modelBase = table .Where(b => b.StartDate <= date && (b.EndDate >= date || b.EndDate == null)) .Where(b => b.Day == day) .Where(b => b.isActive == true) .ToList(); List <Room> roomList = db.Rooms .Where(x => x.isActive == true) .ToList(); int[] hours = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; List <PivotTable> pivotTable = new List <PivotTable>(); foreach (var hour in hours) // her saat için bir satır oluşturuyoruz { PivotTable pivotRow = new PivotTable() { Hour = hour }; foreach (var room in roomList) // her oda için tek tek bakıyoruz { bool added = false; foreach (var item in modelBase) // programdaki her dersi oda ve saat ile karşılaştırıyoruz { if (item.Hour == hour && room.Id == item.RoomId) // eğer uyuyorsa pivota ekliyoruz { pivotRow.Rooms.Add(item); added = true; break; } } if (!added) // hiç biri uymadı ise pivota boş oda ekliyoruz { EmptyRoom emptyRoom = new EmptyRoom(room.Id, hour, day); pivotRow.Rooms.Add(emptyRoom); added = false; } } pivotTable.Add(pivotRow); } return(pivotTable); }
public void CleanerGhostConstructor() { GuestRoom room = new GuestRoom(1, new Point(1, 0), new Point(1, 1), 1); EmptyRoom outside = new EmptyRoom(0, new Point(0, 0), new Point(1, 1)); outside.Entrance = true; room.Neighbors.Add(Direction.West, room); outside.Neighbors.Add(Direction.East, room); CleanerGhost ghost = new CleanerGhost(room); Assert.IsNotNull(ghost); }
public void CleanerGhostArrivalOutside() { Hotel.Hotel hotel = new Hotel.Hotel(); GuestRoom room = new GuestRoom(1, new Point(1, 0), new Point(1, 1), 1); EmptyRoom outside = new EmptyRoom(0, new Point(0, 0), new Point(1, 1)); outside.Entrance = true; hotel.Rooms.Add(room); hotel.Rooms.Add(outside); room.Neighbors.Add(Direction.West, room); outside.Neighbors.Add(Direction.East, room); CleanerGhost ghost = new CleanerGhost(outside); ghost.RemoveObjectEvent += hotel.RemoveObject; hotel.Staff.Add(ghost); hotel.Update(1); ghost.OnArrival(); hotel.Update(1); Assert.IsTrue(hotel.Staff[0] is Cleaner); }
/// <summary> /// Call this to build the hotel from a file. /// </summary> public List <Room> BuildHotel() { // List of all rooms. List <Room> rooms = new List <Room>(); // The hotel width, and height. int extremeX = 0; int smallestX = Int32.MaxValue; int extremeY = 0; int smallestY = Int32.MaxValue; int extremeID = 0; TextReader textReader = new StreamReader(ServiceLocator.Get <ConfigLoader>().GetConfig().LayoutPath); JsonReader jsonReader = new JsonTextReader(textReader); // Dictionary containg room data. Dictionary <string, string> data = new Dictionary <string, string>(); while (jsonReader.Read()) { Console.WriteLine(jsonReader.Value?.ToString()); if (jsonReader.Value != null) { // Read and add the values from the file. string value = jsonReader.Value.ToString(); jsonReader.Read(); data.Add(value, jsonReader.Value.ToString()); } // When we know the dimension, add the room. if (data.Keys.Count > 0 && jsonReader.Value == null) { // if we have data. if (data.Count > 0) { // Get the position/dimension/ID string[] posData = data["Position"].Split(','); string[] dimData = data["Dimension"].Split(','); string[] idData = data["ID"].Split(','); // get the room dimensions. Point dimensions = new Point(Int32.Parse(dimData[0]), Int32.Parse(dimData[1])); // calculate the room position. Point position = new Point(Int32.Parse(posData[0]), Int32.Parse(posData[1]) + (dimensions.Y - 1)); // Calculate the ID int id = Int32.Parse(idData[0]); // Set the extreme values (hotel size) int maxX = position.X + (dimensions.X - 1); // Set extreme values these values are used to determine the placement of the lobby, elevator and stairs. if (extremeX < maxX) { extremeX = maxX; } if (smallestX > position.X) { smallestX = position.X; } if (extremeY < position.Y) { extremeY = position.Y; } else if (smallestY > position.Y) { smallestY = position.Y; } if (extremeID < id) { extremeID = id; } Room aRoom = RoomFactory.BuildRoom(data); if (aRoom != null) { rooms.Add(aRoom); } // The option to create empty rooms is on, these empty rooms fill the space in the 2 high rooms so people can "fly" through them. if (_createEmptyRooms) { if (rooms.Count > 0) { // Add empty rooms to rooms bigger in height. (used for path finding) for (int i = 0; i < dimensions.Y - 1; i++) { rooms.Add(RoomFactory.BuildRoom(-1, "Empty", new Point(position.X, position.Y + i), new Point(dimensions.X, 1))); rooms.Last().Name = "Empty"; } } } } data.Clear(); } } // Add elevator shafts to the hotel. for (int i = 0; i <= extremeY; i++) { extremeID++; rooms.Add(RoomFactory.BuildRoom(extremeID, "ElevatorShaft", new Point(smallestX - 1, smallestY - 1 + i), new Point(1, 1))); } // Add Stairs to the hotel. for (int i = 0; i <= extremeY; i++) { extremeID++; rooms.Add(RoomFactory.BuildRoom(extremeID, "Staircase", new Point(extremeX + 1, smallestY - 1 + i), new Point(1, 1))); } // Add lobbies. for (int i = smallestX; i <= extremeX; i++) { extremeID++; rooms.Add(RoomFactory.BuildRoom(extremeID, "Lobby", new Point(i, smallestY - 1), new Point(1, 1))); } // Add the rooms, and connect them, starts with an empty room outside with ID 0. EmptyRoom outside = RoomFactory.BuildRoom(0, "Empty", new Point(smallestX - 2, smallestY - 1), new Point(1, 1)) as EmptyRoom; outside.Entrance = true; rooms.Add(outside); foreach (Room r in rooms) { PlaceRoom(r); } return(Rooms); }
public GenericRoom(Vector2Int size, Vector2Int position) : base(size, position) { RoomType = new EmptyRoom(); }
/// <summary> /// A button that generates the field in which the whole path finding process can be organized /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Generate_Click(object sender, EventArgs e) { Random rnd = new Random(); MainField field = new MainField(); Cell cell = new Cell(); List <Room> rooms = new List <Room>(); Graphics g = this.CreateGraphics(); lbl_Status.Text = "Status: Nothing"; // Reset the key and gate positions with each new map created (start and end points) this.current_key[0] = 0; this.current_key[1] = 0; this.current_gate[0] = 0; this.current_gate[1] = 0; this.rooms_template = InitialTemplate.prepareEmptyTemplate(); /** Generate a second copy of an empty array that will later match the original one. It will be needed to clear spaces * For connecting joins between the rooms. This can be only properly done if one map will never change after being populated * As dynamically changing map would require a much bigger set of rules to account for when looking where room connections are present. **/ bool[][] rooms_template_permenant = new bool[25][]; rooms_template_permenant = InitialTemplate.prepareEmptyTemplate(); /** Initiate an array of all possible room types that can be generated. The names are only representations of rooms * as a random number generator will allow to pick one by one a room for generation and based on which room is picked * it will be added to the collection of all rooms for geeneration. Which will later be drawn and connected among each other * if connections between them actually exist **/ String[] choices = { "Square", "Plus", "L", "Corner", "Long1", "Long2", "Funnel", "Empty" }; // X, FullPlus - redacted // ------------------ PREPARE THE MAZE -------------------------------- // Generate a list of rooms with their information. The whole screen should have 25 rooms for (int i = 0; i < 25; i++) { // Generate a random number that will decide what the room will be int room_value = rnd.Next(0, choices.Length); String chosen_room = choices[room_value]; // Add the chosen room to the whole collection switch (chosen_room) { case "Square": SquareRoom squareRoom = new SquareRoom(); rooms.Add(squareRoom); break; case "Plus": PlusRoom plusRoom = new PlusRoom(); rooms.Add(plusRoom); break; case "L": LRoom lRoom = new LRoom(); rooms.Add(lRoom); break; case "Empty": EmptyRoom emptyRoom = new EmptyRoom(); rooms.Add(emptyRoom); break; case "Corner": CornerRoom cornerRoom = new CornerRoom(); rooms.Add(cornerRoom); break; case "Long1": LongRoom1 longRoom1 = new LongRoom1(); rooms.Add(longRoom1); break; case "Long2": LongRoom2 longRoom2 = new LongRoom2(); rooms.Add(longRoom2); break; case "FullPlus": FullPlusRoom fullPlusRoom = new FullPlusRoom(); rooms.Add(fullPlusRoom); break; case "Funnel": FunnelRoom funnelRoom = new FunnelRoom(); rooms.Add(funnelRoom); break; case "X": XRoom xRoom = new XRoom(); rooms.Add(xRoom); break; } } /** Populate the information about walls that rooms add to the map in a matrix format (2D array to be more speicific here) * We iterrate through rooms for each case and build it all into a sort of a coordinate matrix type deal **/ int row = 0; int col = 0; int true_row = 0; int true_col = 0; foreach (Room room in rooms) { /** * rooms are build itteratevelly cell by cell, left to right. Consider the following example of a 2x2 room: * Step 1: # * * Step 2: ## * * Step 3: ## * # * * Step 4: ## * ## * * Finish * Same applies for 5 by 5. When the next room is processed, it is built in the same fashion next to the original one or down * if 5 rooms per line have been constructed **/ // In the beginning we reset our position to what we are filling now on the y axis int position_y = 16 + (5 * cell.height * col); // While we still have new space to fill in a designated area - means our room is not fully drawn foreach (bool[] roomLine in room.room) // roomLine - just means a specific row we are moving by building a room { // We move through each value in a row int position_x = 16 + (5 * cell.width * row); foreach (bool roomIndividual in roomLine) // roomIndividual - just means a seperate room cell we fill by moving through the previous line { if (roomIndividual) { true_row = (position_x / cell.width) - 1; true_col = (position_y / cell.height) - 1; this.rooms_template[true_row][true_col] = roomIndividual; rooms_template_permenant[true_row][true_col] = roomIndividual; } position_x += cell.width; } position_y += cell.height; } row += 1; if (row % 5 == 0) { row = 0; col += 1; } } // ------------------ CLEANING THE MAZE -------------------------------- /** * Now the goal is to go over the maze again, applying few rules and deleting spaces between rooms that can be easily connected. * In reality, there are only 4 rules that need to be applied to clean the maze. * Condition: All rooms are closed, and their external walls need to be evaluated for whether they need to be taken down or not. * The walls that need to be evaluated are always located on the X axis on lines: 0, 4, 5, 9, 10, 14, 15, 19, 20, 24, 25 * The walls that need to be evaluated are always located on the Y axis on lines: 0, 4, 5, 9, 10, 14, 15, 19, 20, 24, 25 * Because rooms are not connected beyond lines 0 and 25 on both axes, we can ommmit them. * * The condition is simple: * IF the walls of the given room neighbour 1. an open space on one side next to the space evaluated * 2. a closed space on the other side of the space evaluated * 3. an open space on the side of the cell that fits criteria 2. * THEN rooms can be connected and the given space should be deleted. **/ // Go over first iterration on the X axis (i.e. 4, 9, 14, 19, 24) for (int x = 4; x < rooms_template_permenant.Length; x += 5) { for (int y = 0; y < rooms_template_permenant.Length; y++) { try { if (rooms_template_permenant[y][x - 1] == false && rooms_template_permenant[y][x] == true && rooms_template_permenant[y][x + 1] == true && rooms_template_permenant[y][x + 2] == false) { this.rooms_template[y][x] = false; } } catch { // Do nothing for now } } } // Go over second iterration on the X axis (i.e. 5, 10, 15, 20) for (int x = 5; x < rooms_template_permenant.Length; x += 5) { for (int y = 0; y < rooms_template_permenant.Length; y++) { try { if (rooms_template_permenant[y][x - 2] == false && rooms_template_permenant[y][x - 1] == true && rooms_template_permenant[y][x] == true && rooms_template_permenant[y][x + 1] == false) { this.rooms_template[y][x] = false; } } catch { // Do nothing for now } } } // Go over first iterration on the Y axis (i.e. 4, 9, 14, 19, 24) for (int x = 0; x < rooms_template_permenant.Length; x++) { for (int y = 4; y < rooms_template_permenant.Length; y += 5) { try { if (rooms_template_permenant[y - 1][x] == false && rooms_template_permenant[y][x] == true && rooms_template_permenant[y + 1][x] == true && rooms_template_permenant[y + 2][x] == false) { this.rooms_template[y][x] = false; } } catch { // Do nothing for now } } } // Go over the second iterration on the Y axis (i.e. 5, 10, 15, 20) for (int x = 0; x < rooms_template_permenant.Length; x++) { for (int y = 5; y < rooms_template_permenant.Length; y += 5) { try { if (rooms_template_permenant[y - 2][x] == false && rooms_template_permenant[y - 1][x] == true && rooms_template_permenant[y][x] == true && rooms_template_permenant[y + 1][x] == false) { rooms_template[y][x] = false; } } catch { // Do nothing for now } } } // ------------------ DRAW THE MAZE -------------------------------- // Load all of our objects that are required to draw our map Image image1 = new Bitmap("..\\..\\Graphics\\PNG\\Wall1.png", true); Image image2 = new Bitmap("..\\..\\Graphics\\PNG\\Wall2.png", true); Image image3 = new Bitmap("..\\..\\Graphics\\PNG\\Wall3.png", true); Image image4 = new Bitmap("..\\..\\Graphics\\PNG\\Wall4.png", true); TextureBrush tBrush1 = new TextureBrush(image1); TextureBrush tBrush2 = new TextureBrush(image2); TextureBrush tBrush3 = new TextureBrush(image3); TextureBrush tBrush4 = new TextureBrush(image4); // Clean everything before drawing if there are instances of an old map being present Brush myOldLaceBrush = new SolidBrush(color: Color.OldLace); g.FillRectangle(brush: myOldLaceBrush, x: field.x, y: field.y, width: field.width, height: field.height); // As we have all values of our maze in a 2D Matrix (array), we can just draw them one by one. int place_x = field.x; int place_y = field.y; for (int i = 0; i < this.rooms_template.Length; i++) { for (int j = 0; j < this.rooms_template[i].Length; j++) { bool roomState = this.rooms_template[i][j]; if (roomState) { // Chose a random brush to paint with, as we want all of our walls to be randomly different int rnd_brush = rnd.Next(0, 4); switch (rnd_brush) { case 0: g.FillRectangle(tBrush1, x: place_x, y: place_y, width: cell.width, height: cell.height); break; case 1: g.FillRectangle(tBrush2, x: place_x, y: place_y, width: cell.width, height: cell.height); break; case 2: g.FillRectangle(tBrush3, x: place_x, y: place_y, width: cell.width, height: cell.height); break; case 3: g.FillRectangle(tBrush4, x: place_x, y: place_y, width: cell.width, height: cell.height); break; default: break; } } place_x += cell.width; } place_x = field.x; place_y += cell.height; } // Update the representation that we will want of our matrix to be in, for the future this.rooms_template_redux = TemplateConverter.redefineTemplate(original_template: this.rooms_template); }
// Use this for initialization void Start() { Room.poop = poopObj; Room.wind = windObj; //-move the camera-- int camXY = 300 + Data.Level * 150; int camZ = -1000 - Data.Level * 300; Camera.main.transform.position = new Vector3(camXY, camXY, camZ); //------------------ levelSize = 3 + Data.Level; level = new Room[levelSize, levelSize]; levelObjects = new GameObject[levelSize, levelSize]; grayObjects = new GameObject[levelSize, levelSize]; AddStartAndExit(levelSize); List <Vector2> monsters = new List <Vector2>(); List <Vector2> holes = new List <Vector2>(); for (int i = 0; i < levelSize; i++) { for (int j = 0; j < levelSize; j++) { grayObjects[i, j] = Instantiate(grayObj, new Vector3(i * roomSize, j * roomSize, -1), transform.rotation, transform.parent); grayObjects[i, j].transform.localScale = new Vector3(roomSize, roomSize, 1); if (level[i, j] == null) { float score = UnityEngine.Random.value; GameObject toInstantiate = emptyRoomObj; if (score < monsterRate) { toInstantiate = monsterObj; monsters.Add(new Vector2(i, j)); level[i, j] = new Monster(); } else if (score < monsterRate + holeRate) { toInstantiate = holeObj; holes.Add(new Vector2(i, j)); level[i, j] = new Hole(); } else { level[i, j] = new EmptyRoom(); } levelObjects[i, j] = Instantiate(toInstantiate, new Vector3(i * roomSize, j * roomSize, 0), transform.rotation, transform.parent); levelObjects[i, j].transform.localScale = new Vector3(roomSize, roomSize, 1); } } } foreach (Vector2 position in monsters) { for (int i = -1; i < 2; i += 2) { if ((int)position.x + i >= 0 && (int)position.x + i < levelSize) { level[(int)position.x + i, (int)position.y].AddPoop(); Instantiate(poopObj, new Vector3((position.x + i) * roomSize, position.y * roomSize, 0), transform.rotation, levelObjects[(int)position.x, (int)position.y].transform); } if ((int)position.y + i >= 0 && (int)position.y + i < levelSize) { level[(int)position.x, (int)position.y + i].AddPoop(); Instantiate(poopObj, new Vector3(position.x * roomSize, (position.y + i) * roomSize, 0), transform.rotation, levelObjects[(int)position.x, (int)position.y].transform); } } } foreach (Vector2 position in holes) { for (int i = -1; i < 2; i += 2) { if ((int)position.x + i >= 0 && (int)position.x + i < levelSize) { level[(int)position.x + i, (int)position.y].AddWind(); Instantiate(windObj, new Vector3((position.x + i) * roomSize, position.y * roomSize, 0), transform.rotation, transform.parent).transform.localScale = new Vector3(roomSize, roomSize, 1); } if ((int)position.y + i >= 0 && (int)position.y + i < levelSize) { level[(int)position.x, (int)position.y + i].AddWind(); Instantiate(windObj, new Vector3(position.x * roomSize, (position.y + i) * roomSize, 0), transform.rotation, transform.parent).transform.localScale = new Vector3(roomSize, roomSize, 1); } } } }
public void EmptyRoomConstructor() { EmptyRoom room = new EmptyRoom(1, new Point(0, 0), new Point(1, 1)); Assert.IsNotNull(room); }