Advertisement
Guest User

Tile Clicker

a guest
Nov 21st, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. from tkinter import *
  2. import random
  3.  
  4. # Alik Balika
  5.  
  6. # Make a window
  7. window = Tk()
  8. window.title('Tile clicker')
  9.  
  10. # Make a canvas to put objects on the screen
  11. canvas = Canvas(window, width=350, height=500, bg='black')
  12. canvas.pack()
  13.  
  14. # Make a welcome screen that disappears after a short while
  15. title = canvas.create_text(175, 100, text='Tile Clicker', fill='DeepSkyBlue2', font=('Helvetica,', 30))
  16. directions = canvas.create_text(175, 400, text='Click on the black tiles and see how\n              far you can get!',
  17.                                 fill='DeepSkyBlue2',
  18.                                 font=('Helvetica', 15))
  19.  
  20.  
  21. # Display to show score on screen
  22. score = 0
  23. score_display = Label(window, text='Score :' + str(score))
  24. score_display.pack()
  25.  
  26. tile_list = []  # list to contain the tiles
  27. black_tile_list = []  # list to contain the tiles to be clicked
  28. tile_speed = 2  # initial speed of the tiles
  29. tile_color_list = ['white', 'black']  # colors of the tiles
  30.  
  31.  
  32. # template
  33.  
  34. # tile = canvas.create_rectangle(0, 0, 87.5, 125, outline='red', fill='white')
  35.  
  36. # function to make the tiles
  37. def make_tiles():
  38.     for row in range(4):  # this makes the tiles from row 1 to 4
  39.         x1 = 0
  40.         x2 = 0
  41.         y1 = 0
  42.         y2 = 0
  43.         for column in range(4):  # this makes the tiles from column 1 to 4
  44.             tile_color = random.choice(tile_color_list)
  45.             if row == 0:
  46.                 x2 = x2 + 87.5
  47.                 y2 = 125
  48.                 tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
  49.                 if tile_color == 'black':
  50.                     tile_color = 'white'
  51.                 x1 = x1 + 87.5
  52.  
  53.             if row == 1:
  54.                 x2 = x2 + 87.5
  55.                 y1 = 125
  56.                 y2 = 250
  57.                 tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
  58.                 if tile_color == 'black':
  59.                     tile_color = 'white'
  60.                 x1 = x1 + 87.5
  61.  
  62.             if row == 2:
  63.                 x2 = x2 + 87.5
  64.                 y1 = 250
  65.                 y2 = 375
  66.                 tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
  67.                 if tile_color == 'black':
  68.                     tile_color = 'white'
  69.                 x1 = x1 + 87.5
  70.  
  71.             if row == 3:
  72.                 x2 = x2 + 87.5
  73.                 y1 = 375
  74.                 y2 = 500
  75.                 tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
  76.                 if tile_color == 'black':
  77.                     tile_color = 'white'
  78.                 x1 = x1 + 87.5
  79.  
  80.     # window.after(1000, make_tiles)
  81.  
  82.  
  83.  
  84. def move_tiles():
  85.     pass
  86.  
  87.  
  88. def update_score():
  89.     global score
  90.     score += 1
  91.     score_display.config(text='Score :' + str(score))
  92.  
  93.  
  94. def end_title():
  95.     canvas.delete(title)
  96.     canvas.delete(directions)
  97.  
  98.  
  99. def end_game_over():
  100.     window.destroy()
  101.  
  102.  
  103. def key(event):
  104.     print('pressed', repr(event.char))
  105.  
  106. def click_on_tile(event):
  107.     canvas.focus_set()
  108.     print('clicked at', event.x, event.y)
  109.  
  110.  
  111. canvas.bind('<Key>', key)
  112. canvas.bind('<Button-1>', click_on_tile)
  113. canvas.pack()
  114.  
  115. make_tiles()
  116.  
  117. # player_is_dead = False
  118. #
  119. # while player_is_dead != True:
  120. #     pass
  121.  
  122.  
  123.  
  124.  
  125.  
  126. # this keeps the window running
  127. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement