public IEnumerable<CellCost> Calculate(CellType[,] grid, int horizontalPosition, int verticalPosition) { var output = new List<CellCost>(); if (horizontalPosition > 0) { var left = horizontalPosition - 1; var leftCell = grid[verticalPosition, left]; output.Add( new CellCost(verticalPosition, left, GetCost(leftCell))); } if (horizontalPosition < grid.GetLength(1) - 1) { var right = horizontalPosition + 1; var leftCell = grid[verticalPosition, right]; output.Add( new CellCost(verticalPosition, right, GetCost(leftCell))); } if (verticalPosition > 0) { var down = verticalPosition - 1; var leftCell = grid[down, horizontalPosition]; output.Add( new CellCost(down, horizontalPosition, GetCost(leftCell))); } if (verticalPosition < grid.GetLength(0) - 1) { var up = verticalPosition + 1; var leftCell = grid[up, horizontalPosition]; output.Add( new CellCost(up, horizontalPosition, GetCost(leftCell))); } return output; }
private CellType[,] ParseMaze(string data, int[,] move) { var maze = new CellType[7, 7]; //TODO: _rawData = data.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); if (_rawData.Length != maze.GetLength(0)) { throw new Exception("Can't parse maze: " + data); } X = X + move[0, 0]; Y = Y + move[1, 0]; for (int i = 0; i < maze.GetLength(0); i++) { for (int j = 0; j < _rawData[i].Length; j++) { var cellType = MapCellType(_rawData[i][j]); maze[i, j] = cellType; map[i + X, j + Y] = _rawData[i][j]; } } Debug(data); return(maze); }
//internal CMap(MapRepresent_ProD representMap) //{ // colCount = representMap.ColCount; // rowCount = representMap.RowCount; // mx = new CCell[colCount, rowCount]; // for (int i = 0; i < colCount; i++) // for (int j = 0; j < rowCount; j++) // { // var cell = new CCell(i, j, representMap[i, j]); // mx[i, j] = cell; // if (cell.IsWall) wall.Add(cell); // else // switch (cell.Type) // { // case CellType.Entrance: // entranceCell = cell; // break; // case CellType.Exit: // exitCell = cell; // break; // case CellType.Door: // doorCells.Add(cell); // break; // } // } //} internal CMap(CellType[,] cellMatrix) { colCount = cellMatrix.GetLength(0); rowCount = cellMatrix.GetLength(1); mx = new CCell[colCount, rowCount]; for (int i = 0; i < colCount; i++) for (int j = 0; j < rowCount; j++) { var cell = new CCell(i, j, cellMatrix[i, j]); mx[i, j] = cell; if (cell.IsWall) wall.Add(cell); else switch (cell.Type) { case CellType.Entrance: entranceCell = cell; break; case CellType.Exit: exitCell = cell; break; case CellType.Door: doorCells.Add(cell); break; } } }
public void DrawField(GameField field, CellType[,] pt, bool isYours) { lock (lck) { Bitmap newBitmap = isYours ? TempBitmapYours : TempBitmapEnemy; Graphics g = Graphics.FromImage(newBitmap); using (g) { g.Clear(Color.White); g.DrawImage(grid, 0, 0); for (int i = 0; i < pt.GetLength(0); i++) { for (int j = 0; j < pt.GetLength(1); j++) { if (pt[i, j] == CellType.Point) g.FillEllipse(Brushes.Green, i * StructMap.BlockSize + 10, j * StructMap.BlockSize + 10, 10, 10); } } for (int i = 0; i < field.ships.Count; i++) { for (int j = 0; j < field.ships[i].palub.Count; j++) { if (field.ships[i].palub[j].type == DeckType.Live) { g.FillRectangle(Brushes.Red, field.ships[i].palub[j].point.X * StructMap.BlockSize + 1, field.ships[i].palub[j].point.Y * StructMap.BlockSize + 1, StructMap.BlockSize - 1, StructMap.BlockSize - 1); } else if (field.ships[i].palub[j].type == DeckType.Hurt) { g.FillRectangle(Brushes.Orange, field.ships[i].palub[j].point.X * StructMap.BlockSize + 1, field.ships[i].palub[j].point.Y * StructMap.BlockSize + 1, StructMap.BlockSize - 1, StructMap.BlockSize - 1); } else if (field.ships[i].palub[j].type == DeckType.Dead) { g.FillRectangle(Brushes.Black, field.ships[i].palub[j].point.X * StructMap.BlockSize + 1, field.ships[i].palub[j].point.Y * StructMap.BlockSize + 1, StructMap.BlockSize - 1, StructMap.BlockSize - 1); } } } } Graphics tmp = isYours ? Graphics.FromImage(MainBitmapYours) : Graphics.FromImage(MainBitmapEnemy); using (tmp) { tmp.Clear(Color.White); tmp.DrawImage(newBitmap, 0, 0); } } }
private CellType[,] BuildCellMatrix(int xsize, int ysize = -1) { if (ysize == -1) { ysize = xsize; } CellType[,] CellMatrix; CellMatrix = new CellType[xsize, ysize]; for (int i = 0; i < CellMatrix.GetLength(0); i++) { for (int j = 0; j < CellMatrix.GetLength(1); j++) { CellMatrix[i, j] = CellType.None; } } return(CellMatrix); }
public CellType[,] GetMazeWithWall(int[,] maze) { var result = new CellType[maze.GetLength(0) * 2 + 1, maze.GetLength(1) * 2 + 1]; for (var i = 0; i < maze.GetLength(0); i++) { for (var j = 0; j < maze.GetLength(1); j++) { if (maze[i, j] == 1) { result[i * 2, j * 2] = CellType.WALL; result[i * 2 + 1, j * 2] = CellType.WALL; result[i * 2, j * 2 + 1] = CellType.WALL; result[i * 2 + 1, j * 2 + 1] = CellType.ROAD; } else { result[i * 2, j * 2] = CellType.NONE; result[i * 2 + 1, j * 2] = CellType.NONE; result[i * 2, j * 2 + 1] = CellType.NONE; result[i * 2 + 1, j * 2 + 1] = CellType.NONE; } } } for (var i = 0; i < result.GetLength(0); i++) { for (var j = 0; j < result.GetLength(1); j++) { if (result[i, j] == CellType.ROAD) { for (var k = 0; k < Offsets.Count; k++) { if (result[i + (int)Offsets[k].x, j + (int)Offsets[k].y] != CellType.WALL) { result[i + (int)Offsets[k].x, j + (int)Offsets[k].y] = CellType.WALL; } } } } } return(result); }
public static Picross ConvertToPicross(this TextAsset levelFile) { //split file by row string[] rows = levelFile.text.Split('\n'); CellType[,] cells = new CellType[rows.Length, rows[0].Split(' ').Length]; for (int i = 0; i < cells.GetLength(0); i++) { //split line by space string[] cols = rows[i].Split(' '); //add each char as an int into respective row for (int j = 0; j < cells.GetLength(0); j++) { cells[cells.GetLength(0) - 1 - i, cells.GetLength(0) - 1 - j] = (CellType)int.Parse(cols[j]); } } //get level name string fileName = levelFile.name; string levelName = fileName.Substring(fileName.IndexOf(']') + 2); return(new Picross(levelName, cells)); }
public void Init(CellType[,] cells) { _undoStack.Clear(); NotifyPropertyChanged("Moves"); _width = cells == null ? 0 : cells.GetLength(0); NotifyPropertyChanged("Width"); _height = cells == null ? 0 : cells.GetLength(1); NotifyPropertyChanged("Height"); if (cells == null) { _cells = null; } else { _cells = new ObservableCollection<CellType>(); for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { _cells.Add(cells[x, y]); } } } NotifyPropertyChanged("Cells"); }
private void BuildMapByFerr2D(CellType[,] cells) { var mx = new ProdToFerra2D.CellType[cells.GetLength(0), cells.GetLength(1)]; for (int i = 0; i < mx.GetLength(0); i++) for (int j = 0; j < mx.GetLength(1); j++) mx[i, j] = Interpret(cells[i, j]); CMap map = new CMap(mx); map.RunAnalyze(); FerrTerrainBuilder builder = new FerrTerrainBuilder(map.FinalPolygons.ConvertAll((p) => new Polygon2D(p.mainPoints, p.lines)), ferraPrototype.GetComponent<Ferr2D_Path>(), GameConst.UNITS_PER_CELL, GameConst.UNITS_PER_CELL); builder.Build(); }
private void SetCells(IntVector2 origin, CellType[,] cells) { for (int x = 0; x < cells.GetLength(0); x++) { for (int z = 0; z < cells.GetLength(1); z++) { var spacePosition = new IntVector2(origin.x + x, origin.z + z); if (spacePosition.x >= 0 && spacePosition.x < AreaSize && spacePosition.z >= 0 && spacePosition.z < AreaSize) { this.cells[spacePosition.x, spacePosition.z] = cells[x, z]; } } } }