private void RemoveWall(CellObj current, CellObj chosen) { if (current.X == chosen.X) { if (current.Y > chosen.Y) { current.WallBottom = false; } else { chosen.WallBottom = false; } } else { if (current.X > chosen.X) { current.WallLeft = false; } else { chosen.WallLeft = false; } } }
public void CreateGird(int cols, int rows) { mCols = cols; mRows = rows; float x = mStartX, y = mStartY, z = 1f; for (int r = 0; r < mRows; r++) { List <GameObject> RowCells = new List <GameObject> (); x = mStartX; for (int c = 0; c < mCols; c++) { GameObject _cellObj = Instantiate(Resources.Load("Prefabs/CellObj", typeof(GameObject))) as GameObject; _cellObj.transform.position = new Vector3(x, y, z); CellObj cellObjectScript = _cellObj.GetComponent <CellObj> (); cellObjectScript.SetCurrentSliceData(false, 0f, 0f, 0f); cellObjectScript.ClearSlices(); //some redundancey RowCells.Add(_cellObj); x += mDeltaX; } y += mDeltaY; GridCells.Add(RowCells); } }
public void DestroyRandom() { dropFruit(); if (PlayerInfo.MODE == 1) { if (!IsStar) { List <CellObj> listeff = getListCellEffect(); if (listeff.Count > 0) { CellObj tmp = listeff[Random.Range(0, listeff.Count)]; tmp.RemoveEffect(); EffectSpawner.effect.Thunder(GridManager.grid.GridCell[(int)tmp.Cell.CellPosition.x, (int)tmp.Cell.CellPosition.y].transform.position); } else { destroyNotEmpty(); } } else { Vector2 vtmp = posUnderStar(); FruitObj tmp = FruitSpawner.spawn.FruitGridScript[(int)vtmp.x, (int)vtmp.y]; if (tmp != null && tmp != FruitStar) { tmp.Destroy(); EffectSpawner.effect.Thunder(GridManager.grid.GridCell[(int)tmp.Fruit.FruitPosition.x, (int)tmp.Fruit.FruitPosition.y].transform.position); } } } }
public void DestroyRandom() { //uu tien destroy ganh dropjewel(); if (PLayerInfo.MODE == 1) { if (!isStar) { List <CellObj> listeff = getListCellEffect(); if (listeff.Count > 0) { CellObj tmp = listeff[Random.Range(0, listeff.Count)]; tmp.RemoveEffect(); EffectSpawner.effect.Thunder(GribManager.cell.GribCell[(int)tmp.cell.CellPosition.x, (int)tmp.cell.CellPosition.y].transform.position); } else { destroynotempty(); } } else { Vector2 vtmp = posUnderStar(); JewelObj tmp = JewelSpawner.spawn.JewelGribScript[(int)vtmp.x, (int)vtmp.y]; if (tmp != null && tmp != JewelStar) { tmp.Destroy(); EffectSpawner.effect.Thunder(GribManager.cell.GribCell[(int)tmp.jewel.JewelPosition.x, (int)tmp.jewel.JewelPosition.y].transform.position); } } } }
void CellInstantiate(int x, int y, int type) { ObjTmp = (GameObject)Instantiate(CellPrefab); ObjTmp.transform.SetParent(GribParent.transform, false); ObjTmp.transform.localPosition = new Vector3(x, y); cellscript = ObjTmp.GetComponent <CellObj>(); cellscript.CellCode = type; cellscript.cell = SetCell(type, x, y); cellscript.SetSprite(cellscript.cell.CellType - 1); GribCell[x, y] = ObjTmp; GribCellObj[x, y] = cellscript; }
//public bool GetRuleResult(int state, int fitness) private void ProcessRule(GameObject _cellObj, int fitness) { CellObj cellObjectScript = _cellObj.GetComponent <CellObj> (); bool isAlive = cellObjectScript.GetCurrentSliceIsAlive(); bool lifeState = false; //survive if (isAlive == true) { for (int i = 0; i < surroundingCells; i++) { int rule = rulesSurvive [i]; if (rule == -1) { break; } else { if (fitness == rule) { lifeState = true; break; } } } } //born if (isAlive == false) { for (int i = 0; i < surroundingCells; i++) { int rule = rulesBorn [i]; if (rule == -1) { break; } else { if (fitness == rule) { lifeState = true; break; } } } } cellObjectScript.SetOffScreenSliceState(lifeState); }
private int GetCellLife(GameObject _cellObj) { CellObj cellObjectScript = _cellObj.GetComponent <CellObj> (); if (cellObjectScript.GetCurrentSliceIsAlive()) { return(1); } else { return(0); } }
bool CornerOutCheckTop(GameObject parent) { CellObj obj = parent.GetComponent <CellObj>(); int x = (int)obj.cell.CellPosition.x; int y = (int)obj.cell.CellPosition.y; for (int i = y + 1; i < 9; i++) { if (GribCellObj[x, i] != null) { return(false); } } return(true); }
bool CornerOutCheckLeft(GameObject parent) { CellObj obj = parent.GetComponent <CellObj>(); int x = (int)obj.cell.CellPosition.x; int y = (int)obj.cell.CellPosition.y; for (int i = x - 1; i >= 0; i--) { if (GribCellObj[i, y] != null) { return(false); } } return(true); }
public void FlipGrid() { for (int r = 0; r < mRows; r++) { List <GameObject> rowCells = GridCells [r]; for (int c = 0; c < mCols; c++) { GameObject _cellObj = rowCells [c]; CellObj cellObjectScript = _cellObj.GetComponent <CellObj> (); cellObjectScript.FlipSlices(); } } }
public CellObj[,] GenerateMaze() { var maze = new CellObj[Width, Height]; for (int x = 0; x < maze.GetLength(0); x++) { for (int y = 0; y < maze.GetLength(1); y++) { maze[x, y] = new CellObj { X = x, Y = y }; if (x + 1 == maze.GetLength(0)) { maze[x, y].WallBottom = false; maze[x, y].Floor = false; maze[x, y].WallLeftBorder = true; maze[x, y].WallLeft = false; } if (y + 1 == maze.GetLength(1)) { maze[x, y].WallLeft = false; maze[x, y].Floor = false; maze[x, y].WallBottomBorder = true; maze[x, y].WallBottom = false; } if (x == 0) { maze[x, y].WallLeftBorder = true; maze[x, y].WallLeft = false; } if (y == 0) { maze[x, y].WallBottomBorder = true; maze[x, y].WallBottom = false; } } } RemoveWalls(maze); PlaceItems(maze); PlaceExit(maze); return(maze); }
// 随机消除一个宝石 public void DestroyRandom() { //uu tien destroy ganh dropjewel();// 开启下落检查 // 如果是街机模式 if (PLayerInfo.MODE == 1) { // 如果没有星星宝石 if (!isStar) { // 获取有特效的格子列表 List <CellObj> listeff = getListCellEffect(); // 如果有这样的格子 if (listeff.Count > 0) { // 从列表中随机获取一个格子 CellObj tmp = listeff[Random.Range(0, listeff.Count)]; // 播放并移除特效 tmp.RemoveEffect(); // 播放火球特效 EffectSpawner.effect.Thunder(GribManager.cell.GribCell[(int)tmp.cell.CellPosition.x, (int)tmp.cell.CellPosition.y].transform.position); } else { // 从特殊格子中随机一个消除 destroynotempty(); } } else { // 星星下方随机一个图块坐标 Vector2 vtmp = posUnderStar(); // 根据坐标获取宝石对象 JewelObj tmp = JewelSpawner.spawn.JewelGribScript[(int)vtmp.x, (int)vtmp.y]; // 如果该宝石对象不为空且不是星星宝石 if (tmp != null && tmp != JewelStar) { // 销毁该对象 tmp.Destroy(); // 播放火球特效 EffectSpawner.effect.Thunder(GribManager.cell.GribCell[(int)tmp.jewel.JewelPosition.x, (int)tmp.jewel.JewelPosition.y].transform.position); } } } }
private Cell generateCoins(CellObj maze, Cell c) { var x = c.CoinField.transform.position.x; var y = c.CoinField.transform.position.y; var xn = c.CoinField.transform.localScale.x + x; var yn = c.CoinField.transform.localScale.y + y; c.CoinsArray = new GameObject[maze.CoinCount]; for (int i = 0; i < maze.CoinCount; i++) { var rx = Random.Range(x, xn); var ry = Random.Range(y, yn); GameObject coin = Instantiate(c.Coin, new Vector2(rx, ry), Quaternion.identity); coin.SetActive(true); c.CoinsArray[i] = coin; } return(c); }
private void RemoveWalls(CellObj[,] maze) { CellObj current = maze[0, 0]; current.Visited = true; Stack <CellObj> stack = new Stack <CellObj>(); do { List <CellObj> unvisited = new List <CellObj>(); if (current.X > 0 && !maze[current.X - 1, current.Y].Visited) { unvisited.Add(maze[current.X - 1, current.Y]); } if (current.Y > 0 && !maze[current.X, current.Y - 1].Visited) { unvisited.Add(maze[current.X, current.Y - 1]); } if (current.X < Width - 2 && !maze[current.X + 1, current.Y].Visited) { unvisited.Add(maze[current.X + 1, current.Y]); } if (current.Y < Height - 2 && !maze[current.X, current.Y + 1].Visited) { unvisited.Add(maze[current.X, current.Y + 1]); } if (unvisited.Count > 0) { CellObj chosen = unvisited[Random.Range(0, unvisited.Count)]; RemoveWall(current, chosen); chosen.Visited = true; stack.Push(chosen); current = chosen; } else { current = stack.Pop(); } } while (stack.Count > 0); RemoveRandomWalls(maze); }
public void CreateRandomGrid(int frequency, int rangeX, int rangeY) { for (int r = rangeY; r < mRows - rangeY; r++) { List <GameObject> rowCells = GridCells [r]; for (int c = rangeX; c < mCols - rangeX; c++) { int value = Random.Range(0, 100); if (value < frequency) { GameObject _cellObj = rowCells [c]; CellObj cellObjectScript = _cellObj.GetComponent <CellObj> (); cellObjectScript.SetAlive(); } } } }
/// <summary> /// 根据Map来生成对应元素表格 /// </summary> /// <param name="map"></param> void GridCreate(int[,] map) { GameController.gameController.CellNotEmpty = 0; GridCellObj = new CellObj[7, 9]; for (int x = 0; x < 7; x++) { for (int y = 0; y < 9; y++) { if (map[x, y] > 1) { GameController.gameController.CellNotEmpty++; } if (map[x, y] > 0) { CellInstantiate(x, y, map[x, y]); } EffectSpawner.effect.FruitCrashArray[x, y] = EffectSpawner.effect.FruitCrash(new Vector3(x, y)); } } }
void CellInstantiate(int x, int y, int type) { ObjTmp = (GameObject)Instantiate(CellPrefab); ObjTmp.transform.SetParent(GribParent.transform, false); ObjTmp.transform.localPosition = new Vector3(x, y); cellscript = ObjTmp.GetComponent<CellObj>(); cellscript.CellCode = type; cellscript.cell = SetCell(type, x, y); cellscript.SetSprite(cellscript.cell.CellType-1); GribCell[x, y] = ObjTmp; GribCellObj[x, y] = cellscript; }
void Start() { cell = transform.parent.gameObject.GetComponent <CellObj>(); rect = GetComponent <RectTransform>(); }