public Tuple <int, int> canRotate(TetrisGrid grid, bool clockwise) { byte v; bool passing = true; int target; if (clockwise) { target = (Rotation + 1) % 4; } else { if (Rotation - 1 < 0) { target = 3; } else { target = Rotation - 1; } } BlockTester tester = new BlockTester(0, 0, (float)Tetrimino.Size.Width, (float)Tetrimino.Size.Height); foreach (Tuple <int, int> kick in TetriminoKicks[Util.rotation_id(target, clockwise)]) { passing = true; for (int i = 0; i < TetriminoLayout.GetLength(1); i++) { for (int j = 0; j < TetriminoLayout.GetLength(2); j++) { v = TetriminoLayout[target, i, j]; if (v == 0) { continue; } tester.X = i * ((float)Tetrimino.Size.Width) + (kick.Item1 * (float)Tetrimino.Size.Width) + this.x(); tester.Y = j * ((float)Tetrimino.Size.Height) + (kick.Item2 * (float)Tetrimino.Size.Height) + this.y(); if (grid.isCollision(tester)) { passing = false; break; } } if (passing == false) { break; } } if (passing == true) { return(kick); } } return(null); }
async Task CreateObjects(CanvasControl sender) { TetrisGrid grid = new TetrisGrid(200, 100); TetrisBlockHolder holder = new TetrisBlockHolder(-(((float)Tetrimino.Size.Width * 5)), 0, grid); TetrisBag bag = new TetrisBag(new Random(), grid.Width, 0, grid); TetrisScoreKeeper keeper = new TetrisScoreKeeper(0, holder.Height, holder); handler = new TetrisBlockHandler(grid, holder, bag, keeper, handleWin, handleLoss); drawables.Add(handler); handler.start(); }
public TetrisBlockHandler(TetrisGrid grid, TetrisBlockHolder holder, TetrisBag bag, TetrisScoreKeeper keeper, System.Action winCallback, System.Action loseCallback) { this.grid = grid; this.holder = holder; this.bag = bag; this.scoreKeeper = keeper; this.winCallback = winCallback; this.loseCallback = loseCallback; winCallback(); }
public void checkGrid(TetrisGrid grid) { uint lines = 0; bool lineClear; for (int i = grid.Filled.GetLength(1) - 1; i >= 0; i--) { lineClear = true; for (int j = 0; j < grid.Filled.GetLength(0); j++) { if (!grid.Filled[j, i]) { lineClear = false; break; } } if (lineClear) { lines += 1; for (int k = i; k > 0; k--) { for (int l = 0; l < grid.Filled.GetLength(0); l++) { grid.Filled[l, k] = grid.Filled[l, k - 1]; grid.FilledColor[l, k] = grid.FilledColor[l, k - 1]; } } for (int l = 0; l < grid.Filled.GetLength(0); l++) { grid.Filled[l, 0] = false; } i += 1; } } switch (lines) { case 4: if (previousCheckTetris) { increaseScore(Score += 1200 * Level); Combo += 1; previousCheckTetris = true; } else { increaseScore(Score += 800 * Level); Combo += 1; previousCheckTetris = true; } break; case 3: increaseScore(Score += 500 * Level); Combo += 1; break; case 2: increaseScore(300 * Level); Combo += 1; break; case 1: increaseScore(100 * Level); Combo += 1; break; default: Combo = 0; break; } linesCleared += lines; totalLinesCleared += lines; Score += Combo * 50 * Level; tryLevelUp(); }