From 5444a985719826bf6c516819f7ea5e41b1740798 Mon Sep 17 00:00:00 2001 From: Matt Parlette Date: Fri, 21 Mar 2014 22:59:55 -0400 Subject: [PATCH 1/2] Added a star explosion before showing the congratulations text. This was copied from http://codegolf.stackexchange.com/a/24463. I tried to mess around with adding some text in the center, but that didn't work out, so that should be revisited. Closes #91 --- game.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/game.py b/game.py index d3b8cca..4182754 100644 --- a/game.py +++ b/game.py @@ -21,6 +21,7 @@ from player import Player, Health, Knowledge, Happiness, Money from map import Map import os +import sys, math, time, random class Game: def __init__(self, map = None, debug = False): @@ -106,8 +107,9 @@ def run(self): quit_to_main_menu = False while not quit_to_main_menu: for player in self.players: - if self._finished_game(player): - print "Congratulations %s, you won the game!" % player + #if self._finished_game(player): + if True: + self._player_won(player) quit_to_main_menu = True else: turn_done = False @@ -344,3 +346,46 @@ def _finished_game(self,player): #If we got here, then everything is satisfied for the end game return True + + def _player_won(self,player): + """Show the victory screen for the player who won.""" + + def distance(x, y): + # ((y - y_center) * 2) -> correct ratio for a true circle + return math.ceil(math.sqrt(((x - 40) ** 2) + (((y - 12) * 2) ** 2))) + + def star(radiuses,center_text="winner"): + for r in radiuses: + + # width + for y in range(24): + # height + for x in range(80): + d = distance(x, y) + + #~ border + if (d == r): + sys.stdout.write('*') + #~ inside the star + elif (d < r): + if (r > 35): + sys.stdout.write(' ') + elif (r > 25) and ((d % 2) != 0): + if y == 12: + if x == (40 - len(center_text) / 2): + sys.stdout.write('winner') + else: + sys.stdout.write('-') + elif (r > 15) and ((d % 2) == 0): + sys.stdout.write(' ') + else : + sys.stdout.write(random.choice('****#@')) + #~ space outside the star + else: + sys.stdout.write(' ') + print + time.sleep(0.1) + print "Congratulations, %s won the game!" % player.name + raw_input("Press enter to return to the main menu") + + star(range(0, 12, +3) + range(10, 0, -3) + range(0, 50, 3)) \ No newline at end of file From 5933f978f38489aacd2ecd96c6fd36295c1ac4ba Mon Sep 17 00:00:00 2001 From: Matt Parlette Date: Fri, 28 Mar 2014 09:01:55 -0400 Subject: [PATCH 2/2] Fixes game end screen showing up when you start the game. The fun things that come from midnight commits. --- game.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/game.py b/game.py index 4182754..cae0a97 100644 --- a/game.py +++ b/game.py @@ -107,8 +107,7 @@ def run(self): quit_to_main_menu = False while not quit_to_main_menu: for player in self.players: - #if self._finished_game(player): - if True: + if self._finished_game(player): self._player_won(player) quit_to_main_menu = True else: