Exemple #1
0
def checkwin(board, passcount):
    c = [0, 0, 0]
    for y in range(8):
        for x in range(8):
            c[board[y * 8 + x]] += 1
    if c[0] == 0 or c[1] == 0 or c[2] == 0 or passcount >= 2:
        winner = 0
        if c[1] >= c[2]:
            winner |= 1
        if c[2] >= c[1]:
            winner |= 2
        while ls.keys():
            ls.tick(0.1)
        while not ls.keys():
            for y in range(8):
                for x in range(8):
                    p = lookup(board, x, y)
                    if p & winner:
                        r = random.getrandbits(3)
                        if y == 7 or lookup(board, x, y + 1) != p:
                            if r & 3 == 0:
                                p = 3
                        else:
                            if r & 6:
                                p = screen.pixel(x, y + 1)
                            elif r & 1:
                                p = 3
                    screen.pixel(x, y, p)
            show(screen)
            ls.tick(0.06)
        raise ls.GameOver()
Exemple #2
0
def keyevents():
    global keyhistory
    keys = ls.keys()
    events = keys & (~keyhistory | (keyhistory & (keyhistory >> 8) &
                                    (keyhistory >> 16) & (keyhistory >> 24)))
    keyhistory = ((keyhistory & 0x3FFFFF) << 8) | keys
    return events
def move_player(data):
    x1player, y1player = data['player']['position'][0]
    x2player, y2player = data['player']['position'][1]

    keys = ls.keys()

    if keys & ls.K_LEFT and x1player > 0:
        x1player -= 1
        x2player -= 1
    elif keys & ls.K_RIGHT and x2player < 7:
        x1player += 1
        x2player += 1

    data['player']['position'] = [(x1player, y1player), (x2player, y2player)]
    return data
Exemple #4
0
    (1, 1, 1, 1, 1, 1, 1, 1),
))

blink = 1
dead = False
for y in range(8):
    for x in range(8):
        if screen.pixel(x, y) == 4:
            break;
    else:
        continue
    break

while not dead:
    screen.pixel(x, y, VOID)
    pressed = ls.keys()
    dx = 0
    dy = 0
    if pressed & ls.K_UP:
        dy = -1
    elif pressed & ls.K_DOWN:
        dy = 1
    elif pressed & ls.K_LEFT:
        dx = -1
    elif pressed & ls.K_RIGHT:
        dx = 1
    if screen.pixel(x + dx, y + dy) not in {WALL, ROCK}:
        x += dx
        y += dy
    elif screen.pixel(x + dx, y + dy) == ROCK and dy == 0:
        if screen.pixel(x + dx + dx, y + dy + dy) == VOID:
Exemple #5
0
    snake = [(ls.GREEN, ls.BLUE)]
    dx, dy = 1, 0
    apple_x, apple_y = 6, 4
    screen.pixel(apple_x, apple_y, ls.RED)

    while True:
        if len(snake) > 1:
            x, y = snake[-2]
            screen.pixel(x, y, 1)
        x, y = snake[-1]
        screen.pixel(x, y, 3)

        ls.show(screen)
        ls.tick(1 / game_speed)

        keys = ls.keys()
        if keys & ls.K_UP and dy == 0:
            dx, dy = 0, -1
        elif keys & ls.K_LEFT and dx == 0:
            dx, dy = -1, 0
        elif keys & ls.K_RIGHT and dx == 0:
            dx, dy = 1, 0
        elif keys & ls.K_DOWN and dy == 0:
            dx, dy = 0, 1
        x = (x + dx) % 8
        y = (y + dy) % 8

        if (x, y) in snake:
            break
        snake.append((x, y))
Exemple #6
0
def debounce():
    for i in range(100):
        ls.tick(1 / 100)
        if not ls.keys():
            return