Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.system("cls")
- os.system("clear")
- class Gamestate():
- def __init__(self):
- self.room_dict = {}
- self.player = Player(name="blank", health=100, damage=15, rnum=1)
- self.generate_world()
- def generate_world(self):
- self.main = Room(rnum=1, rname="Main", rdesc="Welcome to room main", north=2, south=3, east=4, west=5)
- self.trail = Room(rnum=2, rname="Trail", rdesc="Welcome to room Trail", south=1)
- self.boat = Room(rnum=3, rname="Boat", rdesc="Welcome to room boat", north=1)
- self.east_shore = Room(rnum=4, rname="East Shore", rdesc="Welcome to the East Shore", west=1)
- self.west_shore = Room(rnum=5, rname="West Shore", rdesc="Welcome to the West Shore", east=1)
- self.room_dict = {self.main.rnum: self.main,
- self.trail.rnum: self.trail,
- self.boat.rnum: self.boat,
- self.east_shore.rnum: self.east_shore,
- self.west_shore.rnum: self.west_shore}
- class Player():
- def __init__(self, name, health, damage, rnum=1):
- self.name = name
- self.health = health
- self.damage = damage
- self.rnum = rnum
- self.location = None
- def print_stats(self):
- print("\n%ss stats:" % (self.name))
- print("Name: %s\nHealth: %d\nDamage: %d" % (self.name, self.health, self.damage))
- def spawn_exits(self):
- print("\nin method spawn exits")
- def do_look(self):
- print("\ncurrent room: %s\nroom description: %s" % (gamestate.player.location.rname, gamestate.player.location.rdesc))
- location = gamestate.player.location
- room_dict = gamestate.room_dict
- print("\nExits:")
- if location.north != None:
- north = room_dict[location.north]
- print("North: %s" % (north.rname))
- if location.south != None:
- south = room_dict[location.south]
- print("South: %s" % (south.rname))
- if location.east != None:
- east = room_dict[location.east]
- print("East: %s" % (east.rname))
- if location.west != None:
- west = room_dict[location.west]
- print("West: %s" % (west.rname))
- def get_room(self):
- current_room = gamestate.room_dict[self.rnum]
- self.location = current_room
- class Room():
- def __init__(self, rnum, rname, rdesc, north=None, south=None, east=None, west=None):
- self.rnum = rnum
- self.rname = rname
- self.rdesc = rdesc
- self.north = north
- self.south = south
- self.east = east
- self.west = west
- def print_room(self):
- print("\nrnum: %d\nrname: %s\nrdesc: %s"
- % (self.rnum, self.rname, self.rdesc))
- gamestate = Gamestate()
- gamestate.player.name = input("\nwhats your name?\nname: ")
- print("\nnice to meet you %s :)" % (gamestate.player.name))
- gamestate.player.get_room()
- gamestate.player.print_stats()
- def going_places(user_input):
- current_location = gamestate.room_dict[gamestate.player.rnum]
- if user_input[0] == "go":
- if user_input[1] == "north":
- if current_location.north != None:
- if current_location.north == gamestate.room_dict[current_location.north].rnum:
- gamestate.player.rnum = gamestate.player.location.north
- # when i say you have entered %s its the location name the user has entered
- # not user input...
- print("\nyou have entered %s" % gamestate.room_dict[current_location.north].rname)
- gamestate.player.location = gamestate.room_dict[current_location.north]
- if user_input[1] == "south":
- if current_location.south != None:
- if current_location.south == gamestate.room_dict[current_location.south].rnum:
- gamestate.player.rnum = gamestate.player.location.south
- print("\nyou have entered %s" % gamestate.room_dict[current_location.south].rname)
- gamestate.player.location = gamestate.room_dict[current_location.south]
- if user_input[1] == "east":
- if current_location.east != None:
- if current_location.east == gamestate.room_dict[current_location.east].rnum:
- gamestate.player.rnum = gamestate.player.location.east
- print("\nyou have entered %s" % gamestate.room_dict[current_location.east].rname)
- gamestate.player.location = gamestate.room_dict[current_location.east]
- if user_input[1] == "west":
- if current_location.west != None:
- if current_location.west == gamestate.room_dict[current_location.west].rnum:
- gamestate.player.rnum = gamestate.player.location.west
- print("\nyou have entered: %s" % gamestate.room_dict[current_location.west].rname)
- gamestate.player.location = gamestate.room_dict[current_location.west]
- def user_input():
- user_input = input("\n<\\ ").lower().split()
- if user_input[0] == "clear":
- os.system("clear")
- os.system("cls")
- elif user_input[0] == "go":
- going_places(user_input)
- def common():
- gamestate.player.do_look()
- user_input()
- def main():
- while True:
- common()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement