Exemplo n.º 1
0
Arquivo: sim.py Projeto: Crowbeak/LD25
def end_menu():
    """
    Displays console commands after the calculation phase of simulation
    is complete.
    """
    ddisplay.print_text(["\nCOMMAND   | EFFECT",
                        "----------|----------------------------------------------",
                        "RESTART   | Restart simulation.",
                        "DECOM     | Choose robots to decommission.\n"])
Exemplo n.º 2
0
Arquivo: sim.py Projeto: Crowbeak/LD25
def placement_cmd(workplaces):
    """
    Displays console commands during the robot placement phase of simulation.
    """
    ddisplay.print_text(["\nCOMMAND   | EFFECT",
                         "----------|-----------------------------------------------"])
    for workplace in workplaces:
        if workplace.cmd == "NONE":
            print "NONE [ID] | Return robot to unassigned robot pool"
        else:
            print "{} [ID] | Move robot with ID number [ID] to {}".format(workplace.cmd,
                                                                          workplace.name)
    ddisplay.print_text(["UPDATE    | Reprint robot lists",
                         "RUN       | Run simulation"])
Exemplo n.º 3
0
Arquivo: sim.py Projeto: Crowbeak/LD25
def print_key(sim_state):
    ddisplay.print_text(["\nSIMULATION: {} \n".format(sim_state.name),
                        "{}\n".format(sim_state.phase),
                        "\nKEY",
                        "----------",
                        "ID:   Robot's ID number",
                        "AGE:  Years robot has been in service",
                        "CARR: Tens of pounds robot can carry",
                        "BATT: Battery life of robot",
                        "UTIL: Rating of robot's ability to complete varied tasks",
                        "COST: Weekly costs of maintaining robot",
                        "BRKS: Number of times robot has broken down"])
    
    if sim_state.phase == 'SIMULATION RESULTS':
        ddisplay.print_text(["T.OUT: Robot's total output over simulated timeframe",
                            "A.OUT: Robot's average output per week over simulated timeframe"])
Exemplo n.º 4
0
def spanishInquisition():
    ddisplay.print_from_file("resources/story/si/si_intro.txt")
    
    choice = 0
    while (int(choice) != 1) and (int(choice) != 2):
        opts = ['\nWell, do you?',
                '1 - I still don\'t understand what I\'m supposed to have done.',
                '2 - Would it matter if I did?']
        ddisplay.print_text(opts)
        
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                pass
            elif int(choice) == 2:
                ddisplay.print_from_file("resources/story/si/si_no_change.txt")
            else:
                print '\n"Have you anything to say in your defense?" he asks again.'
        except ValueError:
            choice = 0
            print '\n"Have you anything to say in your defense?" he asks again.'
    
    ddisplay.print_from_file("resources/story/si/si_verdict.txt")
    raw_input('\n(Press enter key to continue)')
    ddisplay.print_from_file("resources/story/si/si_ending01.txt")
    raw_input('\n(Press enter key to continue)')
    ddisplay.print_from_file("resources/story/si/si_ending02.txt")
    raw_input('\n(Press enter key to continue)')
    ddisplay.print_from_file("resources/story/si/si_ending03.txt")
    
    choice = 0
    again = ['\n"What\'s that?" he asks. I can\'t hear you."',
             '\nHis subordinate snickers.']
    while (int(choice) != 1) and (int(choice) != 2):
        opts = ['1 - You\'re kidding, right? You can\'t be serious.',
                '2 - Say nothing.']
        ddisplay.print_text(opts)
        
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                ddisplay.print_from_file("resources/story/si/si_speech.txt")
            elif int(choice) == 2:
                ddisplay.print_from_file("resources/story/si/si_silence.txt")
            else:
                ddisplay.print_text(again)
        except ValueError:
            choice = 0
            ddisplay.print_text(again)
    
    ddisplay.print_from_file("resources/story/si/si_ending04.txt")
    raw_input('\n(Press enter key to continue)')
    ddisplay.print_from_file("resources/story/si/si_ending05.txt")
    
    raw_input('\n\nTHE END')
Exemplo n.º 5
0
Arquivo: sim.py Projeto: Crowbeak/LD25
def results(workplace, weeks):
    """
    Displays results of the calculation phase of simulation in table format for
    the Workplace instance given.
    """
    ddisplay.print_text(["\n{} ROBOTS".format(workplace.name),
                        "INDIVIDUAL OUTPUTS",
                        "  ID  AGE CARR BATT UTIL COST BRKS |    T.OUT  A.OUT",
                        "-----------------------------------|----------------"])
    for robot in workplace.robots:
        print repr(robot.id).rjust(4), repr(robot.age).rjust(4),
        print repr(robot.strength).rjust(4), repr(robot.battery).rjust(4),
        print repr(robot.utility).rjust(4), repr(robot.cost).rjust(4),
        print repr(robot.breakdowns).rjust(4), '|',
        print repr(robot.total_output).rjust(8),
        print repr(robot.total_output/weeks).rjust(6)
    
    ddisplay.print_text(["\nTOTAL {} OUTPUT: {}".format(workplace.name,
                                                       workplace.total_output()),
                        "\nAVERAGE WEEKLY OUTPUT PER ROBOT: {}".format(workplace.avg_output(weeks))])
Exemplo n.º 6
0
def intro():
    """
    The story introduction. Introduces Dave, has first story choice.
    
    Choices: 1
    Simulations: 0
    
    TODO: Have choice of asking about wife or not indicate interest or lack
          thereof in Dave's personal life. Eventually to impact ability to
          prevent Dave's suicide and its impact on the story.
    TODO: Make coffee intake a relevant stat somehow.
    """
    ddisplay.print_from_file("resources/story/intro/credits.txt")
    raw_input('\n(Press enter key to continue)')
    ddisplay.print_from_file("resources/story/intro/good_morning_dave.txt")
    choice = 0
    again = ['\nCome on, now. I know you haven\'t had your coffee yet, but surely you',
            'can find the 1 and 2 keys on your keyboard.']
    while (int(choice) != 1) and (int(choice) != 2):
        menu = ['\nWhat do you do?',
                '1 - Grunt, wave goodbye, and go to your cubicle.',
                '2 - Ask about his wife.']
        ddisplay.print_text(menu)
    
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                ddisplay.print_from_file("resources/story/intro/good_morning_dave_r1.txt")
            elif int(choice) == 2:
                ddisplay.print_from_file("resources/story/intro/good_morning_dave_r2.txt")
            else:
                ddisplay.print_text(again)
        except ValueError:
            choice = 0
            ddisplay.print_text(again)
Exemplo n.º 7
0
Arquivo: sim.py Projeto: Crowbeak/LD25
def calc_status(i, cycles):
    """
    Calls to print_text() inserted because calculation takes almost no time.
    """
    tenths = cycles/10
    
    if i == 0:
        ddisplay.print_text(["\n\nSIMULATING. PLEASE WAIT..."])
    elif i == (cycles-1):
        ddisplay.print_text(["SIMULATION COMPLETE.\n"])
    else:
        for j in xrange(1, 10):
            if i == tenths*j:
                ddisplay.print_text(["...{}0% complete".format(j)])
Exemplo n.º 8
0
def placement_phase(sim_state):
    sim.placement_display(sim_state)
    cmd_list = build_cmd_list(sim_state.workplaces)
    
    command = [None]
    while command[0] != 'RUN':
        sim.placement_cmd(sim_state.workplaces)
        input = raw_input("\nPlease choose an option from above:")
        command = input.upper().split()
        command.append(' ')
        
        if command[0] not in cmd_list:
            ddisplay.print_text(errorCMD)
        elif command[0] == 'UPDATE':
            sim.placement_display(sim_state)
        elif command[0] == 'RUN':
            break
        else:
            for workplace in sim_state.workplaces:
                if command[0] == workplace.cmd:
                    id = int(command[1])
                    old_home = workplace
                
                    found = False
                    while not found:
                        for other in sim_state.workplaces:
                            if other is workplace:
                                continue
                            else:
                                for robot in other.robots:
                                    if robot.id == id:
                                        old_home = other
                                        found = True
                                        break
                        #Robot not found anywhere; break loop w/o changing oldHome.
                        break
                    
                    if old_home == workplace:
                        ddisplay.print_text(errorCMD)
                    else:
                        move = old_home.removeRobot(id)
                        try:
                            workplace.add_robot(move)
                            print "\nSUCCESS. Robot #{} moved from {} to {}.".format(id,
                                                                                     old_home.name,
                                                                                     workplace.name)
                        except workclass.TooManyRobots:
                            old_home.add_robot(move)
                            ddisplay.print_text(errorMaxRobots)
Exemplo n.º 9
0
Arquivo: sim.py Projeto: Crowbeak/LD25
def placement_display(sim_state):
    """
    Prints console information during the robot placement phase of simulation.
    """
    print_key(sim_state)
    
    for workplace in sim_state.workplaces:
        ddisplay.print_text(["\n{} ROBOTS".format(workplace.name)])
    
        if workplace.max_robots == None:
            ddisplay.print_text(["NO MAXIMUM"])
        else:
            ddisplay.print_text(["MAX NUMBER OF ROBOTS: {}".format(workplace.max_robots)])
        
        ddisplay.print_text(["  ID  AGE CARR BATT UTIL COST BRKS",
                            "----------------------------------"])
    
        for robot in workplace.robots:
            #TODO: Clean this shit up. Check tutorial pg 54 (PDF).
            print repr(robot.id).rjust(4), repr(robot.age).rjust(4),
            print repr(robot.strength).rjust(4), repr(robot.battery).rjust(4),
            print repr(robot.utility).rjust(4), repr(robot.cost).rjust(4),
            print repr(robot.breakdowns).rjust(4)
Exemplo n.º 10
0
def results_phase(sim_state):
    sim_state.phase = 'SIMULATION RESULTS'
    sim.print_key(sim_state)
    for workplace in sim_state.workplaces:
        sim.results(workplace, sim_state.weeks)

    restart = True
    done_yet = False
    while not done_yet:
        sim.end_menu()
        input = raw_input("\nPlease choose an option from above:")
        command = input.upper().split()
        command.append(' ')
        
        if command[0] == 'RESTART':
            done_yet = True
        elif command[0] == 'DECOM':
            id_nums = []
            for workplace in sim_state.workplaces:
                for robot in workplace.robots:
                    id_nums.append(robot.id)
                
            for i in range(sim_state.robots_to_discard_num):
                extant = False
                while not extant:
                    input = raw_input("Enter ID of robot #{} to be decommissioned:".format(i+1))
                    try:
                        if int(input) in id_nums:
                            extant = True
                        else:
                            ddisplay.print_text(errorID)
                    except ValueError:
                        input = ' '
                        ddisplay.print_text(errorID)
            print '\nSIMULATION COMPLETE\n'
            restart = False
            done_yet = True
        else:
            ddisplay.print_text(errorCMD)
    
    return restart
Exemplo n.º 11
0
def ch01():
    intro = ['\nAfter logging in, you consider your options.',
             '\nWhat do you do?']
    ddisplay.print_text(intro)
    
    nosebook = False
    email = False
    again = ['\nNo, no, no, that\'s not a valid choice. Try again!']
    while True:
        menu = ['1 - See what\'s happening on Nosebook.',
                '2 - Check your email.',
                '3 - Do the work they\'re paying you to be here for.']
        ddisplay.print_text(menu)
        
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                if nosebook:
                    print '\nYeah... still a lot of nosebook-picking going on here.'
                else:
                    ddisplay.print_from_file("resources/story/ch01/ch01_nosebook.txt")
                    nosebook = True
            elif int(choice) == 2:
                if email:
                    print '\nNo new email. Alas.'
                else:
                    print '\nEarlobe enlargement? Wow, they\'ll try anything these days.'
                    email = True
            elif int(choice) == 3:
                ddisplay.print_from_file("resources/story/ch01/ch01_work.txt")
                while True:
                    menu = ['\nWhat do you do?',
                            '1 - Review the manual again to stave off the inevitable. [How to Play]',
                            '2 - Just do it.']
                    ddisplay.print_text(menu)
                    
                    choice = raw_input("Pick one:")
                    try:
                        if int(choice) == 1:
                            instructions()
                        elif int(choice) == 2:
                            workplacesToBe = []
                            workplacesToBe.append(workclass.WorkplaceToBe(7, True, workclass.Farm,
                                                                          "FARM #216", "A216"))
                            workplacesToBe.append(workclass.WorkplaceToBe(5, True, workclass.Factory,
                                                                          "FACTORY #139", "C139"))
                            workplacesToBe.append(workclass.WorkplaceToBe(2, False, workclass.Unassigned,
                                                                          "UNASSIGNED", "NONE"))
                            run_sim(workplacesToBe, 2, '#135466')
                            break
                        else:
                            print 'Try again, please. Invalid input.'
                    except ValueError:
                        choice = 0
                        print 'Try again, please. Invalid input.'
                break
            else:
                ddisplay.print_text(again)
        except ValueError:
            choice = 0
            ddisplay.print_text(again)
        
        print '\nWhat do you do next?'

    lunch = ['You yawn and stretch. Coffee time is past. It\'s snack time now.',
             '\nWhoops!',
             '\nApparently you meant lunch time.']
    ddisplay.print_text(lunch)
    
    choice = 0
    again = ['\nYou... wait, what?! Try that again.']
    while (int(choice) != 1) and (int(choice) != 2):
        chc1 = ['\nWhere do you want to go?',
                '1 - The good old cafeteria. Mediocre free food, decent conversation.',
                '2 - Home. Sandwiches and solitude.']
        ddisplay.print_text(chc1)
        
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                ddisplay.print_from_file("resources/story/ch01/ch01_cafeteria.txt")
            elif int(choice) == 2:
                ddisplay.print_from_file("resources/story/ch01/ch01_home.txt")
            else:
                ddisplay.print_text(again)
        except ValueError:
            choice = 0
            ddisplay.print_text(again)
        
        raw_input('\n(Press enter key to continue)')
Exemplo n.º 12
0
def ch03(dave):
    if dave:
        ddisplay.print_from_file("resources/story/ch03/ch03_dave_intro.txt")
        print('\nWhat do you do?')
        time.sleep(0.2)
    
        #Goof off or work.
        nosebook = False
        email = False
        while True:
            opts = ['1 - Pick your Nosebook.',
                    '2 - Check your eternally uninteresting email.',
                    '3 - Slave away.']
            ddisplay.print_text(opts)
        
            choice = raw_input("Pick one:")
            try:
                if int(choice) == 1:
                    if nosebook:
                        print '\nOh, why bother.'
                    else:
                        ddisplay.print_from_file("resources/story/ch03/ch03_nosebook.txt")
                        nosebook = True
                elif int(choice) == 2:
                    if email:
                        print '\nNo new email. Again.'
                    else:
                        print '\nNothing.'
                        email = True
                elif int(choice) == 3:
                    #Tries to work.
                    ddisplay.print_from_file("resources/story/ch03/ch03_work.txt")
                    raw_input('\n(Press enter key to continue)')
                    break
                else:
                    print '\nJust put in a correct input so you can get this done and go home.'
            except ValueError:
                choice = 0
                print '\nJust put in a correct input so you can get this done and go home.'
        
            print '\nWhat do you do next?'
    else:
        ddisplay.print_from_file("resources/story/ch03/ch03_nodave_intro.txt")
        
        choice = 0
        while (int(choice) != 1) and (int(choice) != 2):
            opts = ['\nWill you eat with Biggs and Wedge today?',
                    '1 - Yeah.',
                    '2 - No.']
            ddisplay.print_text(opts)
        
            choice = raw_input("Pick one:")
            try:
                if int(choice) == 1:
                    ddisplay.print_from_file("resources/story/ch03/ch03_yes.txt")
                    raw_input('\n(Press enter key to continue)')
                elif int(choice) == 2:
                    ddisplay.print_from_file("resources/story/ch03/ch03_no.txt")
                    raw_input('\n(Press enter key to continue)')
                else:
                    print '\nSimple question. He\'s just asking.'
            except ValueError:
                choice = 0
                print '\nSimple question. He\'s just asking.'
