I wrote a small "game" in Python for practice. I would like if someone could go over it and tell me if there is anything wrong or if there are any improvements I can make.
import time
import sys
class Creature:
def __init__(self, name, hp, inventory):
self.name = name
self.hp = hp
self.inventory = inventory
def get_hp(self):
return self.hp
def get_name(self):
return self.name
def get_inventory(self):
return self.inventory
def add_item(self, item):
self.inventory.append(item)
class Item:
def __init__(self, name, damage, special):
self.name=name
self.damage=damage
self.special=special
staff = Item("heroStaff", 2, "Nothing")
heroinv = [] # Hero inventory
Hero = Creature("A hero",100,heroinv)
print("You wake up in a dark room")
time.sleep(1)
print("1: Sleep more")
print("2: Look around")
key = input()
if key == "1":
print("You keep sleeping. Good night")
time.sleep(1)
print(".")
time.sleep(1)
print(".")
time.sleep(1)
print(".")
print("You wake up, feeling restored, you decide to look around")
time.sleep(1.5)
out = False
emptybox = False
door1key=False
while not out:
print("")
print("You look around and find a door, a window, and a box")
time.sleep(1)
print("1: Check door")
print("2: Check window")
print("3: Check box")
key = input()
if key == "1":
time.sleep(0.5)
print("trying to unlock door")
time.sleep(1)
print(".")
time.sleep(1)
if not out:
for items in Hero.get_inventory():
if items.name == "Door1Key":
print("CLICK!")
time.sleep(1)
print("*Door opened*")
time.sleep(1)
out = True
door1key=True
if not door1key:
print("Door Could not be opened")
time.sleep(1)
if key=="2":
print("The window is locked. Can't break it")
time.sleep(0.5)
if key=="3":
if not emptybox:
time.sleep(0.5)
print("You open the chest and find a staff(2 damage) and a key, you take them")
key=Item("Door1Key",0,"Nothing")
Hero.add_item(key)
Hero.add_item(staff)
time.sleep(2)
emptybox = True
else:
print("The box is empty")
time.sleep(0.5)
print("You step out of the room")
time.sleep(1)
print("You see an infected cat in front of you, with death in his eyes.")
time.sleep(2)
strkill="HE WANTS TO KILL YOU."
for char in strkill:
if char==' ':
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.5);
else:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.2);
print("")
time.sleep(1)
print("*Infected cat engages*")