コード例 #1
0
ファイル: main.py プロジェクト: ArDrift/Tetris
def game_init(mode, fieldsize, level):
    """
    Initialize the game depending on the given mode, either from scratch,
    or by loading an existing saved state.
    This handles non-existing save files too.
    """
    if mode == "new":
        field = control.make_field(fieldsize)
        next = control.make_random([fieldsize * 2, 0])
        mainloop(control.make_random([fieldsize // 4, 0]), field, next, 0,
                 level)
    elif mode == "load":
        loaded = control.load_game("save.txt")
        if loaded is not None:
            (field, shape, pos, next, points, level) = loaded
        else:
            pyconio.gotoxy(5, 20)
            pyconio.write("Nem található mentés, biztosan mentettél már?")
            pyconio.gotoxy(20, 29)
            pyconio.write("Vissza: ESC")
            key = pyconio.getch()
            while key != pyconio.ESCAPE:
                key = pyconio.getch()
            return main()
        fieldsize = len(field)
        tetro = draw.Tetromino(shape, pos[0], pos[1])
        next = draw.Tetromino(next, fieldsize * 2, 0)
        mainloop(tetro, field, next, points, level)
コード例 #2
0
ファイル: menu.py プロジェクト: ArDrift/Tetris
def setting_adjust(setting, label, min_val, max_val, delta=1):
    """
    Used in the options menu, lets the user change the default options
    with the UP and DOWN keys. The actual setting, its label,
    value interval (and granularity) should be given as parameters.
    """
    draw.logo()
    pyconio.textbackground(pyconio.RESET)
    pyconio.textcolor(pyconio.RESET)
    pyconio.gotoxy(20, 20)
    pyconio.write("{}: {:3}".format(label, setting), flush=True)
    pyconio.gotoxy(15, 29)
    pyconio.write("Irányítás: ↑ ↓ ENTER ESC")
    initial = setting
    pyconio.rawmode()
    key = pyconio.getch()
    while key != pyconio.ENTER:
        if key == pyconio.UP:
            if setting < max_val:
                setting += delta
        elif key == pyconio.DOWN:
            if setting > min_val:
                setting -= delta
        elif key == pyconio.ESCAPE:
            setting = initial
            break
        pyconio.gotoxy(20, 20)
        pyconio.write("{}: {:3}".format(label, setting), flush=True)
        key = pyconio.getch()
    return setting
コード例 #3
0
ファイル: menu.py プロジェクト: ArDrift/Tetris
def list_scores(scorelist, pos, data=None):
    """
    Lists the scores from the given scorelist to the given position.
    Adds numbering and colors (for the top 3) to the list elements,
    and prints out the proper errors when needed. Returns to the main menu,
    with optional data if passed.
    """
    pyconio.clrscr()
    draw.logo()
    pyconio.gotoxy(pos[0], pos[1])
    pyconio.textcolor(pyconio.RESET)
    if scorelist is None:
        pyconio.gotoxy(pos[0] - 15, pos[1])
        pyconio.write("A file nem található, biztosan játszottál már?")
    elif scorelist == -1:
        pyconio.gotoxy(pos[0] - 10, pos[1])
        pyconio.write("Hibás file, ellenőrizd a pontszámokat!")
    else:
        for i in range(len(scorelist)):
            if i + 1 == 1:
                pyconio.textcolor(pyconio.YELLOW)
            elif i + 1 == 2:
                pyconio.textcolor(pyconio.LIGHTGRAY)
            elif i + 1 == 3:
                pyconio.textcolor(pyconio.BROWN)
            else:
                pyconio.textcolor(pyconio.RESET)
            pyconio.gotoxy(pos[0], pos[1] + i)
            pyconio.write("{}. {}".format(i + 1, scorelist[i]))

    pyconio.gotoxy(pos[0] + 2, pos[1] + pos[1] // 2)
    pyconio.textcolor(pyconio.RESET)
    pyconio.write("Vissza: ESC")
    pyconio.flush()
    pyconio.rawmode()
    key = pyconio.getch()
    while key != pyconio.ESCAPE:
        key = pyconio.getch()
    pyconio.clrscr()
    return main_menu(data)
コード例 #4
0
ファイル: menu.py プロジェクト: ArDrift/Tetris
def menu(buttons, data=None):
    """
    Common menu mechanism, including the indication of the selected button
    and navigation. Returns None if the user selected quit
    (either by pressing ESC or selecting the option),
    or executes the selected function otherwise, with optional data.
    """
    pyconio.textcolor(pyconio.WHITE)
    buttons[0].active = True
    draw.logo()
    while True:
        for btn in buttons:
            if btn.active:
                pyconio.textbackground(pyconio.WHITE)
                pyconio.textcolor(pyconio.BLACK)
            else:
                pyconio.textbackground(pyconio.RESET)
                pyconio.textcolor(pyconio.RESET)
            pyconio.gotoxy(20, 20 + buttons.index(btn))
            pyconio.write(btn)

            pyconio.gotoxy(15, 29)
            pyconio.textcolor(pyconio.RESET)
            pyconio.textbackground(pyconio.RESET)
            pyconio.write("Irányítás: ↑ ↓ ENTER ESC")
        pyconio.flush()

        pyconio.rawmode()
        key = pyconio.getch()
        active = buttons.index([x for x in buttons if x.active][0])
        if key == pyconio.ENTER:
            return select(buttons[active].function, data)
        elif key == pyconio.DOWN:
            buttons[active].active = False
            if active == len(buttons) - 1:
                buttons[0].active = True
            else:
                buttons[active + 1].active = True
        elif key == pyconio.UP:
            buttons[active].active = False
            if active == 0:
                buttons[-1].active = True
            else:
                buttons[active - 1].active = True
        elif key == pyconio.ESCAPE:
            return select("quit")
コード例 #5
0
for b in range(0, 16):
    pyconio.gotoxy(5, 5+b)
    for t in range(0, 16):
        pyconio.textcolor(t)
        pyconio.textbackground(b)
        pyconio.write(" X ")
    pyconio.write("\n")
print()

# Raw input
pyconio.textbackground(pyconio.RESET)
pyconio.textcolor(pyconio.RESET)
print("Raw input test, press keys and then Enter:")
pyconio.rawmode()
while True:
    ch = pyconio.getch()
    if ch == pyconio.ENTER:
        break
    print(ch, end=" ")
print()
pyconio.normalmode()

# Raw input buffering
print("Raw input buffering test, 3s delay, press any keys")
pyconio.rawmode()
time.sleep(3)
if not pyconio.kbhit():
    print("No keys pressed.")
else:
    while pyconio.kbhit():
        print(pyconio.getch(), end=" ")
コード例 #6
0
ファイル: test2.py プロジェクト: czirkoszoltan/pyconio
import pyconio

pyconio.clrscr()
print("Use cursor keys to control the asterisk")

x = 40
y = 12
pyconio.rawmode()
while True:
    pyconio.gotoxy(x, y)
    pyconio.textcolor(pyconio.LIGHTGREEN)
    pyconio.write("*")
    pyconio.gotoxy(80, 24)

    key = pyconio.getch()
    pyconio.gotoxy(x, y)
    pyconio.textcolor(pyconio.BLUE)
    pyconio.write(".")

    if key == pyconio.UP:
        y = max(y - 1, 1)
    elif key == pyconio.DOWN:
        y = min(y + 1, 23)
    elif key == pyconio.LEFT:
        x = max(x - 1, 0)
    elif key == pyconio.RIGHT:
        x = min(x + 1, 79)
    elif key == pyconio.ESCAPE:
        break
pyconio.normalmode()