-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpg.py
executable file
·135 lines (107 loc) · 3.65 KB
/
rpg.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
# Scraped from https://github.com/jusdepatate/rpg
import random
class Player:
health = 50
name = ""
isfighting = False
golds = 20
kills = 0
isplaying = True
inventory = [
"Dagger"
]
class Game:
def __init__(self):
self.ennemyhealth = 0
self.ennemy = ""
print("Welcome to this little textual RPG")
print("Made by Jus de Patate_")
while Player.name == "":
Player.name = input("What's the name of your character ?\n")
print("You have", Player.golds, "golds and your weapon is", Player.inventory[0])
def explore(self):
print(Player.name, "finds a new room and explore it...")
if Player.isfighting:
print("You can't explore while in fight")
return 0
rng = random.randint(0, 45)
if rng < 25:
# fight room
Player.isfighting = True
self.ennemyhealth = 25
self.ennemy = "Goblin"
print("Oh no, it's a", self.ennemy, "! Fight him or die !")
elif rng < 40:
# loot room
rng = random.randint(1, 3)
if rng == 1:
Player.inventory.append("Gem")
loot = "a gem"
elif rng == 2:
Player.inventory.append("Ancient Scroll")
loot = "an ancient scroll"
elif rng == 3:
Player.golds += 5
loot = "5 golds"
print(Player.name, "finds a room with a chest,", Player.name, "opens it and finds", loot)
else:
# empty room
print("You find an empty room.")
def fight(self):
if Player.isfighting:
rng = random.randint(0, 15)
if rng == 0:
print(Player.name, "misses", self.ennemy)
else:
print(Player.name, "hits ennemy for", rng, "HP")
self.ennemyhealth = self.ennemyhealth - rng
else:
print("You cannot fight yourself")
def sheet(self):
print(Player.name, "killed", Player.kills, "monsters.")
print(Player.name, "has", Player.health, "HP.")
print("Your bag contains:")
print(Player.golds, "golds")
for i in Player.inventory:
print(i)
def checks(self):
if Player.isfighting:
rng = random.randint(0, 15)
if rng == 0:
print(self.ennemy, "misses", Player.name)
else:
print(self.ennemy, "hits", Player.name, "for", rng, "HP")
Player.health = Player.health - rng
if Player.health <= 0:
print(Player.name, "is dead.")
quit()
if self.ennemyhealth <= 0:
print(self.ennemy, "is dead.")
Player.isfighting = False
self.ennemy = ""
Player.kills += 1
def detect(cmd):
if cmd == "explore" or cmd == "e":
Game.explore(Game)
elif cmd == "fight" or cmd == "f":
Game.fight(Game)
elif cmd == "sheet" or cmd == "s":
Game.sheet(Game)
elif cmd == "quit" or cmd == "q":
print(Player.name, "killed himself inside the dungeon")
Player.isplaying = False
else:
print("Command List:")
print("e / explore : explore the dungeon")
print("f / fight : available only in fights")
print("s / sheet : See character (" + Player.name + ") sheet")
print("q / quit : suicide\n")
Game()
print("")
while Player.isplaying:
Game.checks(Game)
print("What do you want to do ? (? for command list)")
cmd = input()
print("\n")
detect(cmd)