Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MapeczkiKomorkowe
- {
- class Room
- {
- int[,] room;
- int n, s, l, r;
- int sizeX, sizeY;
- private int generations;
- private Random random;
- private int sfp;
- List<List<IntVector2>> nFreeTiles = new List<List<IntVector2>>();
- List<List<IntVector2>> sFreeTiles = new List<List<IntVector2>>();
- List<List<IntVector2>> lFreeTiles = new List<List<IntVector2>>();
- List<List<IntVector2>> rFreeTiles = new List<List<IntVector2>>();
- public Room(int sizeX, int sizeY, int north, int south, int left, int right, Random rrandom, int startingFloorsPrc)
- {
- this.sizeX = sizeX;
- this.sizeY = sizeY;
- room = new int[sizeX, sizeY];
- n = north;
- s = south;
- l = left;
- r = right;
- sfp = startingFloorsPrc;
- random = rrandom;
- }
- private void FillWithVoid()
- {
- for (int i = 0; i < sizeX; i++)
- {
- for (int j = 0; j < sizeY; j++)
- {
- room[i, j] = Tile.VOID;
- }
- }
- }
- private void FillRandomly()
- {
- for (int x = 1; x < sizeX-1; x++)
- {
- for (int y = 1; y < sizeY-1; y++)
- {
- if (random.Next(0, 101) <= sfp)
- room[x, y] = Tile.FLOOR;
- }
- }
- }
- private void CalculateDoors()
- {
- int sx = sizeX;
- int sy = sizeY;
- while (sx % 4 != 0)
- {
- sx -= 2;
- }
- while (sy % 4 != 0)
- {
- sy -= 2;
- }
- int passageSizeX = sx/4;
- int passageSizeY = sy/4;
- int shiftX = sizeX - sx;
- int shiftY = sizeY = sy;
- List<IntVector2> temp = new List<IntVector2>();
- for (int i = 0; i < 4; i++)
- {
- for(int j=0; j<passageSizeX; j++)
- {
- temp.Add(new IntVector2(0, i * passageSizeX + j));
- temp.Add(new IntVector2(1, i * passageSizeX + j));
- }
- nFreeTiles.Add(temp);
- temp.Clear();
- }
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < passageSizeX; j++)
- {
- temp.Add(new IntVector2(sizeY - 1, i * passageSizeX + j));
- temp.Add(new IntVector2(sizeY - 2, i * passageSizeX + j));
- }
- sFreeTiles.Add(temp);
- temp.Clear();
- }
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < passageSizeY; j++)
- {
- temp.Add(new IntVector2(i * passageSizeY + j, 0));
- temp.Add(new IntVector2(i * passageSizeY + j, 1));
- }
- lFreeTiles.Add(temp);
- temp.Clear();
- }
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < passageSizeY; j++)
- {
- temp.Add(new IntVector2(i * passageSizeY + j, sizeX - 1));
- temp.Add(new IntVector2(i * passageSizeY + j, sizeX - 2));
- }
- rFreeTiles.Add(temp);
- temp.Clear();
- }
- }
- private void PlaceDoors()
- {
- if (n != 0)
- {
- foreach (IntVector2 iv in nFreeTiles[n-1])
- {
- room[iv.x, iv.y] = Tile.FLOOR;
- }
- }
- }
- private bool CheckIfAllPassagesExists()
- {
- bool passable = true;
- if (n != 0 && s != 0)
- { }
- if (n != 0 && l != 0)
- { }
- if (n != 0 && r != 0)
- { }
- if (s != 0 && l != 0)
- { }
- if (s != 0 && r != 0)
- { }
- if (r != 0 && l != 0)
- { }
- return passable;
- }
- private int CntCellNeighboursWalls(int x, int y)
- {
- int n = 0;
- if (room[x + 1, y] == Tile.VOID)
- n++;
- if (room[x - 1, y] == Tile.VOID)
- n++;
- if (room[x, y + 1] == Tile.VOID)
- n++;
- if (room[x, y - 1] == Tile.VOID)
- n++;
- if (room[x + 1, y + 1] == Tile.VOID)
- n++;
- if (room[x - 1, y - 1] == Tile.VOID)
- n++;
- if (room[x + 1, y - 1] == Tile.VOID)
- n++;
- if (room[x - 1, y + 1] == Tile.VOID)
- n++;
- return n;
- }
- private int CntCellNeighboursWalls2(int x, int y)
- {
- int n = 0;
- for (int i = -2; i < 3; i++)
- {
- for (int j = -2; j < 3; j++)
- {
- if (i != 0 || j != 0)
- {
- if (isFineCoords(x + i, y + j))
- {
- if (map[x + i, y + j] == VOID)
- n++;
- }
- }
- }
- }
- return n;
- }
- private bool isFineCoords(int x, int y)
- {
- if (x >= 0 && x <= sizeX + 1 && y >= 0 && y <= sizeY + 1)
- { return true; }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement