2048-ml

git clone git://git.codymlewis.com/2048-ml.git
Log | Files | Refs | README | LICENSE

game.py (632B)


      1 #!/usr/bin/env python3
      2 
      3 from getkey import getkey, keys
      4 
      5 import Board
      6 
      7 if __name__ == "__main__":
      8     board = Board.Board(4, 4)
      9     movement = {
     10         keys.UP: board.up,
     11         keys.DOWN: board.down,
     12         keys.LEFT: board.left,
     13         keys.RIGHT: board.right
     14     }
     15     print(board)
     16     while not board.game_over():
     17         print("Your move: ")
     18         key = getkey()
     19         moved = False
     20         if key in movement.keys():
     21             moved = movement[key]()
     22         if moved:
     23             board.spawn_tile()
     24             print()
     25             print(board)
     26     print("Game over!")
     27     print(f"Final score: {board.get_score()}")