public void CurTetraminoMovDown() { Point Position = curTetramino.GetPosition; Point[] Shape = curTetramino.GetShape; bool move = true; CurTetraminoErase(); foreach (Point S in Shape) { if (((int)(S.Y + Position.Y) + 1 + 1) >= rows) { move = false; } else if (BlockControls[((int)(S.X + Position.X) + ((cols / 2) - 1)), (int)(S.Y + Position.Y) + 1 + 1].BackgroundImage != NoImage) { move = false; } } if (move) { curTetramino.MoveDown(); CurTetraminoDraw(); } else { CurTetraminoDraw(); CheckRows(); if ((int)Position.Y <= 1) { gameOver = true; } else { curNumber = nextNumber; nextNumber = tetraminoRandom.Next(0, 7); curTetramino = new Tetramino(curNumber); NextTetraminoErase(); nextTetramino = new Tetramino(nextNumber); NextTetraminoDraw(); } } }
private void GameUpdate() { Action moveLeft = delegate() { tetramino.MoveLeft(); }; Action moveRight = delegate() { tetramino.MoveRight(); }; Action rotate90 = delegate() { tetramino.Rotate(); }; Action rotate270 = delegate() { tetramino.Rotate(); tetramino.Rotate(); tetramino.Rotate(); }; const int ACTIONS_COUNT = 3; Action[] actions = { moveLeft, moveRight, rotate90 }; Action[] backActions = { moveRight, moveLeft, rotate270 }; KeyCode[] keyCodes = { KeyCode.A, KeyCode.D, KeyCode.W }; tetramino.SetActive(field, false); for (int i = 0; i < ACTIONS_COUNT; i++) { if (Input.GetKeyDown(keyCodes[i])) { actions[i](); if (!tetramino.Check(field)) { backActions[i](); } } } if ((Input.GetKey(KeyCode.S) ? INCREASED_FALL_TIME : FALL_TIME) < Time.time - previousDownTime) { tetramino.MoveDown(); if (!tetramino.Check(field)) { tetramino.MoveUp(); tetramino.SetActive(field, true); CheckLineToDelete(); NewTetramino(); if (!tetramino.Check(field)) { GameOver(); return; } } previousDownTime = Time.time; } tetramino.SetActive(field, true); if (Input.GetKeyDown(KeyCode.Escape)) { gameMode = GameMode.Pause; pauseScreen.SetActive(true); } }