示例#1
0
def main():
    logging.info('Entering main function')
    global g_map
    # load game map
    with open("game.xml") as f:
        xml_file = f.read()
    success, g_map = game.obj_wrapper(xml_file) #turn into python object via Q2API
    if not success:
        logging.warning('obj_wrapper failed in main() before stops')
        print "no object"
        exit()
    # construct global dicts: stops
    global stops # possible positions
    for stop in g_map.stop:
        nomen = stop.attrs["nomen"]
        stops[nomen] = stop

    stop = g_map.stop[0] #inital stop
    # initialize player
    global player
    player = g_map.player[0]
    # initialize extras - list of printable items
    global extras
    extras = ['stop_desc','stop_name','sound']
    logging.info('Entering main() game loop')
    os.system('cls')
    # enter main game loop
    while True:
        describe(stop, extras)
        command = raw_input(">")
        os.system('cls') #clearing for better user experience
        #put directly after command so we can print on either side and it looks cohesive.
        stop = process_command(stop, command)
        logging.info('Command Processed')
        logging.info(str(type(stop))) #make sure that we're passing in variable into loop!
示例#2
0
def load_game(game_file):
    '''
    Input: game_file from load command()
    Output: stop object from player profile.

    '''
    logging.info('Found load_game')
    with open(game_file) as f:
        xml_file = f.read()
    #wrap player map here
    success, p_map = game.obj_wrapper(xml_file)
    if not success:
        logging.info('From Q2API - Obj_wrapper failed when loading game')
        exit()
    global player #only need player from file
    global stops #grab dict from main file so that we can call current stop from nomen attribute

    player = p_map.player[0] #assign player via Q2API.xml.mk_class syntax
    nomen = player.attrs["stop"] #grab stop from player's xml file and return for game play
    stop = stops[nomen]

    for itm in player.item: #constructs finds dict from loaded player.
        if itm.attrs["finds"]=='true':

            boss_kw = itm.attrs["boss_kw"]
            logging.info('User has item:'+boss_kw)
            ats = str(itm.value).split(',')[0].strip() #returns ats from unicode
            rhymes = str(itm.value).split(',')[1].strip() #returns rhymes from unicode
            finds[boss_kw] = ats,rhymes
        else:
            logging.info('No item found')
    logging.info('Leaving load_game')
    return stop
示例#3
0
def load_game(game_file):
    '''
    this function opens a player that has a saved game
    '''
    logging.info('Found load_game')
    with open(game_file) as f:
        xml_file = f.read()
    #call player map here because we are not altering most of the file.
    success, p_map = game.obj_wrapper(xml_file)
    if not success:
        logging.warning('From Q2API - Obj_wrapper failed when loading game')
        exit()
    global player #only need player from file
    global stops #grab dict from main file so that we can call current stop from nomen attribute

    player = p_map.player[0] #assign player via Q2API.xml.mk_class syntax
    nomen = player.attrs["stop"] #grab stop from player's xml file and return for game play
    stop = stops[nomen]

    for itm in player.item: #constructs finds dict from loaded player.
        if itm.attrs["finds"]=='true':

            boss_kw = itm.attrs["boss_kw"]
            logging.info('User has item:'+boss_kw)
            ats = str(itm.value).split(',')[0].strip() #returns ats from unicode
            hashes = str(itm.value).split(',')[1].strip() #returns hashes from unicode
            finds[boss_kw] = ats,hashes
        else:
            logging.info('No item found')
    logging.info('Leaving load_game')
    return stop
示例#4
0
def load_game(game_file):
    '''
    this function opens a player that has a saved game
    '''
    with open(game_file) as f:
        xml_file = f.read()
    #call player map here because we are not altering most of the file.
    success, p_map = game.obj_wrapper(xml_file)
    if not success:
        print "Failure to wrap object."
        exit()
    global player #only need player from file
    global stops #grab dict from main file so that we can call current stop from nomen attribute

    player = p_map.player[0] #assign player via Q2API.xml.mk_class syntax
    nomen = player.attrs["stop"] #grab stop from player's xml file and return for game play
    stop = stops[nomen]

    for itm in player.item: #constructs finds dict from loaded player.
        if itm.attrs["finds"]=='true':
            boss_kw = itm.attrs["boss_kw"]
            ats = str(itm.value).split(',')[0].strip() #returns ats from unicode
            hashes = str(itm.value).split(',')[1].strip() #returns hashes from unicode
            finds[boss_kw] = ats,hashes
    return stop
示例#5
0
def main():
    global g_map
    # load game map
    with open("..//levels//game.xml") as f:
        xml_file = f.read()
    success, g_map = game.obj_wrapper(xml_file) #turn into python object via Q2API
    if not success:
        print "Failure to wrap object. Try running mk_class again."
        exit()
    # construct global dicts: stops, battles and
    global stops
    for stop in g_map.stop:
        nomen = stop.attrs["nomen"]
        stops[nomen] = stop
    global battles
    for scenario in g_map.scenario: # load scenarios in to dict with ats, hashes
        ats = scenario.attrs['ats']
        hashes = scenario.attrs['hashes']
        battles[(ats,hashes)] = scenario
    # initalize player
    global player
    player = g_map.player[0]

    # give initial stop
    stop = g_map.stop[0]

    # enter game loop
    while True:
        describe(stop)
        command = raw_input(">")
        stop = process_command(stop, command)
示例#6
0
def main():
    # load game map
    with open("game.xml") as f:
        xml_file = f.read()

    success, g_map = game.obj_wrapper(xml_file)

    # construct rooms dict
    global stops
    for stop in g_map.stop:
        nomen = stop.attrs["nomen"]
        stops[nomen] = stop

    # initialize game
    global player
    player = g_map.player[0]

    # print intro
    intro = g_map.intro[0]
    print intro.desc[0].value

    print image_to_ascii(intro) # prints intro image

    stop = g_map.stop[0] # give initial stop

    # enter game loop
    while True:
        store_twitter = []

        describe(stop)


        if stop.attrs["nomen"]== "endgame": # use nomen here
            exit()
        # #start twitter game here
        # call_prompt = raw_input("What's your call against this mean muggin?!")
        #
        # hash_diff, at_diff = battle(stop.attrs["nomen"],call_prompt)
        # #return tuple of diff of ats and hashes
        # #currently battle function doesn't have unique call for each exit,item or stop specific keyword
        #
        #
        # if hash_diff <0 or at_diff<0: #breaks if either returns zero
        #     print "You're as dead as a doornail."
        #     exit()
        #
        # store_twitter.append(hash_diff,at_diff)
        # # call_difference
        # # a.)grabs the noun as the keyword in twitter for the move/item of the spot
        # #       -if the move/item does not have a keyword, return the same values for the player
        # # b.)grab the keyword

        command = raw_input(">")
        stop = process_command(stop, command)
示例#7
0
def load_ats_hashes(game_file):
    global ats
    global hashes
    with open('../save/'+game_file) as f:
        xml_file = f.read()

    success, p_map = game.obj_wrapper(xml_file)
    #call player map here because we are not altering most of the file.
    if not success:
        print "Failure to wrap object."
        exit()
    global player #only need player from file
    player = p_map.player[0]
    ats = player.attrs["ats"] #grab stop from player's xml file and return for game play
    hashes = player.attrs["hashes"]
    return ats,hashes
示例#8
0
def load_ats_rhymes(game_file):
    '''
    Loads ats and rhymes from player given profile.

    '''
    logging.info('Found load_ats_rhymes')
    with open('save/'+game_file) as f:
        xml_file = f.read()

    success, p_map = game.obj_wrapper(xml_file)
    #call player map here because we are not altering most of the file.
    if not success:
        print "Failure to wrap object."
        exit()
    #only need player from file
    player = p_map.player[0]
    ats = player.attrs["ats"] #grab stop from player's xml file and return for game play
    rhymes = player.attrs["rhymes"]
    logging.info('Leaving load_ats_rhymes')
    return ats,rhymes
示例#9
0
def load_items(game_file):
    '''
    load items and names in list
    '''
    logging.info('Found load_ats_rhymes')
    with open('save/'+game_file) as f:
        xml_file = f.read()

    success, p_map = game.obj_wrapper(xml_file)
    #call player map here because we are not altering most of the file.
    if not success:
        print "Failure to wrap object."
        exit()
    #only need player from file
    player = p_map.player[0]
    item_list=[]
    for it in player.item:
        item_list.append(it.attrs["nomen"])

    logging.info('Leaving load_items')
    return item_list
示例#10
0
def main():
    logging.info('entering main loop')
    global g_map
    # load game map
    with open("game.xml") as f:
        xml_file = f.read()
    success, g_map = game.obj_wrapper(xml_file) #turn into python object via Q2API
    if not success:
        logging.warning('obj_wrapper failed in main() before stops')
        exit()
    # construct global dicts: stops and battles
    global stops # possible positions
    for stop in g_map.stop:
        nomen = stop.attrs["nomen"]
        stops[nomen] = stop
    # battles is a dict of twitter battle result descriptions
    global battles
    for scenario in g_map.scenario: # load scenarios into dict with ats, hashes
        ats = scenario.attrs['ats']
        hashes = scenario.attrs['hashes']
        battles[(ats,hashes)] = scenario

    # initalize player
    global player
    player = g_map.player[0]

    # give initial stop
    stop = g_map.stop[0]
    logging.info('Entering main() game loop')

    # enter game loop
    while True:
        describe(stop)
        command = raw_input(">")
        stop = process_command(stop, command)
        logging.info('Command Processed')
        logging.info(str(type(stop))) #make sure that we're passing in variable into loop!
示例#11
0
def load_game(game_file):
    '''
    Input: game_file from load command()
    Output: stop object from player profile.

    '''
    global g_map
    logging.info('Found load_game')
    with open(game_file) as f:
        xml_file = f.read()
    #wrap player map here
    success, g_map = game.obj_wrapper(xml_file)
    if not success:
        logging.info('From Q2API - Obj_wrapper failed when loading game')
        exit()
    global player #only need player from file
    global stops #grab dict from main file so that we can call current stop from nomen attribute

    player = g_map.player[0] #assign player via Q2API.xml.mk_class syntax
    nomen = player.attrs["stop"] #grab stop from player's xml file and return for game play
    stop = stops[nomen]

    logging.info('Leaving load_game')
    return stop