public static bool CheckRadius(Cell cell, Cell.TypeOfCell cellType) { for (int i = 0; i < 8; i++) { Coordinates checkCoordinate = cell.Coordinate + Coordinates.CoordinateShift[i]; if (GetMapCell(checkCoordinate.Y, checkCoordinate.X).Content == cellType) { return(true); } } return(false); }
public Field(int offset, Cell.TypeOfCell type) { this.offset = offset; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { battleFiieldCells[i, j] = new Cell(); battleFiieldCells[i, j].type = type; battleFiieldCells[i, j].Location = new Point(i * 30 + offset, j * 30 + 50); } } }
/// <summary> /// Ищет свободную пустую клетку /// </summary> /// <returns></returns> public static Cell FindEmptyCell(Cell.TypeOfCell content) { int tryCount = 20; while (tryCount > 0) { Coordinates randomCoordinate = CellLists[(int)Cell.TypeOfCell.Empty][Data.Rnd.Next(0, CellLists[(int)Cell.TypeOfCell.Empty].Count)]; if (Cell.IsFriendlyGround(GetMapCell(randomCoordinate.Y, randomCoordinate.X).Surface, content)) { return(GetMapCell(randomCoordinate.Y, randomCoordinate.X)); } else { tryCount--; } } return(null); }
/// <summary> /// Обновляет клетку в листе клеток и просит пересовать её /// </summary> /// <param name="cell"> Клетка, которую обновляем </param> /// <param name="newType"> Новый тип этой клетки </param> public static void UpdateCellList(Cell cell, Cell.TypeOfCell newType) { if (cell.Surface != Cell.TypeOfCell.Empty) { if ((int)newType < (int)Cell.TypeOfCell.Sea || (int)newType > (int)Cell.TypeOfCell.Basalt) { CellLists[(int)cell.Content].Remove(cell.Coordinate); } else { CellLists[(int)cell.Surface].Remove(cell.Coordinate); } } if (cell.Surface != Cell.TypeOfCell.Empty || newType != Cell.TypeOfCell.Empty) { CellLists[(int)newType].Add(cell.Coordinate); } if ((int)newType < (int)Cell.TypeOfCell.Sea || (int)newType > (int)Cell.TypeOfCell.Basalt) { RenderingScript.UpdateTypeCell(cell); } }