示例#1
0
 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)
示例#2
0
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
示例#3
0
        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()