Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateu Batle <mateu.batle@collabora.co.uk>2010-10-27 20:24:39 (GMT)
committer Mateu Batle <mateu.batle@collabora.co.uk>2010-10-27 20:24:39 (GMT)
commit37614fd603304b179c53823cc33166e7e487d35c (patch)
treef3435e57a5c2d30f6a483803dd0155ea3a767c7f
parente23bd788ccd54a7a9e758a5a2c7268ec6e832694 (diff)
Added message (not visible yet ?)
added proper termination of game
-rwxr-xr-xgame2/game2.py32
-rwxr-xr-xmathquwy.py4
2 files changed, 15 insertions, 21 deletions
diff --git a/game2/game2.py b/game2/game2.py
index 7297a1c..152bcf3 100755
--- a/game2/game2.py
+++ b/game2/game2.py
@@ -141,9 +141,10 @@ class Game2(usmpgames.ApplicationState):
GAMEMODE = self.game_mode
def exiting_state(self, fromStack):
+ global score
self.next_state().clear_all()
self.next_state().add_htmltext(
- _(""" <b>Felicidades</b>\n\nHas conseguido %d puntos""") % self.player.score,
+ _(""" <b>Felicidades</b>\n\nHas conseguido %d puntos""") % score,
color = (0, 255, 0, 0),
pos = (660, 260),
rectsize = (380, 390),
@@ -161,7 +162,7 @@ class Game2(usmpgames.ApplicationState):
mainClock = pygame.time.Clock()
a= round(time.time(),0)
#print ('loopTime: '+str(a))
- compareTime(a)
+ compareTime(a, self)
self.screen().blit(background, (0,0) )
surface = self.screen()
@@ -236,7 +237,7 @@ class Game2(usmpgames.ApplicationState):
for event in pygame.event.get():
if event.type == QUIT:
- closeGame()
+ self.set_running( False )
# KEYDOWN EVENTS
if event.type == KEYDOWN:
if event.key == ord('z'):
@@ -272,7 +273,7 @@ class Game2(usmpgames.ApplicationState):
carrotsQuick = False
score= 0
if event.key == K_ESCAPE:
- closeGame()
+ self.set_running( False )
if event.key == K_LEFT or event.key == ord('a') or event.key == K_KP4 or event.key== K_KP7:
moveLeft = False
@@ -423,7 +424,7 @@ class Game2(usmpgames.ApplicationState):
pygame.mixer.music.stop()
pygame.display.update()
- waitPlayerPressKey()
+ waitPlayerPressKey(self)
#correctAnswerSound.stop()
gameOverSound.stop()
@@ -436,18 +437,13 @@ TIMESTART= round(time.time(),0)
TIMELIMIT=240.0
#print ('time: '+str(TIMESTART))
-def compareTime(playTime):
+def compareTime(playTime, gamestate):
global TIMELIMIT, TIMESTART
c=playTime-TIMESTART
#print('c time: '+str(c))
if(c>TIMELIMIT):
#print ('Time Limit!')
- closeGame()
-
-#Closing Game Method
-def closeGame():
- #pygame.quit()
- sys.exit()
+ gamestate.set_running( False )
#Loading Image Method
def load_image(fileName):
@@ -459,32 +455,32 @@ def load_image(fileName):
#Wait Player to Press Key Method
-def waitPlayerPressKey():
+def waitPlayerPressKey(gamestate):
while True:
for event in pygame.event.get():
pygame.time.wait(300)
pygame.event.clear()
if event.type == QUIT:
- closeGame()
+ gamestate.set_running( False )
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
# Close game if user press scape key
- closeGame()
+ gamestate.set_running( False )
return
if event.type == MOUSEBUTTONDOWN:
return
if event.type == JOYBUTTONDOWN:
return
-def waitPlayerPressKeyNoWait():
+def waitPlayerPressKeyNoWait(gamestate):
while True:
for event in pygame.event.get():
if event.type == QUIT:
- closeGame()
+ self.set_running( False )
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
# Close game if user press scape key
- closeGame()
+ gamestate.set_running( False )
return
if event.type == MOUSEBUTTONDOWN:
return
diff --git a/mathquwy.py b/mathquwy.py
index 30acefe..0b867c2 100755
--- a/mathquwy.py
+++ b/mathquwy.py
@@ -47,15 +47,13 @@ class MathQuwy(usmpgames.Application):
rectsize = (380, 390),
fontsize = 22,
font = "droidsans");
-
-
+
# add game
add_game = game2.Game2( 1, congrats )
substract_game = game2.Game2( 2, congrats )
multiply_game = game2.Game2( 3, congrats )
count_game = game2.Game2( 4, congrats )
-
# add numbers game state (tutorial)
add_tutorial = usmpgames.InfoState( add_game, background_tutorial )
add_tutorial.add_htmltext(