-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·92 lines (80 loc) · 2.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python2
#~main.py~
import actions
import player
from time import sleep
version = 1.2
#enables the debug menu option in the main menu
DEBUG_MODE = "enabled"
#DEBUG_MODE = "disabled"
if DEBUG_MODE == "enabled":
import debug
cache = None #place to remember last function
def menu(Player):
global cache
actions.clearscreen()
startScreen = ("Current Health: %d\n"
"\nWhat would you like to do?\n"
"***************************\n"
"** Enter: Prev Action **\n"
"** R: Roll Dice **\n"
"** V: Visit Shop **\n"
"** L: List Inventory **\n"
"** C: Change Weapon **\n"
"** U: Use Potion **\n"
"** S: Save Game **\n"
"** Q: Quit **\n" %(Player.health))
if DEBUG_MODE == "enabled":
print "%s** D: Debug Menu **" %(startScreen)
print "***************************"
choice = raw_input("\nChoice: ").lower()
#using this method helps clean up all those logic gates
choices = {
'r': actions.roll_dice,
'l': newPlayer.list_inventory,
'c': newPlayer.set_current_weapon,
'v': actions.visit_shop,
'u': newPlayer.use_potion,
's': actions.save_game,
'q': actions.quit_game,
'd': debug.menu,
'': cache, #for convenience
}
if not choice and not cache:
print ("\nThere is no previous action.\n"
"Please choose again.")
sleep(2)
else:
try:
if choices[choice] != cache:
cache = choices[choice]
x = choices[choice]()
if x == 0:
return 0
except TypeError:
if choices[choice] != cache:
cache = choices[choice]
choices[choice](Player)
except KeyError:
print ("\nYou didn't select a valid choice.\n"
"Please choose again.")
sleep(2)
#Starts the game
actions.clearscreen()
print "Dungeon Quest v%.2f" % version
#name = raw_input("\nWho dares to enter the dungeon? ")
name = "Bran"
newPlayer = player.CreatePlayer(name)
while newPlayer.health > 0:
if menu(newPlayer) == 0:
break
if newPlayer.basilisk_attack is True:
print "\nCongratulations! You made it through the dungeon alive!\n"
break
elif newPlayer.run_away > 5:
clearscreen()
print ("\nYou're too much of a wimp to make it though the dungeon alive!\n"
"Don't show your face here again until you toughen yourself up!\n")
break
if not newPlayer.health:
print "\nYou were slain! Maybe you should carry more health potions with you next time!\n"