Exemplo n.º 13
0
def ch02():
    """
    Returns True if Dave is still in player's life at end of module or False
    otherwise.
    """
    ddisplay.print_from_file("resources/story/ch02/ch02_intro.txt")
    
    choice = 0
    while (int(choice) != 1) and (int(choice) != 2):
        opts = ['\n1 - Yeah... that\'s so out of character I can only assume aliens',
                '    are involved.',
                '2 - Nah. Dave\'s a great guy but it\'s nice not to have to deal',
                '    with his peppy peppiness sometimes.']
        ddisplay.print_text(opts)
        
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                dave = True
                ddisplay.print_from_file("resources/story/ch02/ch02_look.txt")
            elif int(choice) == 2:
                dave = False
                print '\nYou sip your coffee obtained in quiet and log in.'
            else:
                print '\nDrink some of your coffee and try that again.'
        except ValueError:
            choice = 0
            print '\nDrink some of your coffee and try that again.'
    
    intro = ['Confronted with the usual options...',
             '\nWhat do you do?']
    ddisplay.print_text(intro)
    
    #Goof off or work.
    nosebook = False
    email = False
    while True:
        opts = ['1 - See what\'s happening on Nosebook.',
                '2 - Check your email.']
        if dave:
            opts.append('3 - Work. Maybe it\'ll take your mind off things.')
        else:
            opts.append('3 - Do the work they\'re paying you to be here for.')
        ddisplay.print_text(opts)
        
        choice = raw_input("Pick one:")
        try:
            if int(choice) == 1:
                if nosebook:
                    if dave:
                        noseSeen = ['\nEven scoffing at the nosebook-picking can\'t cheer you up.',
                                    'The term "nosebook-picking" isn\'t even funny right now.']
                    else:
                        noseSeen = ['\nMore nosebook-picking. Ah, nosebook-picking.',
                                    'Just the term makes you happy. How do you visualize that?']
                    ddisplay.print_text(noseSeen)
                else:
                    ddisplay.print_from_file("resources/story/ch02/ch02_nosebook.txt")
                    if dave:
                        print('\nThis isn\'t helping.')
                    else:
                        print('\nYou should probably work. Probably.')
                    nosebook = True
            elif int(choice) == 2:
                if email:
                    if dave:
                        print('\nNo new email. Not that you did a good job reading the first two.')
                    else:
                        print('\nNo new email. Who\'s surprised?')
                else:
                    newEmail = ['\nSomething from Biggs about a party... don\'t care right now.',
                                'And... news. Noone cares about that.']
                    ddisplay.print_text(newEmail)
                    email = True
            elif int(choice) == 3:
                #Working.
                while True:
                    opts = ['\nWhat do you do?',
                            '1 - Review the manual again.']
                    if dave:
                        opts.append('2 - Work. Or try to.')
                    else:
                        opts.append('2 - Work! It\'s like a crummy party you get paid to attend.')
                    ddisplay.print_text(opts)
                    
                    choice = raw_input("Pick one:")
                    try:
                        if int(choice) == 1:
                            instructions()
                        elif int(choice) == 2:
                            workplacesToBe = []
                            workplacesToBe.append(workclass.WorkplaceToBe(7, True, workclass.Farm,
                                                                          "FARM #512", "A512"))
                            workplacesToBe.append(workclass.WorkplaceToBe(5, True, workclass.Factory,
                                                                          "FACTORY #110", "C110"))
                            workplacesToBe.append(workclass.WorkplaceToBe(6, True, workclass.Factory,
                                                                          "FACTORY #112", "C112"))
                            workplacesToBe.append(workclass.WorkplaceToBe(4, False, workclass.Unassigned,
                                                                          "UNASSIGNED", "NONE"))
                            run_sim(workplacesToBe, 4, '#187949')
                            break
                        else:
                            print 'Try again, please. Invalid input.'
                    except ValueError:
                        choice = 0
                        print 'Try again, please. Invalid input.'
                break
            else:
                if dave:
                    print('\nI know you\'re distracted, but please use proper input.')
                else:
                    print('Have a sip of carefree coffee and try again.')
        except ValueError:
            choice = 0
            if dave:
                print('\nI know you\'re distracted, but please use proper input.')
            else:
                print('Have a sip of carefree coffee and try again.')
        
        print '\nWhat do you do next?'
    
    if dave:
        print('\nLunch time. You still haven\'t heard from Dave. Time to go check on him.')
    else:
        ddisplay.print_from_file("resources/story/ch02/ch02_worked.txt")
    
    raw_input('\n(Press enter key to continue)')
    return dave