Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.26 KB | None | 0 0
  1. from graphics import *
  2. import time
  3.  
  4.  
  5. class MC:
  6.     def __init__(self, x, y, radius, window):
  7.         self.window = window
  8.         self.goingLeft = True
  9.         self.goingRight = True
  10.         self.goingUp = True
  11.         self.goingDown = True
  12.         self.circleColor = color_rgb(0, 255, 0)
  13.         self.circle = Circle(Point(x, y), radius)
  14.         self.circle.setFill(self.circleColor)
  15.         self.circle.draw(window)
  16.  
  17.  
  18.     def step(self):
  19.         windowHeight = self.window.getHeight()
  20.         windowWidth = self.window.getWidth()
  21.         x = self.circle.getCenter().getX()
  22.         y = self.circle.getCenter().getY()
  23.  
  24.         if self.goingLeft:
  25.             dx = -10
  26.  
  27.         if self.goingRight:
  28.             dx = 10
  29.  
  30.         if x + dx >= windowWidth - self.circle.getRadius():
  31.             self.goingLeft = False
  32.         elif x + dx <= self.circle.getRadius():
  33.             self.goingLeft = True
  34.            
  35.         if self.goingUp:
  36.             dy = -10
  37.            
  38.  
  39.         if self.goingDown:
  40.             dy = 10
  41.  
  42.  
  43.         if y + dy >= windowHeight - self.circle.getRadius():
  44.             self.goingUp = False
  45.         elif y + dy <= self.circle.getRadius():
  46.             self.goingUp = True
  47.            
  48.        # self.circle.setFill(color_rgb(int(255 * (windowWidth - x) / windowWidth),0,int(255 * (x / windowWidth))))
  49.         #self.circle.setFill(self.downColor *((windowHeight - y) / windowHeight) + self.UpColor * (y / windowHeight))
  50.    
  51.         self.circle.move(dx, 0)
  52.        
  53.     def routeLR(self):
  54.         direction = input('Where do you want to go? Your choices are left or right. ')
  55.         if direction.rstrip() == "":
  56.             print("Type something!")
  57.             self.routeLR()
  58.         elif direction.rstrip() == "^[[C":
  59.             print("Type something!")
  60.             self.routeLR()
  61.         elif direction.rstrip() == "^[[D":
  62.             print("Type something!")
  63.             self.routeLR()
  64.         elif direction.rstrip().lower().startswith("l"):
  65.             self.goingLeft = True
  66.             self.goingRight = False
  67.             for i in range(7):
  68.                 self.step()
  69.    
  70.         elif direction.rstrip() == "right":
  71.             self.goingLeft = False
  72.             self.goingRight = True
  73.             for i in range(7):
  74.                  self.step()
  75.         else:
  76.             print('Rude. Try again')
  77.             self.routeLR()
  78.  
  79.     def routeUD(self):
  80.         direction = input('Good! How about trying up or down? ')
  81.         if direction == "up":
  82.             self.goingUp = True
  83.             self.goingDown = False
  84.             for i in range(7):
  85.                 self.step()
  86.    
  87.         elif direction == "down":
  88.             self.goingUp = False
  89.             self.goingDown = True
  90.             for i in range(7):
  91.                 self.step()
  92.         else:
  93.             print('Stop that! Try again')
  94.             self.routeUD()
  95.  
  96. def sayMaize(window, x, y):
  97.     textColor = color_rgb(255, 255, 255)
  98.     text = Text(Point(x, y), 'The Maize')
  99.     text.setTextColor(textColor)
  100.     text.setSize(24)
  101.     text.draw(window)
  102.  
  103.  
  104.  
  105.  
  106.    
  107.  
  108.  
  109. def main():
  110.     windowHeight = 500
  111.     windowWidth = 500
  112.     windowTitle = 'worldworld'
  113.     radius = 70
  114.     center = Point(windowWidth / 2, windowHeight / 2)
  115.     circle = Circle(center, radius)
  116.     backgroundColor = color_rgb(40, 40, 40)
  117.     window = GraphWin(windowTitle, windowWidth, windowHeight)
  118.     window.setBackground(backgroundColor)
  119.     ball = MC(windowWidth / 2, 250, 50, window)
  120.  
  121.  
  122.  
  123.     sayMaize(window, (windowWidth/2), (windowHeight/1.2))
  124.    
  125.     print('Welcome to the maize! Press enter if you want to talk.')
  126.     input("")
  127.     print("The rules are simple. You're trapped and I know the way out. ")
  128.     input("")
  129.     print("I'll help you if you want, but we'll have to be fast.")
  130.     input("")
  131.     print("Don't worry, they don't know you're here yet. They know I still have to teach you how the game works. ")
  132.     input("")
  133.     print("Let's start simple. Do you know how to move?")
  134.     input("")
  135.  
  136.     ball.routeLR()
  137.     ball.routeUD()
  138.    
  139.     time.sleep(1.00)
  140.    
  141.  
  142.  
  143.     #sayTextMaize(window, (windowWidth/2), (windowHeight/1.2))
  144.  
  145.     response = input('Hit Enter to quit')
  146.     window.close()
  147.    
  148.  
  149.  
  150.  
  151.  
  152.  
  153.    
  154. if __name__ == "__main__":
  155.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement