Example #1
0
def add_score(score):
    """
    Prompts the user to input their name, and appends the created Score object
    to its proper position in the scorelist.
    Returns None if the user decided not to save their score,
    or otherwise the scorelist.
    """
    pyconio.clrscr()
    if save_topscore() == "continue":
        draw.logo()
        pyconio.gotoxy(13, 22)
        pyconio.normalmode()
        pyconio.write("Add meg a neved (ne használj ':'-ot):", end="\n")
        draw.cursor(True)
        pyconio.flush()
        name = input("                         ")
        while ":" in name:
            pyconio.write("Hibás név, kérlek add meg ':' nélkül.", end="\n")
            name = input("                         ")
        draw.cursor(False)
        pyconio.rawmode()
        scorelist = get_scores()
        if scorelist is not None:
            scorelist.append(Score(name, score))
            scorelist.sort(key=int, reverse=True)
            if len(scorelist) > 5:
                scorelist.pop(-1)
        elif scorelist == -1:
            pyconio.gotoxy(15, 26)
            pyconio.write("Hibás file, ellenőrizd a pontszámokat!")
        else:
            scorelist = [Score(name, score)]
        return scorelist
    else:
        return None
Example #2
0
def pause():
    """
    Ingame pause menu.
    """
    pyconio.clrscr()
    buttons = [
        Button("Játék folytatása", "continue"),
        Button("Mentés", "save"),
        Button("Kilépés a főmenübe", "quit")
    ]
    return menu(buttons)
Example #3
0
def save_menu():
    """
    Menu after save, asking the user to either continue or quit the game.
    """
    pyconio.clrscr()
    pyconio.gotoxy(10, 18)
    pyconio.write("Sikeres mentés, folytatod a játékot?", flush=True)
    buttons = [
        Button("Játék folytatása", "continue"),
        Button("Kilépés a főmenübe", "quit")
    ]
    return menu(buttons)
Example #4
0
def main_menu(settings=None):
    """
    Main menu with the listed buttons, and saved settings, optionally.
    """
    pyconio.clrscr()
    buttons = [
        Button("Játék indítása", "start"),
        Button("Dicsőséglista", "toplist"),
        Button("Beállítások", "options"),
        Button("Betöltés", "load"),
        Button("Kilépés", "quit")
    ]
    if settings is not None:
        return menu(buttons, settings)
    else:
        return menu(buttons)
Example #5
0
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)
Example #6
0
def options(pos, settings=None):
    """
    Options menu with the listed buttons, creating an Options object that
    stores the current settings. If settings are changed,
    those are then passed to the other menus, to make use of them when needed.
    """
    pyconio.clrscr()
    pyconio.gotoxy(pos[0], pos[1])
    buttons = [Button("Pálya mérete", "size"), Button("Kezdő szint", "level")]
    if settings is None:
        settings = Options()
    choice = menu(buttons, settings)
    if choice is not None:
        (selected, set_value) = choice
    else:
        return main_menu(settings)
    if selected == "size":
        settings.size = set_value
    elif selected == "level":
        settings.level = set_value
    pyconio.rawmode()
    return options((20, 20), settings)
Example #7
0
def select(func, data=None):
    """
    List of available functions in the menus. In some cases the menu outputs
    are handled locally, when that is needed for the functionality.
    (When working with local variables that are not available
    in this module.)
    """
    pyconio.clrscr()
    # Used in main menu
    if func == "start":
        if data is not None:
            return ("new", data.size, data.level)
        else:
            return ("new", 20, 1)
        pyconio.clrscr()
    elif func == "toplist":
        return list_scores(get_scores(), (20, 20), data)
    elif func == "options":
        return options((20, 20), data)
    elif func == "load":
        return ("load", 20, 1)
        pyconio.clrscr()
    # Common quit mechanism
    elif func == "quit":
        pyconio.textbackground(pyconio.RESET)
        pyconio.textcolor(pyconio.RESET)
        pyconio.clrscr()
        return None
    # Options menu
    elif func == "size":
        return (func, setting_adjust(data.size, "Méret", 20, 50, 2))
    elif func == "level":
        return (func, setting_adjust(data.level, "Kezdő szint", 1, 10))
    # Pause, save, topscore save menu
    else:
        return func
Example #8
0
def mainloop(tetro, field, next, points=0, level=1):
    """
    Prints the field and the currently active tetromino to its given position.
    While ingame, you can control it with UP-DOWN-LEFT-RIGHT as in Tetris.
    Pause the loop with the ESC key, if you choose continue, the current loop
    ends, and is called again with the current parameters.
    """
    game_sec = time.time()
    draw.screen(tetro, field, next, points, level)
    ingame = (True, 0)

    with pyconio.rawkeys():
        while ingame[0]:
            current_sec = time.time()
            # Control mechanism
            if pyconio.kbhit():
                ingame = control.ingame(tetro, field)
                points += ingame[1] * level
                draw.screen(tetro, field, next, points, level)
            # Fall mechanism
            if round(current_sec, min(level, 2)) >= round(
                    game_sec, min(level, 2)):
                if control.move_valid(control.post_move(tetro, "down"), field):
                    if control.hit(control.post_move(tetro, "down"), field):
                        if tetro.pos[1] >= 1:
                            last = tetro
                            next.pos = [5, 0]
                            tetro = next
                            next = control.store_regen(last, field, next)
                        # Game over if tetro hits another one, while Y pos is <1
                        else:
                            ingame = (False, points)
                            pyconio.clrscr()
                            draw.logo("game_over.txt")
                            time.sleep(1)
                            # Add to top scores if needed
                            scores = menu.get_scores()
                            # If highscores.txt exists, is valid and not empty
                            if scores not in (None, -1, []):
                                if points > scores[-1].points:
                                    scorechoice = menu.add_score(points)
                                    if scorechoice is not None:
                                        menu.write_score(scorechoice)
                            # If invalid
                            elif scores == -1:
                                pyconio.gotoxy(12, 25)
                                pyconio.write("Hibás dicsőséglista!", end="\n")
                                pyconio.gotoxy(8, 26)
                                pyconio.write("Ellenőrizd a highscores.txt-t!")
                                pyconio.flush()
                                time.sleep(2.5)
                            # If doesn't exist yet or empty
                            else:
                                scorechoice = menu.add_score(points)
                                if scorechoice is not None:
                                    menu.write_score(scorechoice)
                            return main()
                    else:
                        tetro.pos[1] += 1
                # When hit, save tetro and generate new one.
                else:
                    last = tetro
                    next.pos = [len(field) // 4, 0]
                    tetro = next
                    next = control.store_regen(last, field, next)
                # Game ticks
                game_sec += control.speed_sec(level)
                draw.screen(tetro, field, next, points, level)
            # Line clear
            if control.line_full(field):
                points += control.delete_full(field) * level
                draw.screen(tetro, field, next, points, level)
            # Level up
            if points >= level**2 * 1000:
                level += 1
                draw.screen(tetro, field, next, points, level)
        # Pause
        pausechoice = menu.pause()
        if pausechoice == "save":
            control.save_game(tetro, field, next, points, level)
            pausechoice = menu.save_menu()
        if pausechoice == "continue":
            return mainloop(tetro, field, next, points, level)
        elif pausechoice is None:
            return main()
Example #9
0
import pyconio
import time

# Init
pyconio.settitle("pyconio test")

# Positioning
pyconio.clrscr()
pyconio.gotoxy(0, 0)
pyconio.textcolor(pyconio.LIGHTGREEN)
pyconio.write("Hello")
pyconio.gotoxy(10, 0)
pyconio.textbackground(pyconio.LIGHTBLUE)
pyconio.write("world!")
print()

# Printing color codes
print(pyconio.backgroundcolors[pyconio.RESET], end="")
print("{}Hello {}world!".format(pyconio.textcolors[pyconio.RED], pyconio.textcolors[pyconio.GREEN]))

# Color combinations
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