private static void Pulse() { if (Console.KeyAvailable) { key = Console.ReadKey(); keyPulse = true; } else { keyPulse = false; } if (Program.key.Key == ConsoleKey.LeftArrow & !tetrimino.IsSomethLeft() & keyPulse) { for (int i = 0; i < 4; i++) { tetrimino.position[i][1] -= 1; } Update(); } else if (Program.key.Key == ConsoleKey.RightArrow & !tetrimino.IsSomethRight() & keyPulse) { for (int i = 0; i < 4; i++) { tetrimino.position[i][1] += 1; } Update(); } if (Program.key.Key == ConsoleKey.DownArrow & keyPulse) { tetrimino.Solve(); } if (Program.key.Key == ConsoleKey.DownArrow & keyPulse) { for (; tetrimino.IsSomthBelow() != true;) { tetrimino.Solve(); } } if (Program.key.Key == ConsoleKey.UpArrow & keyPulse) { tetrimino.Rotate(); tetrimino.Update(); } }
public void Update(GameControl gameControl, GameTime gameTime, KeyboardState keyState, KeyboardState prevKeyState) { tetrimino.Update(slots, stats, gameTime, keyState, prevKeyState); if (!tetrimino.Falling) { //Game over if (tetrimino.Position.Y < 0) { gameControl.GameOver(); } //Detach blocks foreach (Block block in tetrimino.Blocks) { if (block != null) { block.Falling = false; } } //Clear any complete lines int completeLines = 0; for (int i = 0; i < HEIGHT; i++) { bool completeLine = true; for (int j = 0; j < WIDTH; j++) { if (slots[j, i].Block == null) { completeLine = false; break; } } if (completeLine) { for (int j = 0; j < WIDTH; j++) { slots[j, i].Block = null; } for (int k = 0; k < WIDTH; k++) { for (int l = i - 1; l >= 0; l--) { if (slots[k, l].Block != null) { if (!slots[k, l].Block.Falling) { slots[k, l + 1].Block = slots[k, l].Block; slots[k, l].Block = null; } } } } stats.Goal--; completeLines++; } } switch (completeLines) { case 1: { stats.Score += 100; soundControl.PlayClear1(); break; } case 2: { stats.Score += 300; soundControl.PlayClear2(); break; } case 3: { stats.Score += 500; soundControl.PlayClear3(); break; } case 4: { stats.Score += 800; soundControl.PlayClear4(); break; } } //New tetrimino tetrimino = new Tetrimino(next, content, soundControl); PrepareNextTetrimino(); canHold = true; } //Hold if (keyState.IsKeyDown(Keys.LeftShift) && prevKeyState.IsKeyUp(Keys.LeftShift)) { int currentType = tetrimino.Type; if (canHold) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if ((int)tetrimino.Position.Y + j >= 0 && (int)tetrimino.Position.X + i >= 0 && (int)tetrimino.Position.X + i < WIDTH && (int)tetrimino.Position.Y + j < HEIGHT) { if (tetrimino.Blocks[i, j] != null) { slots[(int)tetrimino.Position.X + i, (int)tetrimino.Position.Y + j].Block = null; } } } } if (hold == null) { tetrimino = new Tetrimino(next, content, soundControl); PrepareNextTetrimino(); } else { tetrimino = new Tetrimino((int)hold, content, soundControl); } hold = currentType; stats.Hold.Set((int)hold); canHold = false; soundControl.PlayDropSoft(); } } }