Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Memory game to learn pygame features
- import pygame, sys, random
- from pygame.locals import *
- # VARIABLES
- WINDOWwIDTH = 640
- WINDOWHEIGHT = 480
- BOXSIZE = 40
- GAPSIZE = 10
- BOARDWIDTH = 10 # NUMBER OF COLUMNS
- BOARDHEIGHT = 7 # NUMBER OF ROWS
- XMARGIN = int((WINDOWWIDTH - (BOARDWIDTH * (BOXSIZE + GAPSIZE))) / 2)
- YMARGIN = int((WINDOWHEIGHT - (BOARDHEIGHT * (BOXSIZE + GAPSIZE))) / 2)
- # COLORS
- GRAY = (100, 100, 100)
- NAVYBLUE = ( 60, 60, 100)
- WHITE = (255, 255, 255)
- RED = (255, 0, 0)
- GREEN = ( 0, 255, 0)
- BLUE = ( 0, 0, 255)
- YELLOW = (255, 255, 0)
- ORANGE = (255, 128, 0)
- PURPLE = (255, 0, 255)
- CYAN = ( 0, 255, 255)
- BACKGROUND = NAVYBLUE
- BOXCOLOR = WHITE
- HIGHLIGHTCOLOR = BLUE
- #SHAPES
- DONUT = 'donut'
- SQUARE = 'square'
- DIAMOND = 'diamond'
- LINES = 'lines'
- OVAL = 'oval'
- ALLCOLORS = (RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, CYAN)
- ALLSHAPES = (DONUT, SQUARE, DIAMOND, LINES, OVAL)
- # LOCAL FUNCTIONS
- def generateRevealedBoxesData(value):
- # .....
- def getRandomizedBoard():
- # get a list of every possible shape and color combination
- images = []
- for color in ALLCOLORS:
- for shape in ALLSHAPES:
- images.append( (shape, color) )
- random.shuffle(images)
- numImages = int((BOARDWIDTH * BOARDHEIGHT)/2)
- images = images[:numImages] * 2
- random.shuffle(images)
- # create a random board with randomly placed icons
- board = []
- for x in range(BOARDWIDTH): # for every column
- column = []
- for y in range(BOARDHEIGHT): # for every row
- column.append(images[0]) # add image to board
- del images[0] # remove from list
- board.append(column) # add column to list
- return board
- #def splitIntoGroupsOf(groupSize, List):
- def leftTopCoordsOfBox(x, y):
- # turn board coordinates into pixel
- def getBoxAtPixel(x,y):
- # turn pixel coordinates into box
- def drawIcon(shapem color, boxx, boxy):
- #draw the imange under the box coordinates given
- def getShapeAndColor(board, x, y):
- # getting the type of shape and color of shape
- def drawBoxCovers(board,boxes, cover)
- # draws over image to reveal/conceal the image
- def revealBoxesAnimation(board, boxesToReveal):
- # reveal the image
- def coverBoxesAnimation(board, boxestoCover):
- # cover the image
- def drawBoard(board, revealed)
- # draws board with appropriate covered/revealed pieces
- def drawHighlightBox(x,y):
- # draws a simple highlight around box
- def hasWon(revealedBoxes):
- # check if all boxes are revealed
- # MAIN
- def main():
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement