Ejemplo n.º 1
0
def deleteSave(savelist, fromSaveError=False):
    _invalid = ''
    while True:
        _1, _2, _3 = savelist[:3]
        clearScreen()
        print(display['deletesave'].format(_1, _2, _3) + _invalid)
        _invalid = ''

        choice = userInput()
        if choice not in '123b':
            _invalid = '\n    [ Please choose valid option ]\n'
        elif choice == 'b':
            break
        elif int(choice) > len(savelist) - 3:
            _invalid = '\n    [ This save file is empty ]\n'
        else:
            clearScreen()
            print(display['confirm'].format('DELETE'))
            while True:
                confirm = userInput()
                if confirm == 'n':
                    break
                elif confirm == 'y':
                    deleteFile(
                        os.path.join(scriptDirPath, 'saves',
                                     savelist[int(choice) - 1]))
                    savelist.pop(int(choice) - 1)
                    if fromSaveError: return
                    break

    return savelist
Ejemplo n.º 2
0
def newGame():
    global saveFile
    savefiles = glob.glob(os.path.join(scriptDirPath, 'saves', '*'))
    saves = [os.path.basename(file) for file in savefiles]
    saves.extend(['-EMPTY-', '-EMPTY-', '-EMPTY-'])

    clearScreen()
    print(display['newgame']['name'], end='')
    name = input()

    if len(savefiles) == 3:
        clearScreen()
        print(display['newgame']['saveerror'])
        while True:
            choice = userInput()
            if choice == 'y':
                deleteSave(saves, True)
                break
            elif choice == 'n':
                return 'back'

    clearScreen()
    print(display['newgame']['tutorial'].format(name))
    while True:
        choice = userInput()
        if choice == 'y':
            tutorial()
            break
        elif choice == 'n':
            break

    saveFile = os.path.join(scriptDirPath, 'saves', name)
    open(saveFile, 'x').close()
    return 'play'
Ejemplo n.º 3
0
def loadGame():
    global saveFile
    _invalid = ''
    savefiles = glob.glob(os.path.join(scriptDirPath, 'saves', '*'))
    saves = [os.path.basename(file) for file in savefiles]
    saves.extend(['-EMPTY-', '-EMPTY-', '-EMPTY-'])

    while True:
        _1, _2, _3 = saves[:3]
        clearScreen()
        print(display['loadgame'].format(_1, _2, _3) + _invalid)
        _invalid = ''

        choice = userInput()
        if choice not in '123db':
            _invalid = '\n    [ Please choose valid option ]\n'
        elif choice == 'd':
            saves = deleteSave(saves)
        elif choice == 'b':
            return 'back'
        elif int(choice) > len(savefiles):
            _invalid = '\n    [ This save file is empty ]\n'
        else:
            saveFile = savefiles[int(choice) - 1]
            return 'play'
Ejemplo n.º 4
0
def quitGame():
    clearScreen()
    print(display['confirm'].format('QUIT'))

    if userInput() == 'y':
        return 'quit'
    else:
        return 'back'
Ejemplo n.º 5
0
def mainMenu() :
    print(display['title'])
    while True :
        if userInput() == 's' : break

    _invalid = ''
    while True :
        clearScreen()
        print(display['mainmenu'] + _invalid)
        _invalid = ''

        choice = userInput()
        if choice not in 'nldq' :
            _invalid = '\n    [ Please choose valid option ]\n'
            continue
        result = menuOptions[choice]()
        if result == 'quit' :
            clearScreen(); return False
        elif result == 'play' :
            return True
        elif result == 'back' :
            continue
Ejemplo n.º 6
0
def tutorial():
    tutplayer = Player('Tutorial')
    tutmap = Map(tut=True)
    tutplayer.linkMap(tutmap)
    while True:
        clearScreen()
        tutmap.update()
        choice = userInput()
        if choice == 'q':
            break
        elif choice in 'wasd':
            tutplayer.move(choice)

    del tutmap, tutplayer
Ejemplo n.º 7
0
def difficultyLevel():
    global difficulty
    _invalid = ''
    indicator = [
        ['>', ' '],  # easy
        [' ', '>']
    ]  # hard

    while True:
        clearScreen()
        print(display['difficultylevel'].format(
            indicator[0][difficulty], indicator[1][difficulty]) + _invalid)

        choice = userInput()
        if choice == 'e':
            difficulty = 0
        elif choice == 'h':
            difficulty = 1
        elif choice == 'b':
            return 'back'
        else:
            _invalid = '\n    [ Please choose valid option ]\n'