Skip to main content
Engineering LibreTexts

8.10: The Start of a New Game

  • Page ID
  • def runGame():
        # setup variables for the start of the game
        board = getBlankBoard()
        lastMoveDownTime = time.time()
        lastMoveSidewaysTime = time.time()
        lastFallTime = time.time()
        movingDown = False # note: there is no movingUp variable
        movingLeft = False
        movingRight = False
        score = 0
        level, fallFreq = calculateLevelAndFallFreq(score)
        fallingPiece = getNewPiece()
        nextPiece = getNewPiece()

    Before the game begins and pieces start falling, we need to initialize some variables to their start- of-game values. On line 13 [191] the fallingPiece variable will be set to the currently falling piece that can be rotated by the player. On line 14 [192] the nextPiece variable will be set to the piece that shows up in the "Next" part of the screen so that player knows what piece is coming up after setting the falling piece.

    • Was this article helpful?