Esempio n. 1
0
def End(MAPS, PLAYER, ITEMS, INTERACT, QUESTS, ENEMIES, GAMEINFO, GAMESETTINGS):
    # # Anywhere where a loadgame happens you need all the global variables
    # global PLAYER  # The main character. player is an object instance of class character.
    # global ITEMS  # All the items. This a dictionary of objects of class equipment keyed by their lowcase equipment name (item.name). Remember the lowercase, may trip you up if referencing upercase version in the file.
    # global MAPS  # All the locations. A tuple of objects of class Map inxed by there x,y,z coordinate (MAPS[x][y][z])
    # global INTERACT  # All the interactables (stationary things that need something). This a dictionary of objects of class Interact keyed by their lowcase name (interact.name). Remember the lowercase, may trip you up if referencing upercase version in the file.
    # global QUESTS  # Quest statuses. This is a dictionary of flags (1 or 0) for the status of the quest keyed by quest name.
    # global ENEMIES  # All the npcs. This a dictionary of objects of class Enemy keyed by their lowcase equipment name (item.name.lower()). Remember the lowercase, may trip you up if referencing upercase version in the file.
    # global GAMEINFO  # Miscellaneous game info. Dictionary of all sorts of variables
    # global GAMESETTINGS  # The game settings that are saved in the game

    save_game(GAMEINFO['playername'])  # saves all data RIGHT away so they can't restart when they die

    GAMEINFO['runtime'] = GAMEINFO['runtime'] + (time.time()-GAMEINFO['timestart']) #calculates total time you've been playing by adding your loaded runtime to your instance runtime (end time - start time)
    GAMEINFO['log'] = GAMEINFO['log'] + ["--END OF LOG--", "Stepcount: "+str(GAMEINFO['stepcount']), "Command Count: " + str(GAMEINFO['commandcount']),
      "Run Time: " + str(GAMEINFO['runtime']), "--Character STATS--",str((PLAYER.location[0],PLAYER.location[1],PLAYER.location[2], PLAYER.location[3])),
      str((PLAYER.stats[0],PLAYER.stats[1],PLAYER.stats[2])),str(PLAYER.health),"HEAD: " + str(PLAYER.inv["head"].name),
      "BODY: " + str(PLAYER.inv["body"].name), "HAND: " + str(PLAYER.inv["hand"].name), "OFF-HAND: " + str(PLAYER.inv["off-hand"].name)
        ] #adds the final info to the log leger

    if GAMEINFO['winner']== 0:  # player died and that's how they're out of the loop
        print(LINEBREAK)
        if GAMESETTINGS['SpeedRun']: DisplayTime(GAMEINFO['runtime'])  # displays the runtime for speed running
        if GAMESETTINGS['SpeedRun']: printT("Total Step Count: "+ str(GAMEINFO['stepcount']) + " (\S)Total Command Count: " + str(GAMEINFO['commandcount']))
        logGame(GAMEINFO['log']) # writes the log file
        printT("Thanks for playing!! Better luck next time! (\S)")#lets the player restart the game
    else:
        input("You've " +wincolour+"won"+textcolour+"! Type anything to continue\n").lower()  # If they beat either of the storylines
        GAMEINFO['log'].append("---THEY WON---") #appends they won at the end of the log file to make it easier find
        if GAMEINFO['winner'] == 1: #The bad storyline ending
            printT("After performing the purge of the faculty you join Dr.Cassidy in shaping the New Order.\nAs Dr.Cassidy's apprentice, you reign over McMaster University with an iron fist.\nEngineering Physics is established as the premium field of study and all funding is directed to you.\nYou unlock secrets of untold power which allow you to reinforce your overwhelming grasp on the university.\nYour deeds have given you complete power and you reign supreme for eternity.\nTHE END  (\S)")
            GAMEINFO['winner'] = 1
        elif GAMEINFO['winner'] == 2: #The good storyline ending.
            printT("Having defeated Dr. Cassidy you proved yourself to be a truly honourable engineer.\nWith the forces of evil defeated, McMaster University will continue to operate in peace.\nAll faculties exist in harmony and the integrity of the institution has been preserved.\nYou go on to lead a successful life as an engineer satisfied that you chose what was right.\nTHE END. (\S)")
            GAMEINFO['winner'] = 2
        elif GAMEINFO['winner'] == 3: #The good storyline ending.
            printT("After defeating both Dr. Cassidy and Sir William McMaster you take a moment to think while the deed to McMaster University lies at your feet fluttering slowly in a gentle breeze. You think about what you were told. Does that piece of paper really give you immense power and control over the school? After a quick smirk and a laugh, you pick up the deed and begin to rip it up. The parchment resists for a moment before giving way in a spectacular display of sparks and disappearing into the wind. You go on knowing that the fate of the University now resides in the hands of no one... it resides in everyone's hands. (\S)THE END  (\S)")
            QUESTS['neutral balance'] = 0
            GAMEINFO['winner'] = 3
        if GAMESETTINGS['SpeedRun']: DisplayTime(GAMEINFO['runtime']) #displays the runtime then all other status
        if GAMESETTINGS['SpeedRun']:printT("Total Step Count: "+ str(GAMEINFO['stepcount']) + " (\S)Total Command Count: " + str(GAMEINFO['commandcount']))
        logGame(GAMEINFO['log']) #logs the data to be submitted
        save_game(GAMEINFO['playername'] + " Winner") #saves all data to later be submited, different from the main save file
        Opening.Closing()  # plays the closing
        printT("Thanks for playing!!! (\S)")
    endchoice = ""
    while not endchoice:  # death or ending selection screen
        printT(" (\S)Continue Playing[C]   Restart Game[R]  Exit[E]")
        #printT(" (\S)Continue Playing[C]   Restart Game[R]  Main Menu Return[M]  Exit[E]")
        endchoice = input("Choose what you want to do: ").lower().strip() #this input is to hold the screen until the player decides what to do
        if (GAMEINFO['winner'] == 0) and (endchoice in ["c","continue playing","continue","play"]):
            printT("You can't continue because you're dead!")
            endchoice = ""
        #elif endchoice not in ["c", "r", "m", "e", "continue playing", "continue", "play", "restart game", "restart","main menu return", "main menu", "menu return", "main", "menu", "return", "exit"]:
        elif endchoice not in ["c","r","m","e","continue playing","continue","play","restart game","restart","exit"]:
            printT(""+losecolour+"Please choice a valid option!"+textcolour+"")
            endchoice = ""
    if endchoice in ["c","continue playing","continue","play"]:
        PLAYER.alive = True
        print(LINEBREAK)
        QUESTS['restored order'] = 0  # turn this off so you can continue playing the game without the quest redoing
        QUESTS['create chaos'] = 0
        Main(MAPS, PLAYER, ITEMS, INTERACT, QUESTS, ENEMIES, GAMEINFO, GAMESETTINGS)  # returns to the main (hopefully in the same state)
    elif endchoice in ["r","restart game","restart"]:
        MAPS, PLAYER, ITEMS, INTERACT, QUESTS, ENEMIES, GAMEINFO, GAMESETTINGS = load_game("basegame") #loads in the savefile global variables
        GAMEINFO['timestart'] = time.time() #reset local variable starttime to current time
        Main(MAPS, PLAYER, ITEMS, INTERACT, QUESTS, ENEMIES, GAMEINFO, GAMESETTINGS) #re-enters the main loop
    # No return to main menu implemented due to bad looping structure
    # elif endchoice in ["m","main menu return","main menu","menu return","main","menu","return"]:
    #     Opening.StartScreen()  # Startscreen loop where you can play new game, loadgame, choose settings, or exit
    #     Setup()
    #     Main()
    elif endchoice in ["e","exit"]:
        if input("\n\nAre you sure you want to " +losecolour+ "quit" +textcolour+ " the game?\nType Y if you wish to save and leave,\nanythine else to continue: \n").lower() in ["y", 'yes', 'yeah']:
            GAMEINFO['runtime'] += (time.time() - GAMEINFO['timestart'])  # adds the runtime (initilized to zero) to the session runtime to make the total runtime
            GAMEINFO['timestart'] = time.time()  # resets timestart so it's not doubly added at the end
            logGame(GAMEINFO['log'])  # logs the game when you save it
            save_game(GAMEINFO['playername'])  # saves all data
            # print "Your game has been saved! " + GAMEINFO['playername']  # Don't indicate the save file has save file in the name
            AsciiArt.ThanksForPlaying()
            input("" +indicatecolour+ "We're sad to see you go :(" +textcolour+ " \nI hope whatever you're doing is more fun.\nPress anything to leave")
            exit()
    return MAPS, PLAYER, ITEMS, INTERACT, QUESTS, ENEMIES, GAMEINFO, GAMESETTINGS