Ejemplo n.º 1
0
def interact(game):
    # interaction entre l'utilisateur et le menu
    menu = Game.getMenu(game)
    win = Game.getWin(game)
    # deplacement du curseur
    menu['selectedItem'] = -1
    key = win.getch()
    if key == ord('z'):
        if menu['cursor'] != 0:
            menu['cursor'] -= 1
    if key == ord('s'):
        if menu['cursor'] != len(menu['items']) - 1:
            menu['cursor'] += 1
    if key == ord('e'):
        menu['selectedItem'] = menu['cursor']
    # action a effectuer en fonction de l'item selectionne
    if menu['selectedItem'] == 0:
        game = Game.setName(Game.askName(game), game)
    if menu['selectedItem'] == 1:
        game = Game.setDifficulty(Game.askDifficulty(game), game)
    if menu['selectedItem'] == 2:
        newLevel = Level.create(Level.askLevelNumber(game), 'levels.txt')
        logging.info("nouveau niveau : " + str(newLevel))
        game = Game.setLevel(newLevel, game)
    if menu['selectedItem'] == 3:
        HighScores.show(HighScores.get(), win)
    if menu['selectedItem'] == 4:
        Game.setState('game', game)
    if menu['selectedItem'] == 5:
        Game.setState('quitProgram', game)
    return
Ejemplo n.º 2
0
def show(game):
    # affiche le menu
    menu = Game.getMenu(game)
    win = Game.getWin(game)
    win.erase()
    for i in range(len(menu['items'])):
        if i == menu['cursor']:
            win.addstr(10 + i, 20, "->" + str(menu['items'][i]))
        else:
            win.addstr(10 + i, 22, str(menu['items'][i]))
    win.addstr(2, 2, 'Name : ' + str(Game.getName(game)))
    win.addstr(3, 2, 'Difficulty : ' + str(Game.getDifficulty(game)))
    win.addstr(4, 2, 'Level : ' +
               str(Level.getLevelNumber(Game.getLevel(game))))
    return
Ejemplo n.º 3
0
def askLevelNumber(game):
    # demande le numero du niveau a l'utilsateur
    win = Game.getWin(game)
    level = Game.getLevel(game)
    win.nodelay(0)
    win.erase()
    curses.echo()
    levelNumber = 0
    while levelNumber < 1 or levelNumber > len(level['allLevels']):
        max = str(len(level['allLevels']))
        win.addstr(10, 20, "Choose your level [ 1 - " + max + " ]")
        win.addstr(12, 20, "            ")
        try:
            levelNumber = int(win.getstr(11, 20))
            if levelNumber < 1 or levelNumber > len(level['allLevels']):
                raise ValueError()
        except ValueError:
            win.erase()
            win.addstr(12, 20, "retry !")
    curses.noecho()
    return levelNumber