repl.it
@HenryShearer/

Adventure Game

Python

No description

fork
loading
Files
  • main.py
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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#Import Modules For Later
import time as t
import random as r
import os,sys
from colorama import Fore, Style

#print(Style.RESET_ALL)


#Define all variables, lists, etc.
items = {"sword": "A sharp hunk of metal, perfect for decapitating enemies!", "key": "This ornately carved piece of bronze looks perfect for opening a lock" }

rooms = {"spawn": "A blank room for debugging."}

actions = {"look": "Look", "go": "Go", "clear": "Clear", "help": "Help", "attack": "Attack",}

monsters = {"goblin": "A warty green thing"}

monstersDC = {"goblin": 1,}

inventory = []

currentlocation = "spawn"

PlayerNotDead = True
EnemyNotDead = True
tempitem = 0
templength = 0
check_race = 0
health = 0
damage = 0
dodge = 0
name = 0
XP = 0
EnemyHP = 50
Level = 1
EnemyRoll = 0
EnemyArmor = 10
quit = False
attack = True

#I need to add classes
#class Player(self)

#class Enemy(object):
    #roomIn = ("spawn")



#class Weapon(object):
    #roomIn = ("spawn")
    #damage = 0



#Define Functions
def clearScreen():  
    os.system('cls' if os.name=='nt' else 'clear')

def setupGame():
  global health
  global name
  global damage
  global dodge
  global check_race
  name = input(Fore.CYAN + "What is your name, Hero? > ")
  check_race = input("Are you an elf, dwarf, human, troll or hobbit? > ")
  print(Style.RESET_ALL)
  check_race = str(check_race.lower())
  if check_race == "elf":
      health = 10
      damage = 20
      dodge = 15
  elif check_race == "dwarf":
      health = 20
      damage = 15
      dodge = 10
  elif check_race == "human":
      health = 15
      damage = 15
      dodge = 15
  elif check_race == "hobbit":
      health = 10
      damage = 10
      dodge = 50
  elif check_race == "troll":
      health = 20
      damage = 25
      dodge = 0
  else:
      setupGame()

def UpdateGame():
  pass

def Look(x):
  print(Fore.GREEN)
  if x == "look":
    print(rooms[currentlocation])
    print(Style.RESET_ALL)
  elif x in items:
    print(items[x])
    print(Style.RESET_ALL)
  elif x in monsters:
    print(monsters[x])
    print(Style.RESET_ALL)
  else:
    print(Fore.RED + "What?") 
    print(Style.RESET_ALL)

def Take():
  pass

def Attack(x):
  global attack
  global EnemyHP
  global EnemyArmor
  global EnemyNotDead
  global PlayerNotDead
  if x in monsters:  
    if attack == True:
      if PlayerNotDead and EnemyNotDead:
          checkForHit = r.randint(0, 20)
          print(checkForHit)
          if checkForHit >= EnemyArmor:
              damageDealt = r.randint(0, 20)
              damageDealt += damage
              EnemyHP -= damageDealt
              print(Fore.YELLOW + f"You did {damageDealt} damage to the {x}")
              if EnemyHP <= 0:
                print(f"You killed the {x}!")
                EnemyNotDead = False
                attack = False
                GetLoot(x, monstersDC[x]) #NEED TO FIX
                print(Style.RESET_ALL)
              else:
                pass #continue fight
          else:
            print(Fore.YELLOW + "It hit the armor.") #hit armor
      else:
        pass #end combat
    else:
      print(Fore.RED + "There is nothing to attack!")
      print(Style.RESET_ALL)
  else: 
    print(Fore.RED + "Attack what?")
    print(Style.RESET_ALL)

def Help():
  for action in actions:
    currentAction = actions[action]
    print(Fore.RED + currentAction)
  print(Style.RESET_ALL)

def TakeInput(x):
    x = x.lower()
    args = x.split(' ') 
    length = len(args)
    if args[0] in actions:
        if args[0] == "look":
          Look(args[length-1])
        elif args[0] == "clear":
          clearScreen()
        elif args[0] == "help":
          Help()
        elif args[0] == "attack":
          Attack(args[length-1])
    else:
        print(Fore.RED + "I don't know what you mean")
        print(Style.RESET_ALL)

def RandomEncounter(Monster):
  #add individual monster noises)
  EnemyRoll = r.randint(0, 20)
  PlayerRoll = r.randint(0, 20)
  if EnemyRoll > PlayerRoll:
    pass
  else:
    pass

def init():
  clearScreen()
  setupGame()
  inventory.clear()

def MainLoop():
  UpdateGame()
  TakeInput(input("> "))

def GetLoot(Monster, DC):
  DC = int(DC)
  if DC % 2 == 0:  
    lowBound = int(DC/2)
  else: lowBound = int((DC+1)/2)
  lootCheck = r.randint(lowBound, DC)
  if lootCheck == 1:
    print(f"The {Monster} had nothing.")
    inventory.append(None)
  elif lootCheck == 2:
    print(f"The {Monster} had nothing.")
    inventory.append(None)
  if lootCheck == 3:
    print(f"The {Monster} had nothing.")
    inventory.append(None)
  if lootCheck == 4:
    print(f"The {Monster} had nothing.")
    inventory.append(None)



#run game
init()
while quit == False:
  MainLoop()
?