-
Notifications
You must be signed in to change notification settings - Fork 0
/
levels.py
80 lines (60 loc) · 2.45 KB
/
levels.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
# Game levels
from random import randint
from time import sleep
import string
import characters
import coin_flip
import rock_paper_scissors
# TODO
# Level for puzzle games like Hangman or Jumble
class PuzzleLevel(object):
def __init__(self, player):
self.player = player
# Level for fighting Monsters
class MonsterLevel(object):
def __init__(self, player):
self.player = player
def enter(self):
""" Instantiate a monster and deal with it, then update player stats. """
monster = characters.Monster(randint(1,10))
print "Oh no! Looks like you've run into a monster. It's level is %d." % monster.level
if monster.level >= self.player.level:
next = str.lower(raw_input("It's too strong for you, there's no way you can defeat it. Run away or fight? "))
if "run" in next:
escape = randint(1,6)
if escape >= 4:
print "Phew, that was close but you're safe for now..."
else:
print "You try to run, but the monster takes a hit at you. -2 health"
self.player.health -= 2
elif "fight" in next:
kill_monster = randint(1,10)
if kill_monster >= 8:
print "By a miracle, you defeat the monster! +2 level up!"
self.player.level += 2
else:
print "It was a valiant effort but you were no match for this beast."
print "-1 level down, -4 health"
self.player.level -=1
self.player.health -= 4
else:
print "The monster is no match for your greatness. +1 level up!"
self.player.level += 1
# Chance games such as Heads or Tails and Rock, Paper, Scissors
class ChanceLevel(object):
def __init__(self, player):
self.player = player
def enter(self):
""" Get and play a chance minigame and update player stats."""
key = randint(0,1)
minigame = self.get_minigame(key)
win = minigame.play()
if win == 1:
print "+1 level up."
self.player.level += 1
def get_minigame(self, key):
""" Return minigame object."""
if key == 0:
return coin_flip.CoinFlip()
else:
return rock_paper_scissors.RockPaperScissors()