private void lockActive() { isLocking = true; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i + active.X < 22 && j + active.Y < 10 && i + active.X >= 0 && j + active.Y >= 0) { permaBlocked[i + active.X][j + active.Y] |= active.Blocking[i][j]; if (active.Blocking[i][j] && i + active.X >= 2) { permaColors[i + active.X - 2][j + active.Y] = active.Color; } } } } active = next; next = Tetromino.getRandom(); ghost = new Tetromino(active); active.X = 0; active.Y = 3; dueLock = false; isLocking = false; for (int i = 2; i < 22; i++) { if (permaBlocked[i].All(x => x)) { for (int j = i; j > 0; j--) { permaBlocked[j] = permaBlocked[j - 1]; if (j >= 3) { permaColors[j - 2] = permaColors[j - 3]; } } permaBlocked[0] = new bool[10]; permaColors[0] = new ConsoleColor?[10]; } } var args = new TetrominoLockedEventArgs(); args.Next = next; TetrominoLocked(this, args); if (permaBlocked[1].Any(x => x)) { Environment.Exit(0); } }
public void ProcessInput(UserInput input) { switch (input) { case UserInput.Down: if (tryMove(1, 0, active)) { active.X++; } break; case UserInput.Left: if (tryMove(0, -1, active)) { active.Y--; } break; case UserInput.Right: if (tryMove(0, 1, active)) { active.Y++; } break; case UserInput.Lock: while (tryMove(1, 0, active)) { active.X++; } lockActive(); break; case UserInput.RotateClockwise: doRotate(false); break; case UserInput.RotateCClockwise: doRotate(true); break; case UserInput.Hold: if (hold == null) { hold = active; active = next; next = Tetromino.getRandom(); TetrominoLockedEventArgs largs = new TetrominoLockedEventArgs(); largs.Next = next; TetrominoLocked(this, largs); } else { Tetromino temp = hold; hold = active; active = temp; } ghost = new Tetromino(active); active.X = 0; active.Y = 3; TetrominoHeldEventArgs args = new TetrominoHeldEventArgs(); args.Hold = hold; TetrominoHeld(this, args); break; } dueLock = false; evaluateLock(); HasChanged = true; }
private void lockActive() { isLocking = true; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i + active.X < 22 && j + active.Y < 10 && i + active.X >= 0 && j + active.Y >= 0) { permaBlocked[i + active.X][j + active.Y] |= active.Blocking[i][j]; if (active.Blocking[i][j] && i + active.X >= 2) { permaColors[i + active.X - 2][j + active.Y] = active.Color; } } } } active = next; next = Tetromino.getRandom(); ghost = new Tetromino(active); active.X = 0; active.Y = 3; dueLock = false; isLocking = false; for (int i = 2; i < 22; i++) { if (permaBlocked[i].All(x => x)) { for (int j = i; j > 0; j--) { permaBlocked[j] = permaBlocked[j - 1]; if (j >= 3) { permaColors[j - 2] = permaColors[j - 3]; } } permaBlocked[0] = new bool[10]; permaColors[0] = new ConsoleColor?[10]; } } var args = new TetrominoLockedEventArgs(); args.Next = next; TetrominoLocked(this, args); if (permaBlocked[1].Any(x => x)) { Environment.Exit(0); } }
public void ProcessInput(UserInput input) { switch (input) { case UserInput.Down: if (tryMove(1, 0, active)) { active.X++; } break; case UserInput.Left: if (tryMove(0, -1, active)) { active.Y--; } break; case UserInput.Right: if (tryMove(0, 1, active)) { active.Y++; } break; case UserInput.Lock: while (tryMove(1, 0, active)) { active.X++; } lockActive(); break; case UserInput.RotateClockwise: doRotate(false); break; case UserInput.RotateCClockwise: doRotate(true); break; case UserInput.Hold: if (hold == null) { hold = active; active = next; next = Tetromino.getRandom(); TetrominoLockedEventArgs largs = new TetrominoLockedEventArgs(); largs.Next = next; TetrominoLocked(this, largs); } else { Tetromino temp = hold; hold = active; active = temp; } ghost = new Tetromino(active); active.X = 0; active.Y = 3; TetrominoHeldEventArgs args = new TetrominoHeldEventArgs(); args.Hold = hold; TetrominoHeld(this, args); break; } dueLock = false; evaluateLock(); HasChanged = true; }