Created
November 14, 2015 16:35
-
-
Save SpaceVoyager/1c7ed026233937657160 to your computer and use it in GitHub Desktop.
eight_puzzle_v0.1.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ui | |
pieces = [1, 2, 3, 4, 5, 6, 7, 8, 0] | |
v = ui.View(background_color=(0.50, 0.50, 0.50)) | |
board = ui.View() | |
v.add_subview(board) | |
v.present('full_screen') | |
board.frame = ((v.width-v.height)/2, 0, v.height, v.height) | |
board.border_width = 3 | |
board.border_color = (0.00, 0.00, 0.50) | |
# convert index of button to row number and column number | |
def index2loc(index): | |
row = index / 3 | |
column = index % 3 | |
return (row, column) | |
# convert number in the pieces list into button text | |
def number2button_text(num): | |
if num == 0: | |
return '' | |
else: | |
return str(num) | |
for i in range(9): | |
button_text = number2button_text((pieces[i])) | |
button = ui.Button(title=button_text) | |
button.background_color = (1,1,1) | |
button.font = ('Futura-CondensedExtraBold', 200) | |
button.width = v.height/3 | |
button.height = button.width | |
button.border_width = 1 | |
(r, c) = index2loc(i) | |
print r, c | |
button.x = button.width*c | |
button.y = button.height*r | |
board.add_subview(button) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment