public void setCell(Vector2 v, MAP_REF ct) { int x = (int)v.x; int y = (int)v.y; RefMap[x, y] = ct; }
public Board(int xs, int ys, int px, int py) { this.xsize = xs; this.ysize = ys; this.pieceXSize = px; this.pieceYSize = py; board = new Piece[xsize * ysize]; RefMap = new MAP_REF[xsize , ysize]; setEmptyBoard(); }
public Board(int xs, int ys, int px, int py, int minLength, int maxLength) { this.xsize = xs; this.ysize = ys; this.pieceXSize = px; this.pieceYSize = py; this.minLength = minLength; this.maxLength = maxLength; //board = new Piece[xsize * ysize]; RefMap = new MAP_REF[xsize , ysize]; setEmptyBoard(); }
public void setCell(int x, int y, MAP_REF mr) { RefMap[x, y] = mr; }
public void setCell(Vector2 v, MAP_REF ct) { int x = (int)v.x; int y = (int)v.y; RefMap[x,y] = ct; }
private bool makeFitRoom(int xlength, int ylength, Room r, int incDir, Vector2 ent, ArrayList doors, int numDoors) { //x and y should be made so it is outside of the door (basically inside the new room) /* int xPos = 0; int xNeg = 0; int yPos = 0; int yNeg = 0; bool xpFound = false; bool xnFound = false; bool ypFound = false; bool ynFound = false; */ Debug.Log("xL = " + xlength + ", yL = " + ylength); // NEW TEST MAP_REF[,] room = new MAP_REF[xlength, ylength]; #region north //Dir = north if (incDir == 2) { Debug.Log("Making North"); //room[xlength / 2, 0] = MAP_REF.FLOOR; for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { if (RefMap[(int)ent.x - (xlength / 2) + w, (int)ent.y + l] == MAP_REF.UNUSED) { if (w == 0 || w == xlength - 1 || l == 0 || l == ylength - 1) { if (w == 0 && l == 0) r.cor3 = new Vector2((int)ent.x - (xlength / 2) + w, (int)ent.y); if (w == 0 && l == ylength - 1) r.cor1 = new Vector2((int)ent.x - (xlength / 2) + w, (int)ent.y + l); if (w == xlength - 1 && l == 0) r.cor4 = new Vector2((int)ent.x + (xlength / 2), (int)ent.y); if (w == xlength - 1 && l == ylength - 1) r.cor2 = new Vector2((int)ent.x + (xlength / 2), (int)ent.y + l); //set wall room[w, l] = MAP_REF.WALL; } else {//set floor room[w, l] = MAP_REF.FLOOR; } } else { room[w, l] = RefMap[(int)ent.x - (xlength / 2) + w, (int)ent.y + l]; } } } int doorsMade = 0; for(int d = 0; d < doors.Count; d++) { //Debug.Log("Array Content" + doors[d]); switch ((int)doors[d]) { case 0: Debug.Log("Making door N"); int[] coord = new int[] { Random.Range(1, xlength - 1), ylength - 1 }; if(room[coord[0],coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 1: Debug.Log("Making door W"); coord = new int[] { 0, Random.Range(1, ylength - 1) }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 2: Debug.Log("Making door E"); coord = new int[] { xlength - 1, Random.Range(1, ylength - 1) }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; } if(doorsMade == numDoors) { break; } } Debug.Log("entrance v: " + ent.x + "," + ent.y + ". cor1="+r.cor1+", c2:"+r.cor2); // LINK room to refMap for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { setCell((int)ent.x - (xlength / 2) + w, (int)ent.y + l, room[w, l]); // RefMap[x - (xlength / 2) + w, y + l] = room[w, l]; } } } #endregion //East if (incDir == 1) { Debug.Log("Making East"); room[xlength-1, ylength/2] = MAP_REF.FLOOR; for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { if (RefMap[(int)ent.x + w, (int)ent.y-ylength/2 + l] == MAP_REF.UNUSED) { if (w == 0 || w == xlength - 1 || l == 0 || l == ylength - 1) { if (w == 0 && l == 0) r.cor1 = new Vector2((int)ent.x + w, (int)ent.y + ylength / 2 ); if (w == 0 && l == ylength - 1) r.cor3 = new Vector2((int)ent.x + w, (int)ent.y - ylength / 2); if (w == xlength - 1 && l == 0) r.cor2 = new Vector2((int)ent.x + w, (int)ent.y + ylength / 2 ); if (w == xlength - 1 && l == ylength - 1) r.cor4 = new Vector2((int)ent.x + w, (int)ent.y - ylength / 2); //set wall room[w, l] = MAP_REF.WALL; } else {//set floor room[w, l] = MAP_REF.FLOOR; } } else { room[w, l] = RefMap[(int)ent.x + w, (int)ent.y-ylength/2 + l]; } } } int doorsMade = 0; for (int d = 0; d < doors.Count; d++) { switch ((int)doors[d]) { case 0: Debug.Log("Making door E"); int[] coord = new int[] { xlength - 1, (int)Random.Range(1, ylength - 1) }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 1: Debug.Log("Making door N"); coord = new int[] { (int)Random.Range(1, xlength - 1), ylength - 1 }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 2: Debug.Log("Making door S"); coord = new int[] { (int)Random.Range(1, xlength - 1), 0 }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; } if (doorsMade == numDoors) { break; } } // LINK room to refMap for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { setCell((int)ent.x + w, (int)ent.y -ylength/2+ l, room[w, l]); // RefMap[x - (xlength / 2) + w, y + l] = room[w, l]; } } } //SOUTH if (incDir == 0) { Debug.Log("Making South"); room[xlength / 2, 0] = MAP_REF.FLOOR; for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { if (RefMap[(int)ent.x - (xlength / 2) + w, (int)ent.y - l] == MAP_REF.UNUSED) { if (w == 0 || w == xlength - 1 || l == 0 || l == ylength - 1) { if (w == 0 && l == 0) r.cor3 = new Vector2((int)ent.x - (xlength / 2), (int)ent.y-ylength+1); if (w == 0 && l == ylength - 1) r.cor1 = new Vector2((int)ent.x - (xlength / 2), (int)ent.y); if (w == xlength - 1 && l == 0) r.cor4 = new Vector2((int)ent.x + (xlength / 2), (int)ent.y-ylength+1); if (w == xlength - 1 && l == ylength - 1) r.cor2 = new Vector2((int)ent.x + (xlength / 2), (int)ent.y); //set wall room[w, l] = MAP_REF.WALL; } else {//set floor room[w, l] = MAP_REF.FLOOR; } } else { room[w, l] = RefMap[(int)ent.x - (xlength / 2) + w, (int)ent.y - l]; } } } int doorsMade = 0; for (int d = 0; d < doors.Count; d++) { switch ((int)doors[d]) { case 0: Debug.Log("Making door S"); int[] coord = new int[] { (int)Random.Range(1, xlength - 1), ylength - 1 }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 1: Debug.Log("Making door E"); coord = new int[] { xlength - 1, (int)Random.Range(1, ylength - 1) }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 2: Debug.Log("Making door W"); coord = new int[] { 0, (int)Random.Range(1, ylength - 1) }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; } if(doorsMade == numDoors) { break; } } // LINK room to refMap for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { setCell((int)ent.x - (xlength / 2) + w, (int)ent.y - l, room[w, l]); // RefMap[x - (xlength / 2) + w, y + l] = room[w, l]; } } } //West if (incDir == 3) { Debug.Log("Making West"); room[0, ylength/2] = MAP_REF.FLOOR; for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { if (RefMap[(int)ent.x - w, (int)ent.y-ylength/2 + l] == MAP_REF.UNUSED) { if (w == 0 && l == 0) r.cor1 = new Vector2((int)ent.x - xlength+1, (int)ent.y + ylength / 2); if (w == 0 && l == ylength - 1) r.cor3 = new Vector2((int)ent.x - xlength+1, (int)ent.y - ylength / 2); if (w == xlength - 1 && l == 0) r.cor2 = new Vector2((int)ent.x, (int)ent.y + ylength / 2); if (w == xlength - 1 && l == ylength - 1) r.cor4 = new Vector2((int)ent.x, (int)ent.y - ylength / 2 ); if (w == 0 || w == xlength - 1 || l == 0 || l == ylength - 1) { //set wall room[w, l] = MAP_REF.WALL; } else {//set floor room[w, l] = MAP_REF.FLOOR; } } else { room[w, l] = RefMap[(int)ent.x - w, (int)ent.y -ylength/2 + l]; } } } int doorsMade = 0; for (int d = 0; d < doors.Count; d++) { //Debug.Log("Array Content" + doors[d]); switch ((int)doors[d]) { case 0: Debug.Log("Making door W"); int[] coord = new int[] { xlength-1, Random.Range(1, ylength - 1) }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 1: Debug.Log("Making door S"); coord = new int[] { (int)Random.Range(1, xlength - 1), 0 }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; case 2: Debug.Log("Making door N"); coord = new int[] { (int)Random.Range(1, xlength - 1), ylength - 1 }; if (room[coord[0], coord[1]] == MAP_REF.WALL) { room[coord[0], coord[1]] = MAP_REF.DOOR; doorsMade++; } break; } if(doorsMade == numDoors) { break; } } // LINK room to refMap for (int w = 0; w < xlength; w++) { for (int l = 0; l < ylength; l++) { setCell((int)ent.x - w, (int)ent.y -ylength/2+ l, room[w, l]); // RefMap[x - (xlength / 2) + w, y + l] = room[w, l]; } } } #region oldDoors // SET DOORS! //makeRandomDoorInRoom(r, (int)r.cor1.x, (int)r.cor1.y, 0); //makeRandomDoorInRoom(r, (int)r.cor2.x, (int)r.cor2.y, 0); //makeRandomDoorInRoom(r, (int)r.cor3.x, (int)r.cor3.y, 0); //makeRandomDoorInRoom(r, (int)r.cor4.x, (int)r.cor4.y, 0); /*for (int a = 0; a < numDoors; a++) { switch ((int)doors[a]) { case 0: //north door - (c1x+c2) /2, c1.y makeRandomDoorInRoom(r,(int)r.cor1.x+(xlength/2), (int)r.cor1.y, 0 );//(int)(r.cor3.x + r.cor4.x) / 2, (int)r.cor3.y, 0); break; case 1: //east door makeRandomDoorInRoom(r, (int)r.cor2.x, (int)r.cor2.y-(ylength/2), 0); break; case 2: //south door makeRandomDoorInRoom(r, (int)r.cor3.x + (xlength / 2), (int)r.cor3.y, 0); break; case 3: //west door makeRandomDoorInRoom(r, (int)r.cor3.x, (int)r.cor3.y + (ylength / 2), 0); break; } }*/ // new test for splitting room in accurate sizes: /* for(int i = 0; i < xlength/2; i++) { if(getCell(x+i, y) == MAP_REF.UNUSED && !xpFound && x+i != 0 && x+i != xsize) { xPos++; } else { xpFound = true; } if (getCell(x - i, y) == MAP_REF.UNUSED && !xnFound && x - i != 0 && x - i != xsize) { xNeg++; } else { xnFound = true; } } for (int j = 0; j < ylength/2; j++) { if (getCell(x, y - j) == MAP_REF.UNUSED && !ynFound && y - j != 0 && y - j != ysize) { yNeg++; } else { ynFound = true; } if (getCell(x, y + j) == MAP_REF.UNUSED && !ypFound && y + j != 0 && y + j != ysize) { yPos++; } else { ypFound = true; } } // X values if(!(xNeg+xPos == xlength)) { while(xNeg<xlength && getCell(xNeg, y)==MAP_REF.UNUSED && xNeg + xPos < xlength) { if(getCell(xNeg+1, y) == MAP_REF.UNUSED) { xNeg++; } else { break; } } while (xPos < xlength && getCell(xPos, y) == MAP_REF.UNUSED && xNeg + xPos < xlength) { if (getCell(xPos + 1, y) == MAP_REF.UNUSED) { xPos++; } else { break; } } } // Y values if (!(yNeg + yPos == ylength)) { while (yNeg < ylength && getCell(x, yNeg) == MAP_REF.UNUSED && yNeg + yPos < ylength) { if (getCell(x, yNeg+1) == MAP_REF.UNUSED) { yNeg++; } else { break; } } while (yPos < ylength && getCell(x, yPos) == MAP_REF.UNUSED && yNeg + yPos < ylength) { if (getCell(x, yPos+1) == MAP_REF.UNUSED) { yPos++; } else { break; } } }*/ /////// End /////// /* for (int i = 0; i < xlength; i++) { //Debug.Log("x = " + i + ", y = " + y); //Debug.Log(getCell(x + i, y)); if (getCell(x+i, y) == MAP_REF.UNUSED && !xpFound && x+i != 0 && x+i != xsize) { xPos++; } else { xpFound = true; } if (getCell(x-i, y) == MAP_REF.UNUSED && !xnFound && x - i != 0 && x- i != xsize) { xNeg++; } else { xnFound = true; } } for (int j = 0; j < ylength; j++) { if (getCell(x, y-j) == MAP_REF.UNUSED && !ynFound && y-j != 0 && y-j != ysize) { yNeg++; } else { ynFound = true; } if (getCell(x, y+j) == MAP_REF.UNUSED && !ypFound && y + j != 0 && y + j != ysize) { yPos++; } else { ypFound = true; } }*/ //Debug.Log("xPos = " + xPos + ", xNeg = " + xNeg + ", yPos = " + yPos + ", yNeg = " + yNeg); //MAKE SURE THE TOTAL LENGTH IS NOT BIGGER THAT MAX! /* if (xPos == xNeg) { xPos /= 2; xNeg /= 2; } if(yPos == yNeg) { yPos /= 2; yNeg /= 2; }*/ /* for(int w = x-xNeg; w < x+xPos; w++) { for(int l = y-yNeg; l < y+yPos; l++) { if(w==x-xNeg || w == x + xPos-1 || l == y - yNeg || l == y + yPos-1)//lower and higher end { if (getCell(w, l) != MAP_REF.WALL || getCell(w, l) == MAP_REF.UNUSED) { if(getCell(w, l) != MAP_REF.DOOR) { setCell(w, l, MAP_REF.WALL); } } }else { setCell(w, l, MAP_REF.FLOOR); } } }*/ //Debug.Log(doorPlace + " = doorplace"); /* int xVal = 0; int yVal = 0; if (xPos > xNeg) { xVal = xPos; } else { xVal = xNeg; } if (yPos > yNeg) { yVal = yPos; } else { yVal = yNeg; } */ /* x+xVal = Right y+yVal = Up x-xneg = left x */ /*ArrayList doors = new ArrayList(); //int nod = Random.Range(1, 4); for(int a = 0; a < numberOfDoors; a++) { Debug.Log("Adding " + numberOfDoors + "doors to list"); bool placed = false; while (!placed) { int d = Random.Range(0, 3); if (!doors.Contains(d)) { doors.Add(d); placed = true; } } }*/ //Debug.Log("Done adding doors to list"); /* while (numDoors > 0) { int doorPlace = (int)doors[0];//Random.Range(0, 3); switch (incDir) { case 0://NorthFacing room //North, east and west if (doorPlace == 0)//North { makeRandomDoorInRoom(r, ((x - xNeg) + (x + xPos - 1)) / 2, y - yVal, 0); } else if (doorPlace == 1)//east { makeRandomDoorInRoom(r, x + xPos - 1, ((y - yNeg) + (y + yPos - 1)) / 2, 0); } else { makeRandomDoorInRoom(r, x - xNeg, ((y - yNeg) + (y + yPos - 1)) / 2, 0); } break; case 1://Eastfacing //East, north and south if (doorPlace == 0) { makeRandomDoorInRoom(r, x + xPos - 1, ((y - yNeg) + (y + yPos - 1)) / 2, 0); } else if (doorPlace == 1) { makeRandomDoorInRoom(r, ((x - xNeg) + (x + xPos - 1)) / 2, y - yVal, 0); } else { makeRandomDoorInRoom(r, ((x - xNeg) + (x + xPos - 1)) / 2, y + yVal - 1, 0); } break; case 2://southfacing //south, east and west if (doorPlace == 0) { makeRandomDoorInRoom(r, ((x - xNeg) + (x + xPos - 1)) / 2, y + yVal - 1, 0); } else if (doorPlace == 1) { makeRandomDoorInRoom(r, x + xPos - 1, ((y - yNeg) + (y + yPos - 1)) / 2, 0); } else { makeRandomDoorInRoom(r, x - xNeg, ((y - yNeg) + (y + yPos - 1)) / 2, 0); } break; case 3://westfacing //west, south and north if (doorPlace == 0) { makeRandomDoorInRoom(r, x - xNeg, ((y - yNeg) + (y + yPos - 1)) / 2, 0); } else if (doorPlace == 1) { makeRandomDoorInRoom(r, ((x - xNeg) + (x + xPos - 1)) / 2, y + yVal - 1, 0); } else { makeRandomDoorInRoom(r, ((x - xNeg) + (x + xPos - 1)) / 2, y - yVal, 0); } break; } doors.RemoveAt(0); numDoors--; }*/ #endregion cleanMissedDoors (); setCell(r.startX, r.startY, MAP_REF.FLOOR); setCell((int)ent.x, (int)ent.y, MAP_REF.FLOOR); /*setCell((int)ent.x, (int)ent.y+1, MAP_REF.FLOOR); setCell((int)ent.x, (int)ent.y-1, MAP_REF.FLOOR); setCell((int)ent.x+1, (int)ent.y, MAP_REF.FLOOR); setCell((int)ent.x-1, (int)ent.y, MAP_REF.FLOOR);*/ return true; }
/* public void placePiece(Piece p) { int psx = p.xStart; int psy = p.yStart; } */ public void setCell(int x, int y, MAP_REF mr) { if(mr == MAP_REF.DOOR) { if(x+maxLength >= RefMap.GetLength(0) || y+maxLength >= RefMap.GetLength(1) || x-maxLength <= 0 || y- maxLength <= 0) { mr = MAP_REF.WALL; } } RefMap[x, y] = mr; }