Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import random
- # Alik Balika
- # Make a window
- window = Tk()
- window.title('Tile clicker')
- # Make a canvas to put objects on the screen
- canvas = Canvas(window, width=350, height=500, bg='black')
- canvas.pack()
- # Make a welcome screen that disappears after a short while
- title = canvas.create_text(175, 100, text='Tile Clicker', fill='DeepSkyBlue2', font=('Helvetica,', 30))
- directions = canvas.create_text(175, 400, text='Click on the black tiles and see how\n far you can get!',
- fill='DeepSkyBlue2',
- font=('Helvetica', 15))
- # Display to show score on screen
- score = 0
- score_display = Label(window, text='Score :' + str(score))
- score_display.pack()
- tile_list = [] # list to contain the tiles
- black_tile_list = [] # list to contain the tiles to be clicked
- tile_speed = 2 # initial speed of the tiles
- tile_color_list = ['white', 'black'] # colors of the tiles
- # template
- # tile = canvas.create_rectangle(0, 0, 87.5, 125, outline='red', fill='white')
- # function to make the tiles
- def make_tiles():
- for row in range(4): # this makes the tiles from row 1 to 4
- x1 = 0
- x2 = 0
- y1 = 0
- y2 = 0
- for column in range(4): # this makes the tiles from column 1 to 4
- tile_color = random.choice(tile_color_list)
- if row == 0:
- x2 = x2 + 87.5
- y2 = 125
- tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
- if tile_color == 'black':
- tile_color = 'white'
- x1 = x1 + 87.5
- if row == 1:
- x2 = x2 + 87.5
- y1 = 125
- y2 = 250
- tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
- if tile_color == 'black':
- tile_color = 'white'
- x1 = x1 + 87.5
- if row == 2:
- x2 = x2 + 87.5
- y1 = 250
- y2 = 375
- tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
- if tile_color == 'black':
- tile_color = 'white'
- x1 = x1 + 87.5
- if row == 3:
- x2 = x2 + 87.5
- y1 = 375
- y2 = 500
- tile = canvas.create_rectangle(x1, y1, x2, y2, outline='black', fill=tile_color)
- if tile_color == 'black':
- tile_color = 'white'
- x1 = x1 + 87.5
- # window.after(1000, make_tiles)
- def move_tiles():
- pass
- def update_score():
- global score
- score += 1
- score_display.config(text='Score :' + str(score))
- def end_title():
- canvas.delete(title)
- canvas.delete(directions)
- def end_game_over():
- window.destroy()
- def key(event):
- print('pressed', repr(event.char))
- def click_on_tile(event):
- canvas.focus_set()
- print('clicked at', event.x, event.y)
- canvas.bind('<Key>', key)
- canvas.bind('<Button-1>', click_on_tile)
- canvas.pack()
- make_tiles()
- # player_is_dead = False
- #
- # while player_is_dead != True:
- # pass
- # this keeps the window running
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement