Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created May 27, 2017 14:18
Show Gist options
  • Save SpaceVoyager/91fbe358a6184e4cfbca43d4f7697747 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/91fbe358a6184e4cfbca43d4f7697747 to your computer and use it in GitHub Desktop.
rabbitrobber.py
import ui
import random
rabbit_size = 50
v = ui.View(background_color=('#bcdeff'))
board = ui.View()
v.add_subview(board)
v.present('full_screen', hide_title_bar=False , orientations=['landscape'])
board.frame = (v.width-v.height + rabbit_size/2, rabbit_size/2 , v.height - rabbit_size, v.height - rabbit_size)
board.border_width = 10
board.border_color = ('black')
board.background_color = ('#ffffff')
rows = 8
cols = 8
blocks = []
for r in range(rows):
for c in range(cols):
random_num = random.randint(1, 100)
image = ui.ImageView()
if random_num < 12:
image = ui.ImageView()
image.image = ui.Image('emj:Boar')
elif random_num < 24 and random_num > 11:
image = ui.ImageView()
image.image = ui.Image('emj:Bank')
else:
image.background_color = ('#838383')
image.width = board.height/cols
image.height = board.height/rows
image.border_color = ('black')
image.border_width = 5
image.x = image.width*c
image.y = image.height*r
image.font = ('American Typewriter',60)
board.add_subview(image)
blocks.append({'image' : image, 'row_number' : r, 'column_number' : c})
rabbit_buttons = []
for r in range(rows + 1):
for c in range(cols + 1):
test_rabbit_button = ui.Button()
test_rabbit_button.image = ui.Image('emj:Rabbit_Face')
test_rabbit_button.tint_color = .89, .9, .77
test_rabbit_button.x = -18 + v.width-v.height + rabbit_size/2 + r*float(board.width-10)/cols
test_rabbit_button.y = -5 + c*float(board.height - 3)/rows
test_rabbit_button.width = rabbit_size
test_rabbit_button.height = rabbit_size
v.add_subview(test_rabbit_button)
rabbit_buttons.append({'rabbit' : test_rabbit_button, 'row_number' : r, 'column_number' : c})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment