César Bustíos avatar César Bustíos committed aabc49a Merge

Merge default

Comments (0)

Files changed (1)

 # Game and board settings
 WINDOW_WIDTH = 640
 WINDOW_HEIGHT = 480
-HALF_WIDTH = WINDOW_WIDTH / 2
-HALF_HEIGHT = WINDOW_HEIGHT / 2
-FPS = 15
 BOX_SIZE = 40
 BOX_GAP = 10
 BOARD_COLS = 9
     pygame.display.set_caption('Geezle - Memory Puzzle')
 
     board = generate_board(False)
-    new_game = True
+    new_game = False
+    running = True
     box_img = BOX_IMG
 
     # Number of moves
     # First selected logo [row, col]
     first_choice = None
 
-    while True:
+    # Block mouse motion events
+    pygame.event.set_blocked(pygame.MOUSEMOTION)
+
+    while running:
+        # New board?
+        if new_game:
+            board = generate_board(False)
+            new_game = False
+
         # Background image
         SCREEN.blit(BACKGROUND_IMG, (0, 0))
         draw_table(WHITE, BLACK)
 
         draw_board(board, box_img)
-        clicked = False
-
-        # Events handling
-        for event in pygame.event.get():
-            if event.type == QUIT:
-                pygame.quit()
-                sys.exit()
-            elif event.type == MOUSEMOTION:
-                x, y = event.pos
-            elif event.type == MOUSEBUTTONUP:
-                if event.button == 1:
-                    x, y = event.pos
-                    clicked = True
 
         # Display options: New game, Quit, Sound, etc.
         options = display_game_options_and_score(str(score))
 
-        if clicked and new_game is not True:
+        clicked = False
+        pygame.display.update()
+
+        # Events handling
+        event = pygame.event.wait()
+        if event.type == QUIT:
+            running = False
+        elif event.type == MOUSEBUTTONUP:
+            if event.button == 1:
+                x, y = event.pos
+                clicked = True
+
+        if clicked:
             # New game?
             if options['new_game'].collidepoint(x, y):
                 new_game = True
         # Get box at pixel (x,y)
         row, col = get_box(board, x, y)
 
-        if row != None and col != None and new_game is not True:
-            # Mouse is over a box
-            if not board['revealed'][row][col]:
-                highlight_box(board, row, col)
-
+        if row != None and col != None:
             # Box is clicked
             if not board['revealed'][row][col] and clicked:
                 reveal_box(board, row, col, box_img)
             #~ new_game = False
 
         pygame.display.update()
-        CLOCK.tick(FPS)
+
+    pygame.quit()
 
 
 def animate_unrevealed(rect, box_img):
     win_rect = win_surface.get_rect()
 
     # Position
-    win_rect.center = (HALF_WIDTH, HALF_HEIGHT)
+    left = (BOARD_WIDTH / 2) + X_MARGIN
+    top = (BOARD_HEIGHT / 2) + Y_MARGIN
+    win_rect.center = (left, top)
 
     SCREEN.blit(win_surface, win_rect)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.