Last active
October 24, 2019 12:58
-
-
Save wkta/9903256 to your computer and use it in GitHub Desktop.
#MonthOfCode day 31 - exit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# thema= EXIT, description= a dumb game. How to win this? | |
import random | |
import time | |
import sys | |
COIN_F = (True,False) # coin flipping | |
RUSSIAN_R = (False,False,True,False,False,False) # luck: 1 out of 6 | |
START_MSG = 'A new gladiator enters the arena...' | |
D_QUOTES = ( | |
'Death may have taken you but memories remain', | |
'Rest in peace, brave warrior', | |
'Where the battle rages, there the courage of the warrior is proved', | |
'Having something to struggle for, is a blessing', | |
'Courage is found in unlikely places', | |
'Being brave is allowing the unexpected to happen' | |
) | |
game_over = False | |
t0 = time.time() # init. the game | |
print(START_MSG) | |
while not game_over: | |
if random.choice(COIN_F): | |
time.sleep(0.13) # a quick fight | |
else: | |
time.sleep(0.29) # a long fight | |
if random.choice(RUSSIAN_R): # player dies | |
score_msg = "You lasted: {:2f} sec".format(time.time() - t0) | |
score_msg += " amongst the lions. You can do better, trust me!" | |
print(score_msg) | |
print(' "{}"'.format(random.choice(D_QUOTES))) | |
print() | |
# replay? | |
user_choice = '' | |
while user_choice!='y' and user_choice!='n': | |
user_choice = input('Respawn? y/n> ') | |
if user_choice == 'n': | |
game_over=True | |
else: | |
t0 = time.time() # reset the game | |
print(START_MSG) | |
print('GAME OVER.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment