// If a tile's isEnvironment property is set to false, it can not // collide with the player (active block) and will not be considered // when checking for full rows. Additionally setting its color to // the background color effectively deletes the tile/block. public static void DeleteRow(Tile[,] tiles, int row, Color backColor) { for (int i = row; i > 0; i--) { for (int j = 0; j <= tiles.GetUpperBound(1); j++) { tiles[i, j].isEnvironment = tiles[i - 1, j].isEnvironment; tiles[i, j].label.BackColor = tiles[i - 1, j].label.BackColor; } } for (int j = 0; j <= tiles.GetUpperBound(1); j++) { tiles[0, j].isEnvironment = false; tiles[0, j].label.BackColor = backColor; } }
// The World constructor receives a reference to the Controls object so // it can add window elements (labels in this case) to the main screen public World(Control.ControlCollection controls, Color backColor, int rows, int columns, int colWidth, int rowHeight) { this.rows = rows; this.columns = columns; this.backColor = backColor; tiles = new Tile[rows, columns]; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { tiles[row, col].label = new Label(); tiles[row, col].label.AutoSize = false; tiles[row, col].label.BorderStyle = BorderStyle.FixedSingle; tiles[row, col].label.Location = new Point(col * colWidth, row * rowHeight); tiles[row, col].label.Size = new Size(colWidth, rowHeight); controls.Add(tiles[row, col].label); } } }
private bool TileIsAbleToSet(Tile tile) { return (Field[tile.X[0], tile.Y[0]] == tile.Sort || Field[tile.X[0], tile.Y[0]] == 0) && (Field[tile.X[1], tile.Y[1]] == tile.Sort || Field[tile.X[1], tile.Y[1]] == 0) && (Field[tile.X[2], tile.Y[2]] == tile.Sort || Field[tile.X[2], tile.Y[2]] == 0) && (Field[tile.X[3], tile.Y[3]] == tile.Sort || Field[tile.X[3], tile.Y[3]] == 0); }
private bool TileIsAbleToRotate(Tile tile) { Tile copy = CopyTile(tile); copy.Rotate(); return TileIsAbleToSet(copy); }
private bool TileIsAbleToMove(Tile tile, int x, int y) { Tile copy = CopyTile(tile); copy.Move(x, y); return TileIsAbleToSet(copy); }
private void SetTilePermanently(Tile tile) { DeleteTile(tile); tile.Sort += 8; SetTile(tile); }
private void SetTile(Tile tile) { for(int i = 0; i < 4; i++) { Field[tile.X[i], tile.Y[i]] = tile.Sort; } }
private void RotateTile(Tile tile) { if (TileIsAbleToRotate(tile)) { DeleteTile(tile); tile.Rotate(); SetTile(tile); } }
private void MoveTile(Tile tile, int x, int y) { if (TileIsAbleToMove(tile, x, y)) { DeleteTile(tile); tile.Move(x, y); SetTile(tile); } else if (y > 0) //Means tile tried to move down but couldn't { SetTilePermanently(tile); if (OnCurrentTileReachedBottom != null) { OnCurrentTileReachedBottom(this, new EventArgs()); } } }
private void DeleteTile(Tile tile) { for (int i = 0; i < 4; i++) { Field[tile.X[i], tile.Y[i]] = 0; } }
private Tile CopyTile(Tile tile) { Tile copy = new Tile(0); Array.Copy(tile.X, copy.X, 4); //Needed because arrays are reference types Array.Copy(tile.Y, copy.Y, 4); copy.Sort = tile.Sort; copy.Status = tile.Status; return copy; }
public void SetNewTile() { CurrentTile = WaitingLine.First(); WaitingLine.Remove(CurrentTile); WaitingLine.Add(new Tile(new Random().Next(1, 8))); if (TileIsAbleToSet(CurrentTile)) { SetTile(CurrentTile); } else { if (OnGameEnds != null) { OnGameEnds(this, new EventArgs()); } } }