Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
boggle by struggling pythonista
import ui
from random import randint
import time
import random
import json
w,h = ui.get_screen_size()
view = ui.View(bg_color='#0D76A8', frame=(0,0,w,h))
N = 4 #size of grid
dice = {0: ['A', 'A', 'E', 'E', 'G', 'N'],
1: ['E', 'L', 'R', 'T', 'T', 'Y'],
2: ['A', 'O', 'O', 'T', 'T', 'W'],
3: ['A', 'B', 'B', 'J', 'O', 'O'],
4: ['E', 'H', 'R', 'T', 'V', 'W'],
5: ['C', 'I', 'M', 'O', 'T', 'U'],
6: ['D', 'I', 'S', 'T', 'T', 'Y'],
7: ['E', 'I', 'O', 'S', 'S', 'T'],
8: ['D', 'E', 'L', 'R', 'V', 'Y'],
9: ['A', 'C', 'H', 'O', 'P', 'S'],
10: ['H', 'I', 'M', 'N', 'Q', 'U'],
11: ['E', 'E', 'I', 'N', 'S', 'U'],
12: ['E', 'E', 'G', 'H', 'N', 'W'],
13: ['A', 'F', 'F', 'K', 'P', 'S'],
14: ['H', 'L', 'N', 'N', 'R', 'Z'],
15: ['D', 'E', 'I', 'L', 'R', 'X']}
# add subview to hold dice
square = 125
grid = 4
mg = 10
tray_size = (N * square) + (N * grid) + (3*grid)
main_button = ui.Button(name = 'main_button', bg_color='#0D3C64', tint_color='white', frame=(w/2-120,h-150,240,100))
main_button.title = 'Roll'
view.add_subview(main_button)
main_button.corner_radius=5
tray = ui.View(bg_color='#999999', frame=(w/2-250,h/2-250,tray_size,tray_size))
view.add_subview(tray)
b=[[ui.Button(frame=(i*(square + grid) + 2*grid,j*(square + grid) + 2*grid, square, square)) for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(N):
b[j][i].loc=(i,j)
# value=random.randrange(6)
# b[j][i].title=str(value+1)
b[j][i].title=str([i]+[j])
b[j][i].bg_color='white'
b[j][i].line_width=1
b[j][i].tint_color='blue'
tray.add_subview(b[j][i])
b[j][i].corner_radius=5
view.present(hide_title_bar=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment