1. César Bustíos
  2. Memoreek

Commits

César Bustíos  committed 3beacb6

Cleaning up a little bit and GPL

  • Participants
  • Parent commits 0a2f30c
  • Branches default

Comments (0)

Files changed (1)

File geezle.py

View file
  • Ignore whitespace
 #-*- coding: utf-8 -*-
 
-########################################################################
-# Geezle - Memory Puzzle
-# (Based on Al Sweigart's game from the book "Making Games with Python
-# and Pygame")
+##############################################################################
 #
-# Author: Cesar Bustios <cesarbustios@gmail.com>
+# This file is part of Geezle
 #
+# Copyright (C) 2012  César Bustíos Benites
+#
+# Geezle is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Geezle is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+#
+# Author: César Bustíos Benites <cesarbustios@gmail.com>
+# Email: cesarbustios@gmail.com
 # Google+: https://plus.google.com/u/0/103603507868093099204
+# License: GPL v3
 #
-# Released under a "Simplified BSD" license
-########################################################################
+# Geezle was based on Al Sweigart's game from the book "Making Games with
+# Python and Pygame"
+#
+##############################################################################
 
 import sys
 import os
 
 
 # Paths
-PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
-IMAGES_DIR = os.path.join(PROJECT_DIR, 'data/images')
-FONTS_DIR = os.path.join(PROJECT_DIR, 'data/fonts')
-SOUNDS_PATH = os.path.join(PROJECT_DIR, 'data/sounds')
-LOGOS_DIR = os.path.join(IMAGES_DIR, 'logos')
-UNREVEALED_BOX_IMG_PATH = os.path.join(IMAGES_DIR, 'unrevealed_logo1.png')
-BACKGROUND_IMG_PATH = os.path.join(IMAGES_DIR, 'memory_background.jpg')
+PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
+IMAGES_PATH = os.path.join(PROJECT_PATH, 'data/images')
+FONTS_PATH = os.path.join(PROJECT_PATH, 'data/fonts')
+SOUNDS_PATH = os.path.join(PROJECT_PATH, 'data/sounds')
+UNREVEALED_BOX_IMG_PATH = os.path.join(IMAGES_PATH, 'unrevealed_logo1.png')
+BACKGROUND_IMG_PATH = os.path.join(IMAGES_PATH, 'memory_background.jpg')
 BACKGROUND_MUSIC_PATH = os.path.join(SOUNDS_PATH, 'memory_music.mp3')
 
 # Main screen resolution
 HIGHLIGHT_WIDTH = 3
 X_MARGIN = ((WINDOW_WIDTH - BOARD_WIDTH) / 3)
 Y_MARGIN = ((WINDOW_HEIGHT - BOARD_HEIGHT) / 3)
-OPTION_X_MARGIN = 75
-OPTION_Y_MARGIN = 30
 
 # Colors
 WHITE = (255, 255, 255)
 BACKGROUND_IMG = pygame.image.load(BACKGROUND_IMG_PATH)
 
 pygame.init()
-MAIN_SURFACE = pygame.display.set_mode(SCREEN_RESOLUTION)
+SCREEN = pygame.display.set_mode(SCREEN_RESOLUTION)
 CLOCK = pygame.time.Clock()
 
 # Loading and playing background music:
             new_game = False
 
         # Background image
-        MAIN_SURFACE.blit(BACKGROUND_IMG, (0, 0))
+        SCREEN.blit(BACKGROUND_IMG, (0, 0))
         draw_table(WHITE, BLACK)
 
         draw_board(board)
         # Temporary surface for replacing previous unrevealed box image
         tmp = pygame.surface.Surface((BOX_SIZE, BOX_SIZE))
         tmp.fill(WHITE)
-        MAIN_SURFACE.blit(tmp, (rect.x, rect.y))
+        SCREEN.blit(tmp, (rect.x, rect.y))
 
         # Scale and blit the image
         img = pygame.transform.scale(img, (width, height))
-        MAIN_SURFACE.blit(img, (x, y))
+        SCREEN.blit(img, (x, y))
         pygame.time.delay(25)
         pygame.display.update()
         height -= 5
     """
     rect = board['rects'][row][col]
     r = pygame.rect.Rect(rect.left-5, rect.top-5, BOX_SIZE+10, BOX_SIZE+10)
-    pygame.draw.rect(MAIN_SURFACE, HIGHLIGHT_COLOR, r, HIGHLIGHT_WIDTH)
+    pygame.draw.rect(SCREEN, HIGHLIGHT_COLOR, r, HIGHLIGHT_WIDTH)
 
 
 def get_box(board, x, y):
     Message for logo masters.
     """
     # Font
