Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bernabé <laurent.bernabe@gmail.com>2013-09-21 20:47:59 (GMT)
committer Laurent Bernabé <laurent.bernabe@gmail.com>2013-09-21 20:47:59 (GMT)
commitab0fae7bb422e7675a68d9fd13d8ab08a47b87b5 (patch)
treebb4ae5b529f92f0e33df295351d5751177b7016b
parent7f54e794a358ac0b5d37c48c0b9da4e41f5d30cd (diff)
Now at the end of the game, balls operations and their results are shown as a list.
-rw-r--r--elements_painter.py27
-rw-r--r--main.py34
2 files changed, 47 insertions, 14 deletions
diff --git a/elements_painter.py b/elements_painter.py
index cbfd2c2..07bc8e5 100644
--- a/elements_painter.py
+++ b/elements_painter.py
@@ -8,6 +8,7 @@ Created on Sun Sep 15 01:28:19 2013
"""
import pygame
+from olpcgames.pangofont import PangoFont
def paint_ball(ball, surface):
@@ -69,3 +70,29 @@ def paint_result_bar(result_bar, surface):
surface.blit(text_surface,
(edge[0] + result_bar.get_insets(),
edge[1] + result_bar.get_insets()))
+
+
+def paint_results(game_area, balls_list, surface):
+ """
+ Draws all results, with their ball color as "header".
+ game_area : area of the balls => tuple of 4 integer
+ balls_list : list of balls => list of Ball
+ surface : the destination surface => PyGame.Surface
+ """
+ font = PangoFont(family='Helvetica', size=16)
+ LINE_HEIGHT = font.size("0123456789")[1]
+ CIRCLES_RADIUS = LINE_HEIGHT / 2
+ ball_index = 0
+ BLACK = (0, 0, 0)
+ for ball in balls_list:
+ pygame.draw.circle(surface, ball.get_bg_color(),
+ (game_area[0] + CIRCLES_RADIUS,
+ game_area[
+ 1] + ball_index * LINE_HEIGHT + CIRCLES_RADIUS),
+ CIRCLES_RADIUS)
+ txt = ball.get_operation().get_text() + " = " + str(ball.get_operation().
+ get_result())
+ txt_surface = font.render(txt, color=BLACK)
+ surface.blit(txt_surface,
+ (game_area[0] + 40, game_area[1] + ball_index * LINE_HEIGHT))
+ ball_index += 1
diff --git a/main.py b/main.py
index 39af2a7..01abcc3 100644
--- a/main.py
+++ b/main.py
@@ -12,7 +12,8 @@ from olpcgames.pangofont import PangoFont
from pygame.locals import QUIT, USEREVENT, MOUSEBUTTONUP
from ball import Ball
from operation import Operation, OPER_ADD, OPER_SUB, OPER_MUL, OPER_DIV
-from elements_painter import paint_ball, paint_time_bar, paint_result_bar
+from elements_painter import paint_ball, paint_time_bar, paint_result_bar,\
+ paint_results
from time_bar import TimeBar
from result_bar import ResultBar
from game_state import GameState
@@ -118,9 +119,9 @@ def main():
screen.fill(BACKGROUND)
paint_result_bar(result_bar, screen)
paint_time_bar(time_bar, screen)
- for ball in the_balls:
- paint_ball(ball, screen)
if game_state == GameState.NORMAL:
+ for ball in the_balls:
+ paint_ball(ball, screen)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
@@ -139,28 +140,33 @@ def main():
if all_target_balls_destroyed(
target_result, the_balls):
game_state = GameState.WON
+ show_status = True
+ pygame.time.set_timer(USEREVENT + 2, 800)
else:
game_state = GameState.LOST
+ show_status = True
+ pygame.time.set_timer(USEREVENT + 2, 800)
clock.tick(FPS)
for ball in the_balls:
ball.move()
balls_collision.manage_colliding_balls(the_balls)
else:
- if game_state == GameState.WON:
- end_txt = "Success !"
- else:
- end_txt = "Failure !"
- end_txt_surface = end_font.render(end_txt,
- color=BLUE, background=RED)
- screen.blit(end_txt_surface, END_TXT_POS)
+ paint_results(balls_area, the_balls, screen)
+ # Blinks the status text.
+ if show_status:
+ if game_state == GameState.WON:
+ end_txt = "Success !"
+ else:
+ end_txt = "Failure !"
+ end_txt_surface = end_font.render(end_txt,
+ color=BLUE, background=RED)
+ screen.blit(end_txt_surface, END_TXT_POS)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
- elif event.type == MOUSEBUTTONUP:
- if event.button == LEFT_BUTTON:
- pygame.quit()
- exit()
+ elif event.type == USEREVENT + 2:
+ show_status = not show_status
if __name__ == "__main__":
main()