def test_cell_size(self): b = Board(4, 9) _value = (34, 55) b.cell_size = _value self.assertEqual(b.cell_size[0], _value[0]) self.assertEqual(b.cell_size[1], _value[1]) b._setupUI() self.assertEqual(b.cell_size[0], _value[0]) self.assertEqual(b.cell_size[1], _value[1]) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.cell_size[0], _value[0]) self.assertEqual(b.cell_size[1], _value[1]) b2 = Board(42, 99) _value = 1 b2.cell_size = _value self.assertEqual(b2.cell_size[0], _value) self.assertEqual(b2.cell_size[1], _value) b2._setupUI() self.assertEqual(b2.cell_size[0], _value) self.assertEqual(b2.cell_size[1], _value) b2.on_timer = lambda: b.close() b2.start_timer(TIME_TO_CLOSE) b2.show() self.assertEqual(b2.cell_size[0], _value) self.assertEqual(b2.cell_size[1], _value)
def cell_size_test(): b = Board(4, 9) _value = (34, 55) b.cell_size = _value assert b.cell_size[0] == _value[0] assert b.cell_size[1] == _value[1] b._setupUI() assert b.cell_size[0] == _value[0] assert b.cell_size[1] == _value[1] b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.cell_size[0] == _value[0] assert b.cell_size[1] == _value[1] b2 = Board(42, 99) _value = 1 b2.cell_size = _value assert b2.cell_size[0] == _value assert b2.cell_size[1] == _value b2._setupUI() assert b2.cell_size[0] == _value assert b2.cell_size[1] == _value b2.on_timer = lambda: b.close() b2.start_timer(TIME_TO_CLOSE) b2.show() assert b2.cell_size[0] == _value assert b2.cell_size[1] == _value
def test_cell_color(self): b = Board(4, 9) _value = "#000fff000" b.cell_color = _value self.assertEqual(b.cell_color, _value) b._setupUI() self.assertEqual(b.cell_color, _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.cell_color, _value)
def margin_color_test(): b = Board(10, 10) _value = "dark gray" b.margin_color = _value assert b.margin_color == _value b._setupUI() assert b.margin_color == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.margin_color == _value
def cell_spacing_test(): b = Board(1, 1) _value = 7 b.cell_spacing = _value assert b.cell_spacing == _value b._setupUI() assert b.cell_spacing == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.cell_spacing == _value
def margin_test(): b = Board(7, 1) _value = 19 b.margin = _value assert b.margin == _value b._setupUI() assert b.margin == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.margin == _value
def cursor_test(): b = Board(1, 20) _value = "watch" b.cursor = _value assert b.cursor == _value b._setupUI() assert b.cursor == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.cursor == _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
def cell_color_test(): b = Board(4, 9) _value = "#000fff000" b.cell_color = _value assert b.cell_color == _value b._setupUI() assert b.cell_color == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.cell_color == _value
def test_margin_color(self): b = Board(10, 10) _value = "dark gray" b.margin_color = _value self.assertEqual(b.margin_color, _value) b._setupUI() self.assertEqual(b.margin_color, _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.margin_color, _value)
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 test_cell_spacing(self): b = Board(1, 1) _value = 7 b.cell_spacing = _value self.assertEqual(b.cell_spacing, _value) b._setupUI() self.assertEqual(b.cell_spacing, _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.cell_spacing, _value)
def test_margin(self): b = Board(7, 1) _value = 19 b.margin = _value self.assertEqual(b.margin, _value) b._setupUI() self.assertEqual(b.margin, _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.margin, _value)
def test_cursor(self): b = Board(1, 20) _value = "watch" b.cursor = _value self.assertEqual(b.cursor, _value) b._setupUI() self.assertEqual(b.cursor, _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.cursor, _value)
def test_title(self): b = Board(2, 2) _value = "qwertyu 213213 dsdadasd~...." b.title = _value self.assertEqual(b.title, _value) b._setupUI() self.assertEqual(b.title, _value) self.assertEqual(b._root.title(), _value) b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() self.assertEqual(b.title, _value) self.assertEqual(b._root.title(), _value)
def title_test(): b = Board(2, 2) _value = "qwertyu 213213 dsdadasd~...." b.title = _value assert b.title == _value b._setupUI() assert b.title == _value assert b._root.title() == _value b.on_timer = lambda: b.close() b.start_timer(TIME_TO_CLOSE) b.show() assert b.title == _value assert b._root.title() == _value
b[row][col] = IMGID if not b[row][col] else None elif btn == 3: b[row][col] = "fruit.png" def timerfn(): b.print(datetime.datetime.now().strftime("[H]: Help %H:%M:%S")) def startfn(): b[0][0] = 12 b[0][1] = "Hello" b[0][2] = b[4][1] = IMGID b[3][6] = "fruit.png" b = Board(5, 15) b.title = "Hello, World!" b.margin = 10 b.cell_spacing = 6 b.cell_size = (50, 40) b.margin_color = b.grid_color = "AntiqueWhite4" b.cell_color = "AntiqueWhite1" b.on_start = startfn b.on_key_press = kbdfn b.on_mouse_click = mousefn b.on_timer = timerfn b.start_timer(1000) b.create_output(color='gray20', background_color='AntiqueWhite3', font_size=10) b.show()
c = random.randint(0, FIELD_WIDTH - 1) # Random collumn 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 = field.cell_spacing = 1 field.grid_color = field.margin_color = "dark sea green" field.cell_color = "PaleGreen4" field.on_key_press = kbd_fn field.on_timer = timer_fn setup() field.show()
def fntimer(): b.shuffle() b.start_timer(500) b = Board(3, 12) b[1][0] = 'H' b[1][1] = 'e' b[1][2] = 'l' b[1][3] = 'l' b[1][4] = 'o' b[1][5] = 'comma' b[1][6] = 'W' b[1][7] = 'o' b[1][8] = 'r' b[1][9] = 'l' b[1][10] = 'd' b[1][11] = 'excl' b.cell_size = (80, 100) b.title = "WTF????" b.margin = 10 b.cell_spacing = 3 b.grid_color = b.margin_color = "AntiqueWhite3" b.cell_color = "gray20" b.start_timer(2000) b.on_timer = fntimer 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()