public void FillRandomly() { int randomIndex = UnityEngine.Random.Range(0, EmptyCells.Count); GridCell cell = EmptyCells.ElementAt(randomIndex); cell.FillSelfWithRandomOption(); }
//-------------------------------------------------Перемещение камеры( SM - Scrolling of Move )-----------------------------------------------------------------\\ static public void SM_Drawing(ScreenSideofDrawing VectorofScrolling, bool ReDraw) { /* * Метод перерисовки клеток * при * * скроллинге перемещения * * ( метод ScrollingMove в классе ScrollPosition ) * */ byte VoS = (byte)VectorofScrolling; // Подготовка IndexX = ScrollPosition.GetCameraX() - 1; // IndexY = ScrollPosition.GetCameraY() - 1; // метода IndexX = IndexX - RowsCount; // ( задание начальных IndexY = IndexY - RowsCount; // значений переменных while (ScrollPosition.GetCameraX() - 1 + RowsCount + 1 > IndexX) // Перемещение { while (ScrollPosition.GetCameraY() - 1 + RowsCount + 1 > IndexY) // // камеры { EmptyCells.SM_OffsetingImages(IndexX, IndexY, cellhgh, VoS); // IndexY++; // ( клеток } // в обратную IndexX++; // сторону ) IndexY = IndexY - (2 * RowsCount) - 1; // } if (ReDraw == true) // добавление и удаление картинок { EmptyCells.SM_DeletingCells(RowsCount, VoS); // удаление ячеек, что попали за границу экрана EmptyCells.SM_AddingCells(RowsCount, VoS, cellhgh); // отрисовка ячеек, что были за границей экрана } }
//----------------------------------------------------------------------------------------------------------------------------------\\ static public void Drawing(Grid grid) { /* * Метод отрисовки картинок * ячеек на старте игры * и при скроллинге * приближения и отдаления */ //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\ if (SystemParameters.PrimaryScreenHeight > SystemParameters.PrimaryScreenWidth) { cellhgh = Convert.ToInt32(SystemParameters.PrimaryScreenHeight / (5 + ScrollPosition.GetAprx())); //cellhgh = ширина экрана / (5*scrollposition.aprx) } else { cellhgh = Convert.ToInt32(SystemParameters.PrimaryScreenWidth / (5 + ScrollPosition.GetAprx())); } cellhghVisual = cellhgh - cellhghOffsetDist + cellhghOffsetAprx; //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------\\ IndexX = ScrollPosition.GetCameraX() - 1; IndexY = ScrollPosition.GetCameraY() - 1; EmptyCells.SetGridImage(IndexX, IndexY, grid); EmptyCells.SetImagePosition(IndexX, IndexY, cellhgh); valueconst = 3; while (valueconst < ScrollPosition.GetAprx() + 7) { value = valueconst; RowsCount = (valueconst - 1) / 2; IndexX = IndexX + RowsCount; IndexY = IndexY + RowsCount; while (value > 0) { EmptyCells.SetGridImage(IndexX, IndexY, grid); EmptyCells.SetImagePosition(IndexX, IndexY, cellhghVisual, RowsCount, valueconst, value, ScreenSideofDrawing.SD_BottomSide); IndexX--; value--; } IndexY--; value = valueconst - 1; while (value > 0) { EmptyCells.SetGridImage(IndexX, IndexY, grid); EmptyCells.SetImagePosition(IndexX, IndexY, cellhghVisual, RowsCount, valueconst, value, ScreenSideofDrawing.SD_LeftSide); IndexY--; value--; } IndexX++; value = valueconst - 1; while (value > 0) { EmptyCells.SetGridImage(IndexX, IndexY, grid); EmptyCells.SetImagePosition(IndexX, IndexY, cellhghVisual, RowsCount, valueconst, value, ScreenSideofDrawing.SD_RightSide); IndexX++; value--; } IndexY++; value = valueconst - 2; while (value > 0) { EmptyCells.SetGridImage(IndexX, IndexY, grid); EmptyCells.SetImagePosition(IndexX, IndexY, cellhghVisual, RowsCount, valueconst, value, ScreenSideofDrawing.SD_TopSide); IndexY++; value--; } IndexX = ScrollPosition.GetCameraX() - 1; IndexY = ScrollPosition.GetCameraY() - 1; valueconst += 2; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { EmptyCells.GridInitialization(); Logic.Drawing(maingrid); }
public void SpawnField(int sizeX, int sizeY) { SetupCamera(sizeX + 2, sizeY + 2); CleanField(); //Field generation and filling lists of each cell's neighbours for (int i = 0; i < sizeX + 2; i++) { for (int j = 0; j < sizeY + 2; j++) { Cells.Add(new Cell()); Cells[i * (sizeY + 2) + j].Position = new Vector2(i, j); x = i; y = 0; z = j; position = new Vector3(x, y, z); if (i >= 1 && j >= 1 && i < sizeX + 1 && j < sizeY + 1) { instance = Instantiate(_config.Floor); instance.transform.position = position; instance.transform.SetParent(floorParent); Cells[i * (sizeY + 2) + j].IsWalkable = true; Cells[i * (sizeY + 2) + j].IsFlyable = true; if (j % 2 == 0 && i % 2 == 0) { instance = Instantiate(_config.InnerWall); instance.transform.position = position; instance.transform.SetParent(innerWallsParent); Cells[i * (sizeY + 2) + j].IsWalkable = false; } else if (!(i == 1 && j == 1)) { instance = Instantiate(_config.Food); instance.transform.position = position; instance.transform.SetParent(foodParent); _gameManager.FoodAmount++; } //Filling neighbours of each cell if (j > 1) { Cells[i * (sizeY + 2) + j].SetNeighbour(Cells[i * (sizeY + 2) + j - 1]); Cells[i * (sizeY + 2) + j - 1].SetNeighbour(Cells[i * (sizeY + 2) + j]); } if (i > 1) { Cells[i * (sizeY + 2) + j].SetNeighbour(Cells[(i - 1) * (sizeY + 2) + j]); Cells[(i - 1) * (sizeY + 2) + j].SetNeighbour(Cells[i * (sizeY + 2) + j]); } } else { instance = Instantiate(_config.OuterWall); instance.transform.position = position; instance.transform.SetParent(outerWallsParent); Cells[i * (sizeY + 2) + j].IsWalkable = false; Cells[i * (sizeY + 2) + j].IsFlyable = false; } if (Cells[i * (sizeY + 2) + j].IsWalkable) { EmptyCells.Add(Cells[i * (sizeY + 2) + j]); } } } SpawnEnemies(_config.Levels[_gameManager.CurrentLevel].EnemyAmount); }
public void FillLowestEntropy() { GridCell cellWithLeastOptions = EmptyCells.OrderBy(item => item.Options.Count).First(); cellWithLeastOptions.FillSelfWithRandomOption(); }