Advertisement
Guest User

scratch.py

a guest
Dec 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. import os
  2.  
  3. os.system("cls")
  4. os.system("clear")
  5.  
  6.  
  7. class Gamestate():
  8. def __init__(self):
  9. self.room_dict = {}
  10. self.player = Player(name="blank", health=100, damage=15, rnum=1)
  11. self.generate_world()
  12.  
  13. def generate_world(self):
  14. self.main = Room(rnum=1, rname="Main", rdesc="Welcome to room main", north=2, south=3, east=4, west=5)
  15. self.trail = Room(rnum=2, rname="Trail", rdesc="Welcome to room Trail", south=1)
  16. self.boat = Room(rnum=3, rname="Boat", rdesc="Welcome to room boat", north=1)
  17. self.east_shore = Room(rnum=4, rname="East Shore", rdesc="Welcome to the East Shore", west=1)
  18. self.west_shore = Room(rnum=5, rname="West Shore", rdesc="Welcome to the West Shore", east=1)
  19.  
  20. self.room_dict = {self.main.rnum: self.main,
  21. self.trail.rnum: self.trail,
  22. self.boat.rnum: self.boat,
  23. self.east_shore.rnum: self.east_shore,
  24. self.west_shore.rnum: self.west_shore}
  25.  
  26. class Player():
  27. def __init__(self, name, health, damage, rnum=1):
  28. self.name = name
  29. self.health = health
  30. self.damage = damage
  31. self.rnum = rnum
  32. self.location = None
  33.  
  34. def print_stats(self):
  35. print("\n%ss stats:" % (self.name))
  36. print("Name: %s\nHealth: %d\nDamage: %d" % (self.name, self.health, self.damage))
  37.  
  38. def spawn_exits(self):
  39. print("\nin method spawn exits")
  40.  
  41. def do_look(self):
  42. print("\ncurrent room: %s\nroom description: %s" % (gamestate.player.location.rname, gamestate.player.location.rdesc))
  43.  
  44. location = gamestate.player.location
  45. room_dict = gamestate.room_dict
  46.  
  47. print("\nExits:")
  48. if location.north != None:
  49. north = room_dict[location.north]
  50. print("North: %s" % (north.rname))
  51. if location.south != None:
  52. south = room_dict[location.south]
  53. print("South: %s" % (south.rname))
  54. if location.east != None:
  55. east = room_dict[location.east]
  56. print("East: %s" % (east.rname))
  57. if location.west != None:
  58. west = room_dict[location.west]
  59. print("West: %s" % (west.rname))
  60.  
  61.  
  62. def get_room(self):
  63. current_room = gamestate.room_dict[self.rnum]
  64. self.location = current_room
  65.  
  66. class Room():
  67. def __init__(self, rnum, rname, rdesc, north=None, south=None, east=None, west=None):
  68. self.rnum = rnum
  69. self.rname = rname
  70. self.rdesc = rdesc
  71. self.north = north
  72. self.south = south
  73. self.east = east
  74. self.west = west
  75.  
  76. def print_room(self):
  77. print("\nrnum: %d\nrname: %s\nrdesc: %s"
  78. % (self.rnum, self.rname, self.rdesc))
  79.  
  80. gamestate = Gamestate()
  81.  
  82. gamestate.player.name = input("\nwhats your name?\nname: ")
  83. print("\nnice to meet you %s :)" % (gamestate.player.name))
  84.  
  85. gamestate.player.get_room()
  86. gamestate.player.print_stats()
  87.  
  88.  
  89. def going_places(user_input):
  90. current_location = gamestate.room_dict[gamestate.player.rnum]
  91. if user_input[0] == "go":
  92. if user_input[1] == "north":
  93. if current_location.north != None:
  94. if current_location.north == gamestate.room_dict[current_location.north].rnum:
  95. gamestate.player.rnum = gamestate.player.location.north
  96. # when i say you have entered %s its the location name the user has entered
  97. # not user input...
  98. print("\nyou have entered %s" % gamestate.room_dict[current_location.north].rname)
  99. gamestate.player.location = gamestate.room_dict[current_location.north]
  100. if user_input[1] == "south":
  101. if current_location.south != None:
  102. if current_location.south == gamestate.room_dict[current_location.south].rnum:
  103. gamestate.player.rnum = gamestate.player.location.south
  104. print("\nyou have entered %s" % gamestate.room_dict[current_location.south].rname)
  105. gamestate.player.location = gamestate.room_dict[current_location.south]
  106. if user_input[1] == "east":
  107. if current_location.east != None:
  108. if current_location.east == gamestate.room_dict[current_location.east].rnum:
  109. gamestate.player.rnum = gamestate.player.location.east
  110. print("\nyou have entered %s" % gamestate.room_dict[current_location.east].rname)
  111. gamestate.player.location = gamestate.room_dict[current_location.east]
  112. if user_input[1] == "west":
  113. if current_location.west != None:
  114. if current_location.west == gamestate.room_dict[current_location.west].rnum:
  115. gamestate.player.rnum = gamestate.player.location.west
  116. print("\nyou have entered: %s" % gamestate.room_dict[current_location.west].rname)
  117. gamestate.player.location = gamestate.room_dict[current_location.west]
  118.  
  119.  
  120. def user_input():
  121.  
  122. user_input = input("\n<\\ ").lower().split()
  123.  
  124. if user_input[0] == "clear":
  125. os.system("clear")
  126. os.system("cls")
  127. elif user_input[0] == "go":
  128. going_places(user_input)
  129.  
  130. def common():
  131. gamestate.player.do_look()
  132. user_input()
  133.  
  134. def main():
  135. while True:
  136. common()
  137.  
  138. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement