SHARE
TWEET

Untitled

a guest Aug 24th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from turtle import Turtle
  2.  
  3. class Character:
  4.  
  5.     turtles = ["Leonardo", "Donatello", "Raphael", "Michaelangelo"]
  6.     color = {"Leonardo" : "blue" ,  "Donatello" : "purple", "Raphael" : "red" , "Michaelangelo": "orange"}
  7.     weapon = {"Leonardo" : "ninjato" ,  "Donatello" : "bo", "Raphael" : "sai" , "Michaelangelo": "nunchuck"}
  8.  
  9.     def __init__(self, name = None):
  10.         self.name = None
  11.  
  12.     def get_turtle(self):
  13.         """
  14.         User selects turtle from class variable turtle
  15.         user selecton checks color and weapon variables to match with turtle selected
  16.         turtle deleted from index so that map class can create the other turtles
  17.         """
  18.         while self.name == None:
  19.             select = input("Please select your Ninja Turtle: Leonardo, Donatello, Raphael, or Michaelangelo.\n")
  20.             if  select in Character.turtles:
  21.                 self.name = select
  22.                 index = Character.turtles.index(self.name)
  23.                 del Character.turtles[index]
  24.             else:
  25.                 print("Please select one of the Turtles")
  26.         self.weapon = Character.weapon[self.name]
  27.         self.color = Character.color[self.name]
  28.         print("You selected: " + self.name + ".")
  29.         print("You are the " + self.color + " turtle.")
  30.         print("Your weapon is a " + self.weapon + ".\n")
  31.  
  32.  
  33. class Room:
  34.     def __init__(self, room_name, description):
  35.         """
  36.         sets room name, description
  37.         creates a dictionary to capture room names and directions to guide user movement
  38.         """
  39.         self.room_name = room_name
  40.         self.description = description
  41.         self.linked_rooms = {}
  42.  
  43.     def map_to(self, room_link, direction):
  44.         """
  45.         adds rooms and directions to dictionary created in __init__ method
  46.         """
  47.         self.linked_rooms[direction] = room_link
  48.        
  49.     def room_details(self):
  50.         """
  51.         prints out current room and description
  52.         prints out adjoining rooms and their directions to guide users movement
  53.         """
  54.         print(self.room_name)
  55.         print("")
  56.         print(self.description)
  57.         for direction in self.linked_rooms:
  58.           room = self.linked_rooms[direction]
  59.           print("The " + room.room_name + " is " + direction)
  60.        
  61.     def movement(self, direction):
  62.         """
  63.         allows user movement between rooms
  64.         """
  65.         if direction in self.linked_rooms:
  66.             return self.linked_rooms[direction]
  67.         else:
  68.             print("There is no exit that way")
  69.             return self
  70.  
  71. class Map:
  72.     def __init__(self, name):
  73.         self.name = name
  74.    
  75.     def startmap(self):
  76.         """
  77.         uses turtle module to create the map
  78.         sets color of turtle to match the color of the user's selection
  79.         """
  80.         combos = [(-100,-100), (-40,-100), (-40,-40), (20, -100), (20,-40), (20,20), (80, -100), (80,-40), (140, -40)]
  81.         mapp = False
  82.         while mapp == False:
  83.             zone.shape("turtle")
  84.             zone.color("black")
  85.             zone.pensize(4)
  86.             zone.speed(0)
  87.             zone.penup()
  88.             for combo in combos:
  89.                 zone.goto(combo)
  90.                 zone.pendown()
  91.                 for combo in range(4):
  92.                     zone.forward(60)
  93.                     zone.left(90)
  94.                 zone.penup()
  95.             zone.goto(-70,-70)
  96.             zone.color(Character.color[player1.name])
  97.             mapp = True
  98.            
  99.     def movement(self, x, y):
  100.         """
  101.         moves the turtle through the map based on coordinates in the overall grid
  102.         """
  103.         self.x = x
  104.         self.y = y
  105.         zone.goto(self.x, self.y)
  106.  
  107.     def endmap(self):
  108.         """
  109.         creates three more turtles and matches them to the colors of the character not selected by the user
  110.         creats an additional turtle and shapes it as an orange circle to represent the pizza
  111.         moves all the new creations to the final room
  112.         """
  113.         turt2 = Turtle()
  114.         turt3 = Turtle()
  115.         turt4 = Turtle()
  116.         turt5 = Turtle()
  117.         two = Character.turtles[0]
  118.         color2 = Character.color[two]
  119.         three = Character.turtles[1]
  120.         color3 = Character.color[three]
  121.         four = Character.turtles[2]
  122.         color4 = Character.color[four]
  123.         turt2.shape("turtle")
  124.         turt3.shape("turtle")
  125.         turt4.shape("turtle")
  126.         turt2.color(color2)
  127.         turt2.penup()
  128.         turt2.right(180)
  129.         turt2.goto(190,10)
  130.         turt3.color(color3)
  131.         turt3.penup()
  132.         turt3.right(180)
  133.         turt3.goto(190,-10)
  134.         turt4.color(color4)
  135.         turt4.penup()
  136.         turt4.right(180)
  137.         turt4.goto(190,-30)
  138.         turt5.shape("circle")
  139.         turt5.penup()
  140.         turt5.right(180)
  141.         turt5.goto(170,-10)
  142.         turt5.color("dark orange")
  143.        
  144.  
  145. class Game:
  146.     def __init__(self):
  147.         print("""_______________________________
  148.             TMNT
  149. The Legend of the Greatest Pizza!
  150. ________________________________ \n""")
  151.  
  152.     def start(self):
  153.         print("You hear the Turtle emergency phone ring and answer it.\n")
  154.         player1.get_turtle()
  155.         print("""On the other end of the line you hear Splinter,
  156. "Oh {} it's you. Fantastic!"
  157. "We need you to get to GoodCorp Labs as soon as possible.
  158. They were in the middle of developing a solution to World Peace...
  159. and the worlds greatest pizza ...
  160. but Shredder showed up and is trying to steal the technology.
  161. We need you to join the other turtles and get there before Shreddar
  162. takes the tech.
  163. Take the map I left on the refrigerator and go.
  164. The map should automatically load and show your location at the Labs."
  165. You say: 'the world's greatest pizza, I've got to get there fast.'\n""".format(player1.name))
  166.  
  167.         print("________________________________________________________\n")
  168.         current_room = lobby
  169.         mapmaker = Map("A")
  170.         mapmaker.startmap()
  171.         x_var = {lobby : -70, main : -10, break_room : -10, sales : 50, file : 50, bathroom : 50, production : 110, lab : 110, research : 150}
  172.         y_var = {lobby : -70, main : -70, break_room : -10, sales : -70, file : -10, bathroom : 50, production : -70, lab : -10, research : -10}
  173.         end = None
  174.         while current_room != research and end != "q":
  175.             current_room.room_details()
  176.             action = input("""\nThe available movements are north, east, south and west.
  177. You may be limited in which direction you can move by the room you are in.
  178. Refer to the info right below room description to see available movement directions
  179. Input your action here-->""").lower()
  180.             if action in ["north", "south", "east", "west"]:
  181.                 current_room = current_room.movement(action)
  182.                 mapmaker.movement(x_var[current_room], y_var[current_room])
  183.             if current_room == research:
  184.                mapmaker.endmap()
  185.                print("Research and Development")
  186.                print(research.description)
  187.                print("You join the other turtles in victory over Shredder, but know he will be back.\n")
  188.                print("Now is time to enjoy the best pizza ever!")
  189.                end = input("Type q to quit.")
  190.        
  191.  
  192. # The items below are the room names and descriptions for each each instance of the Room class.
  193. lobby = Room("Lobby", """You arrive in the lobby of the Lab.
  194. The door was broken and there is office equipment scattered around the room.
  195. the emergency lights are flashing all around you.\n""")
  196. main = Room("Main Office", """The main office area.
  197. Most of the desks and computers have been broken.
  198. Injured police, scientists, and businessmen are lying on the floor.
  199. One of the police begs you to reach the tech before Shredder\n""")            
  200. break_room = Room("Break Room", """A room with a few small tables a refrigerator and a microwave.
  201. You can tell that your fellow turtles have been here.
  202. You smell microwaved pizza.\n""")
  203. sales = Room("Sales Office", """The room is mostly dark with just a single flourescent bulb providing light.
  204. You see a foot soldier.
  205. You sneak up behind him and grab him.
  206. He begs to be let go for information.
  207. You let him go and he tells you Shredder went towards the lab.\n""")
  208. file = Room("File Room", """The room has long rows of file cabinets.
  209. A few cabinets have been opened and their files are thrown across the floor.\n""")
  210. bathroom = Room("Bathroom", """A standard bathroom.
  211. There is nothing in here.\n""")
  212. production = Room("Production Room", """The room contains multiple manuals and engineering equipment.
  213. Most of it has been smashed.
  214. You see a foot soldier on the ground.
  215. The other turtles must be near.\n""")
  216. lab = Room("Lab", """A standard chemistry lab with lots of vials, scales and bunsen burners.
  217. Most of the equipment has been smashed.
  218. You see Shredder, he is trying to get to the Research and Development room.
  219. He sees you and knows that with you there there's no way he can win the fight.
  220. He jumps through the window without the tech.\n""")
  221. research = Room("Research and Development", """The room where final products are tested and approved.
  222. The room smells of the most delicious pizza ever.""")
  223.  
  224. # this takes the room instance and links them to adjacent rooms and their directions
  225. lobby.map_to(main, "east")
  226. main.map_to(lobby, "west")
  227. main.map_to(break_room, "north")
  228. main.map_to(sales, "east")
  229. break_room.map_to(main, "south")
  230. sales.map_to(main, "west")
  231. sales.map_to(file, "north")
  232. sales.map_to(production, "east")
  233. file.map_to(sales, "south")
  234. file.map_to(bathroom, "north")
  235. bathroom.map_to(file, "south")
  236. production.map_to(sales, "west")
  237. production.map_to(lab, "north")
  238. lab.map_to(production, "south")
  239. lab.map_to(research, "east")
  240.  
  241. player1 = Character()
  242. zone = Turtle()
  243. turt2 = Turtle()
  244. turt3 = Turtle()
  245. turt4 = Turtle()
  246. turt4 = Turtle()
  247. game = Game()
  248. game.start()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top