def test_grid_color(self): b = Board(4, 9) _value = "magenta" b.grid_color = _value self.assertEqual(b.grid_color, _value) b._setupUI() self.assertEqual(b.grid_color, _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.grid_color, _value)
def grid_color_test(): b = Board(4, 9) _value = "magenta" b.grid_color = _value assert b.grid_color == _value b._setupUI() assert b.grid_color == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.grid_color == _value
if field[r][c] is None: # It must be an empty place field[r][c] = "fruit" break def setup(): global snake, lastkey w2 = FIELD_WIDTH // 2 # field center h2 = FIELD_HEIGHT // 2 field.fill(None) snake = [(h2, w2), (h2, w2 + 1)] # Initial snake position for pos in snake: field[pos[0]][pos[1]] = 'body' # Draw the snake fruit_random_position() lastkey = "Left" # starts moving to the left field.start_timer(300) # 300 ms field = Board(FIELD_HEIGHT, FIELD_WIDTH) field.cell_size = BLOCK_SIZE field.title = "Snake game" field.cursor = None # Hide the cursor field.margin = 10 field.grid_color = "dark sea green" field.margin_color = "dark sea green" field.cell_color = "PaleGreen4" field.on_key_press = kbd_fn field.on_timer = timer_fn setup() field.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()
from game2dboard import Board b = Board(8, 8) b.title = "Playground!" b.margin = 0 b.cell_spacing = 1 b.cell_size = 80 b.margin_color = None b.grid_color = "red" b.cell_color = "green" # b.background_image = "chess" b.create_output(color='gray20', background_color='AntiqueWhite3', font_size=10) b.show()
else: field.close() lastkey = "" def start(): global player, Diff if Diff == "": Diff = pymsgbox.confirm( "Controls:\n Left-Right-Up-Down arrows - to move\n M - return to choosing difficulty\nChoose your difficult", "Difficult", ['Easy', 'Normal', 'Hard']) field.fill(None) walls() wc = m // 2 hc = n // 2 field[hc][wc] = "Player" player = [(hc, wc)] lastkey = "" field.start_timer(300) field = Board(FIELD_HEIGHT, FIELD_WIDTH) field.cell_size = BLOCK_SIZE field.title = "Labirint" field.grid_color = "DarkGray" field.cell_color = "DarkGray" field.on_key_press = keysPress field.on_timer = move start() field.show()