-    win_font = pygame.font.Font(os.path.join(FONTS_DIR, win_style), 96)
+    win_font = pygame.font.Font(os.path.join(FONTS_PATH, win_style), 96)
 
     # Surface
     win_surface = win_font.render('You win!', True, GOLD)
     # Position
     win_rect.center = (HALF_WIDTH, HALF_HEIGHT)
 
-    MAIN_SURFACE.blit(win_surface, win_rect)
+    SCREEN.blit(win_surface, win_rect)
 
 
 def display_ingame_options(font_style):
     """
     Returns options rects for colliding process
     """
+    x_margin = 75
+    y_margin = 30
+
     # Font
-    option_font = pygame.font.Font(os.path.join(FONTS_DIR, font_style), 20)
+    option_font = pygame.font.Font(os.path.join(FONTS_PATH, font_style), 20)
 
     # Surfaces
     option1_surface = option_font.render('New Game', True, GOLD)
     option2_rect = option2_surface.get_rect()
 
     # Positions
-    option1_rect.center = (HALF_WIDTH - OPTION_X_MARGIN, WINDOW_HEIGHT - OPTION_Y_MARGIN)
-    option2_rect.center = (HALF_WIDTH + OPTION_X_MARGIN, WINDOW_HEIGHT - OPTION_Y_MARGIN)
+    option1_rect.center = (HALF_WIDTH - x_margin, WINDOW_HEIGHT - y_margin)
+    option2_rect.center = (HALF_WIDTH + x_margin, WINDOW_HEIGHT - y_margin)
 
     # Show the options
-    MAIN_SURFACE.blit(option1_surface, option1_rect)
-    MAIN_SURFACE.blit(option2_surface, option2_rect)
+    SCREEN.blit(option1_surface, option1_rect)
+    SCREEN.blit(option2_surface, option2_rect)
 
     return option1_rect, option2_rect
 
         return
 
     # Play awesome sound
-    sound_path = os.path.join(SOUNDS_PATH, 'reveal_box.wav')
-    sound = pygame.mixer.Sound(sound_path)
+    sound_file = os.path.join(SOUNDS_PATH, 'reveal_box.wav')
+    sound = pygame.mixer.Sound(sound_file)
     sound.play()
 
     animate_unrevealed(rect)
 
     # Mark box as revealed
     board['revealed'][row][col] = True
-    MAIN_SURFACE.blit(board['logos'][row][col], (rect.x, rect.y))
+    SCREEN.blit(board['logos'][row][col], (rect.x, rect.y))
     pygame.display.update()
 
 
     Returns a shuffled list of logos images
     """
     logos = []
-    for img in os.listdir(LOGOS_DIR):
+    logos_path = os.path.join(IMAGES_PATH, 'logos')
+
+    for img in os.listdir(logos_path):
         try:
             # Go Archie!
-            logos.append(pygame.image.load(os.path.join(LOGOS_DIR, img)).convert_alpha())
+            logos.append(pygame.image.load(os.path.join(logos_path, img)).convert_alpha())
         except pygame.error, e:
             continue
     random.shuffle(logos)
+
     return logos
 
 
             x = rect.x
             y = rect.y
             if not board['revealed'][row][col]:
-                MAIN_SURFACE.blit(UNREVEALED_BOX_IMG, (x, y))
+                SCREEN.blit(UNREVEALED_BOX_IMG, (x, y))
             else:
-                MAIN_SURFACE.blit(board['logos'][row][col], (x, y))
+                SCREEN.blit(board['logos'][row][col], (x, y))
 
 
 def draw_table(bg_color, border_color):
     y = Y_MARGIN - margin
     width = BOARD_WIDTH + margin * 2
     height = BOARD_HEIGHT + margin * 2
-    pygame.draw.rect(MAIN_SURFACE, bg_color, (x, y, width, height))
+    pygame.draw.rect(SCREEN, bg_color, (x, y, width, height))
 
     # Table border
     width = 5
         (x + BOARD_WIDTH + margin * 2, y + BOARD_HEIGHT + margin * 2),
         (x, y + BOARD_HEIGHT + margin * 2)
     )
-    pygame.draw.polygon(MAIN_SURFACE, BLACK, point_list, width)
-
-
+    pygame.draw.polygon(SCREEN, BLACK, point_list, width)
 
 
 def update_score(score):
-    score_font = pygame.font.Font(os.path.join(FONTS_DIR, 'pixel.ttf'), 25)
+    score_font = pygame.font.Font(os.path.join(FONTS_PATH, 'pixel.ttf'), 25)
     score_text = 'Moves: %s' % str(score.zfill(3))
     score_surface = score_font.render(score_text, True, GOLD)
     score_rect = score_surface.get_rect()
     score_rect.center = (HALF_WIDTH, 25)
-    MAIN_SURFACE.blit(score_surface, score_rect)
+    SCREEN.blit(score_surface, score_rect)
 
 
 if __name__ == '__main__':