コード例 #1
0
ファイル: Game.cs プロジェクト: Hoodekly/Tetris
    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);
        }
    }
コード例 #2
0
 public void RotateTetramino()
 {
     lock (moveMutex)
     {
         actualTetramino.Rotate(true);
         CheckRotation();
     }
 }