void GenerateRooms() { int i = 0; int roomCount = Synched.Next(MIN_ROOM_COUNT, MAX_ROOM_COUNT + 1); int lootRoomCount = 0; int w; int h; int r; int ox; int oz; int iterations = 0; while (rooms.Count < roomCount) { if (iterations == 5000) { Debug.LogWarning("Dungeon.Generate() is looping!"); break; } w = Synched.Next(MIN_ROOM_SIZE, MAX_ROOM_SIZE + 1); h = Synched.Next(MIN_ROOM_SIZE, MAX_ROOM_SIZE + 1); while (w % 2 != 0) { w = Synched.Next(MIN_ROOM_SIZE, MAX_ROOM_SIZE + 1); } while (h % 2 != 0) { h = Synched.Next(MIN_ROOM_SIZE, MAX_ROOM_SIZE + 1); } ox = Synched.Next(1, size - w - 2); oz = Synched.Next(1, size - h - 2); if (SquareRoom.Validate(ox, oz, i, w, h)) { if (i == 0) { rooms.Add(new SquareRoom(ox, oz, i, w, h, RegionProfile.Entrance)); } else if (i >= (roomCount / 2) && lootRoomCount < MAX_LOOT_ROOMS) { lootRoomCount++; rooms.Add(new SquareRoom(ox, oz, i, w, h, RegionProfile.Treasure)); } else { rooms.Add(new SquareRoom(ox, oz, i, w, h, RegionProfile.Generic)); } i++; } iterations++; } }
protected override void RenderMap() { // first render the floor for all the rooms List <Region> rooms = Map.GetRegions().Where(r => r is Room).ToList(); foreach (Room room in rooms) { if (room is SquareRoom) { // first calculate the floor size we need SquareRoom sroom = room as SquareRoom; int maxPossibleWidth = sroom.Width; int maxPossibleHeight = sroom.Height; int areaToCover = sroom.Width * sroom.Height; Vector3 floorPlacement = new Vector3(sroom.X, 0, sroom.Y); FloorComponent floor = Floors.Where(f => f.WidthInTiles == sroom.Width && f.DepthInTiles == sroom.Height).FirstOrDefault(); if (floor == null) { throw new Exception("We failed to find a floor for the room " + sroom.Width + " X " + sroom.Height); } FloorComponent renderedComponent = Instantiate(floor, floorPlacement, Quaternion.identity); MapRender.Add(renderedComponent.gameObject); } else { throw new NotImplementedException("We don't know how to render " + room.GetType()); } } }
public IHttpActionResult CalculateQuantitySquareRoom(PaintRequestModelSquareRoom paintInfo) { try { var squareRoom = new SquareRoom { Height = paintInfo.Height, Width = paintInfo.Width, Length = paintInfo.Length }; var coverageInfo = _paintService.CalculateCoverage(squareRoom, paintInfo.PaintId); var quantityInfo = new PaintQuantityResponseModel { PaintInfo = paintInfo, Area = coverageInfo.Area, Volume = coverageInfo.Volume, TinsRequired = coverageInfo.TinsRequired, CoverageM2PerTin = coverageInfo.CoverageM2PerTin }; return(Ok(quantityInfo)); } catch (ArgumentException ae) { return(NotFound()); } catch (Exception e) { return(BadRequest(e.Message)); } }
/// <summary> /// First step to create our map is to place the rooms we want in our map. /// This will NumberOfRoomPlacementRetries attempt to place a randomly sized room /// in a random location on the map. /// </summary> private void PlaceRegions() { for (int numberOfPlacementAttempts = 0; numberOfPlacementAttempts < NumberOfRoomPlacementRetries; numberOfPlacementAttempts++) { Room newRoom = null; newRoom = SquareRoom.CreateRandomSizedRoom(MinRegionWidth, MaxRegionWidth, MinRegionHeight, MaxRegionHeight); PlaceRoomRandomly(newRoom); } }
void Start() { SquareRoom startRoom = gameObject.AddComponent <SquareRoom> (); startRoom.Initialize(12); additionQueue.Enqueue(startRoom); int repeat = Random.Range(0, 3); while (repeat-- > 0) { additionQueue.Enqueue(startRoom); } }
public void WhenICallCalculateCoverage_ThenTinsRequiredIsCalculatedCorrectly() { _mockQueryHandler.Setup(x => x.Handle(It.IsAny <IPaintDetailsQuery>())) .Returns(_paints); double H = 1, W = 2, L = 3, coverage = 10.0; var room = new SquareRoom() { Height = H, Width = W, Length = L }; double expectedTinsRequired = room.CalculateArea() / coverage; var rslt = _paintService.CalculateCoverage(room, 1); rslt.TinsRequired.Should().Be(expectedTinsRequired); }
public void WhenICallCalculateCoverageWithInvalidPaintId_ThenItThrowsArgumentException() { _mockQueryHandler.Setup(x => x.Handle(It.IsAny <IPaintDetailsQuery>())) .Returns(_emptyPaints); double H = 1, W = 2, L = 3, coverage = 10.0; int paintId = 1; var room = new SquareRoom() { Height = H, Width = W, Length = L }; double expectedTinsRequired = room.CalculateArea() / coverage; _paintService.Invoking(p => p.CalculateCoverage(room, paintId)) .Should().Throw <ArgumentException>(); }
/// <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); }
public void Setup() { _squareRoom = new SquareRoom(); }