public static Pos MoveObject(this GridStruct grid, int x, int y, Move direction) { Pos newPos = GetNewLocation(x, y, direction); grid.GetTile(newPos.x, newPos.y).gameObject = grid.GetTile(x, y).gameObject; grid.GetTile(x, y).gameObject = BaseObjectFacotry.Create(Blocks.EMPTY); return(newPos); }
private void UpdateGridTiles() { game.Children.Clear(); spRows.Orientation = Orientation.Horizontal; for (int x = 0; x < grid.width; x++) { StackPanel spCols = new StackPanel(); spCols.Orientation = Orientation.Vertical; for (int y = 0; y < grid.height; y++) { Label btnTile = new Label(); TileStruct tile = grid.GetTile(x, y); btnTile.Style = Application.Current.FindResource("Tile") as Style; btnTile.DataContext = tile; spCols.Children.Add(btnTile); } spRows.Children.Add(spCols); StackPanel spCols1 = (StackPanel)spRows.Children[0]; } game.Children.Add(spRows); }
public static PlayerEntity FindPlayer(this GridStruct grid) { for (int x = 0; x < grid.grid.GetLength(0); x++) { for (int y = 0; y < grid.grid.GetLength(1); y++) { if (Entitys.PLAYER.Equals(grid.GetTile(x, y).gameObject.GetType())) { PlayerEntity player = (PlayerEntity)grid.GetTile(x, y).gameObject; player.x = x; player.y = y; return(player); } } } return(null); }
public static bool CanMove(this GridStruct grid, Pos pos) { if (pos.IsInGrid(grid) && grid.GetTile(pos.x, pos.y).gameObject.GetType() == Blocks.EMPTY) { return(true); } return(false); }
public static bool CanMove(this GridStruct grid, int x, int y, Move direction) { Pos newPos = GetNewLocation(x, y, direction); if (newPos.IsInGrid(grid) && grid.GetTile(newPos.x, newPos.y).gameObject.GetType() == Blocks.EMPTY) { return(true); } return(false); }
public static GridStruct Copy(this GridStruct grid) { GridStruct newGrid = new GridStruct(grid.width, grid.height); for (int x = 0; x < grid.width; x++) { for (int y = 0; y < grid.height; y++) { TileStruct tile = grid.GetTile(x, y); newGrid.SetTile(x, y, tile.floor.GetType(), tile.environmentObject.GetType(), tile.gameObject.GetType()); } } return(newGrid); }
public static Pos FindTilePosition(this GridStruct grid, TileStruct tile) { for (int x = 0; x < grid.grid.GetLength(0); x++) { for (int y = 0; y < grid.grid.GetLength(1); y++) { if (grid.GetTile(x, y).Equals(tile)) { Pos pos = new Pos(x, y); return(pos); } } } return(null); }