1 import pygame, sys, sqlite3
2
3 import pyzzle
4 import DB
5 from Slide import Slide
6 from Hotspot import Hotspot
7 from Switch import Switch
8 from Item import Item
9 from Panel import Panel
10 from Text import Text
11 from standard import *
12 import os
13
14 panel=Panel()
15 cursor=pygame.sprite.Sprite()
16 cursor.rect=Rect(0,0,0,0)
17 cursor.image=pygame.Surface((0,0))
18 screen=None
19 framerate=30
20 datafile=None
21 globals=DB.Table('globals', (object,), {})
22 stages=DB.Table('stages', (object,), {})
23 design=False
24 zip=True
25 menu=sys.exit
26 history=[]
27
28 -def init(screensize=(800,600), name='Pyzzle', iconfile=None, fullscreen=False):
29 """Initializes the screen. Must call before anything else.
30 @type screensize: (int,int)
31 @param screensize: Dimensions of the screen.
32 @type name: string
33 @param name: Text to display in the window's title bar
34 @param iconfile: name of the image file to display as the window's icon
35 """
36 pygame.init()
37 pyzzle.screen=pygame.display.set_mode(screensize,
38 pygame.FULLSCREEN if fullscreen else 0)
39 pyzzle.panel.rect=pyzzle.screen.get_rect()
40 if iconfile:
41 icon=pygame.image.load(iconfile).convert_alpha()
42 pygame.display.set_icon(icon)
43 pygame.mouse.set_visible(False)
44 pygame.display.set_caption(name)
45 -def load(datafilename):
57
58 -def save(datafilename=None):
59 """Saves game data to an SQLite database file.
60 @param datafilename: name of the SQLite database file to load,
61 or the currently loaded file, if none specified
62 """
63 if datafilename:
64 pyzzle.datafile=DB.DB(datafilename)
65 datafile.save(Slide)
66 datafile.save(Hotspot)
67
69 """Corrects capitalization of any image files mentioned in
70 the loaded SQLite database file.
71 Useful to prepare for distribution using dynamically downloaded content,
72 but takes a while to run."""
73 for stage in stages:
74 directory=os.path.join('pictures',stage.folder)
75 print directory
76 for file in os.listdir(directory):
77 print file
78 datafile.query('update Slide set image = ? where lower(image)=lower(?)',
79 (file,file))
119