Advertisement
Guest User

asdf

a guest
Dec 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. # Exemplar Graphics-5
  2. # This is an example program that contains graphics using
  3. # the pygame module, contains user-defined classes, and
  4. # responds to multiple kinds of events.
  5. # It contains these kinds of statements: expression, assignment,
  6. # import, function definition, while, for, if, return, class
  7. # definition
  8. # It contains these kinds of expressions: identifier, literal,
  9. # attribute reference, function call, binary operator, expression
  10. # list
  11. # It uses these types: str, int, float, bool, NoneType, function,
  12. # module, tuple, pygame.Color, pygame.Rect, Game,
  13. # Circle
  14.  
  15. from uagame import Window
  16. import pygame, time
  17. from pygame.locals import *
  18.  
  19. # User-defined functions
  20.  
  21. def main():
  22.  
  23. window = Window('ur mom', 500, 400)
  24. window.set_auto_update(False)
  25. game = Game(window)
  26. game.play()
  27. window.close()
  28.  
  29. # User-defined classes
  30. class Tile:
  31. def __init__(self, spot, window, x, y, width, height):
  32.  
  33. self.spot = spot
  34. self.window = window
  35. self.x_coor = x
  36. self.y_coor = y
  37. self.width = width
  38. self.height = height
  39. self.color = pygame.Color('white')
  40. self.border = 3
  41. self.clicked = False
  42.  
  43. def draw(self):
  44.  
  45. self.rect = pygame.draw.rect(self.window.get_surface(), self.color, [self.x_coor, self.y_coor, self.width, self.height],self.border)
  46.  
  47. def click(self, mouse_pos):
  48.  
  49. self.mouse_pos = mouse_pos
  50. thisissomethingrandom = self.rect.collidepoint(self.mouse_pos)
  51. print(type(True))
  52.  
  53.  
  54. #print(typing)
  55. #print(str(self.mouse_pos))
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. class Game:
  63. # An object in this class represents a complete game.
  64.  
  65. def __init__(self, window):
  66. # Initialize a Game.
  67. # - self is the Game to initialize
  68. # - window is the uagame window object
  69.  
  70. self.window = window
  71. self.bg_color = pygame.Color('blue')
  72. self.fg_color_str = "green"
  73. self.pause_time = 0.04 # smaller is faster game
  74. self.close_clicked = False
  75. self.continue_game = True
  76. self.window.set_bg_color('black')
  77. self.blah_pos = 0
  78. self.viewablah = False
  79.  
  80. #Tiles
  81. self.grid_size = 3
  82. self.which_tile = 0
  83. self.wind_x = window.get_width()
  84. self.wind_y = window.get_height()
  85. self.put_row = []
  86. tiles_width = self.wind_x // self.grid_size
  87. tiles_height = self.wind_y // self.grid_size
  88.  
  89. #Tile(self, spot, window, x, y, width, height):
  90. for column_spot in range (0, self.grid_size):
  91. tiles_y = (tiles_height)*column_spot
  92. for row_spot in range(0, self.grid_size):
  93. tiles_x = (tiles_width)*row_spot
  94. self.the_tile = Tile(row_spot, self.window, tiles_x , tiles_y, tiles_width, tiles_height)
  95. self.put_row.append(self.the_tile)
  96.  
  97.  
  98. def play(self):
  99. # Play the game until the player presses the close box.
  100. # - self is the Game that should be continued or not.
  101.  
  102. while not self.close_clicked: # until player clicks close box
  103. # play frame
  104. self.handle_event()
  105. self.draw()
  106. if self.continue_game:
  107. self.update()
  108. self.decide_continue()
  109. time.sleep(self.pause_time) # set game velocity by pausing
  110.  
  111. def handle_event(self):
  112. # Handle each user event by changing the game state
  113. # appropriately.
  114. # - self is the Game whose events will be handled
  115.  
  116. event = pygame.event.poll()
  117. if event.type == QUIT:
  118. self.close_clicked = True
  119. elif event.type == MOUSEBUTTONUP and self.continue_game:
  120. self.handle_mouse_up()
  121.  
  122.  
  123.  
  124.  
  125. def draw(self):
  126. # Draw all game objects.
  127. # - self is the Game to draw
  128. self.window.clear()
  129. if self.viewablah == True:
  130. self.window.draw_string('blah', self.blah_pos, self.blah_pos)
  131. for tiles in range (0, (self.grid_size*self.grid_size)):
  132. self.the_thingy = self.put_row[tiles]
  133. Tile.draw(self.the_thingy)
  134. if not self.continue_game:
  135. # Perform appropriate game over actions
  136. self.window.clear()
  137. self.window.update()
  138.  
  139. def handle_mouse_up(self):
  140. # Respond to the player releasing the mouse button by
  141. # taking appropriate actions.
  142. # - self is the Game where the mouse up occurred
  143. where_mouse = pygame.mouse.get_pos()
  144. for n in range(0,9):
  145. this = self.put_row[n]
  146. this.click(where_mouse)
  147.  
  148.  
  149.  
  150.  
  151. pass
  152.  
  153. def update(self):
  154. # Update the game objects.
  155. # - self is the Game to update
  156.  
  157. self.elapsed_time = pygame.time.get_ticks() // 1000
  158.  
  159. def decide_continue(self):
  160. # Check and remember if the game should continue
  161. # - self is the Game to check
  162. pass
  163.  
  164. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement