previous_row = r # Save last position previous_col = c def newgame(): global previous_row, previous_col, reversed_cards, match_count, attempts_count previous_row = previous_col = reversed_cards = match_count = attempts_count = 0 game[0][0] = game[0][1] = 1 game[0][2] = game[0][3] = 2 game[1][0] = game[1][1] = 3 game[1][2] = game[1][3] = 4 game[2][0] = game[2][1] = 5 game[2][2] = game[2][3] = 6 game[3][0] = game[3][1] = 7 game[3][2] = game[3][3] = 8 game.shuffle() game.print(MSG) game = Board(4, 4) game.cell_size = 130 game.margin_color = game.grid_color = "wheat1" game.cell_color = "wheat3" game.cell_spacing = 2 game.title = "Memory Game" game.create_output(background_color="wheat4", color="white") game.on_mouse_click = fnmouse game.on_key_press = fnkbd game.on_start = newgame game.show()
from game2dboard import Board def mouse_fn(btn, row, col): # mouse calback function b[row][col] = 1 if not b[row][col] else 0 b = Board(3, 4) # 3 rows, 4 columns, filled w/ None b[0][0] = 0 b.title = "Click me!" b.cell_size = 120 b.cell_color = "honeydew" b.on_mouse_click = mouse_fn b.show()
from game2dboard import Board b = Board(8, 8) b.title = "Playground!" b.margin = 21 b.cell_size = 74 b.cell_spacing = 1 b.background_image = "chess" b.create_output(color='gray20', background_color='AntiqueWhite3', font_size=10) b.on_mouse_click = lambda btn, r, c : b.print("Clicked on [{}][{}]".format(r, c)) b.print("Click me") b.show()
from game2dboard import Board b = Board(2, 2) b[0][0] = 5 b[1][1] = 10 print(b) a = b.copy() print(a) b.title = "Hi!" b.grid_color = None b.on_mouse_click = lambda b, r, c: print(type(b), type(r), type(c)) b.show()