Exemplo n.º 1
0
def runGame(surface, fpsclock, data) :
    if not hasattr(data.user, 'init') :
        charector_select_scene.show(surface, fpsclock, data)

    w = surface.get_width()
    h = surface.get_height()
    dRect = Rect(0, 0, int(w/2), int(h/2))
    dRect.center = (int(w/2), int(h/2))

    record(data)
    record(data.user)

    while True:
        status = map_scene.show(surface, fpsclock, data)
        if status is map_scene.SELECT_FINISH :
            s = data.map.selected_item
            if s is None:
                # game may be over but how could it be?
                break

            assert (s.type in [T_EVENT, T_STORE, T_BATTLE]), "unexpected map_item type meet: %s" % s.type
            if s.type == T_EVENT:
                nop = 1
            elif s.type == T_STORE:
                store_scene.show(surface, fpsclock, data)
            elif s.type == T_BATTLE:
                nop = 1
        elif status is map_scene.DONE:
            print('game is over~')
            return

        if s and s.type == T_STORE:
            data.map.current_item = data.map.selected_item

    print("game_scene is done\n")
Exemplo n.º 2
0
def put(user_input,connectionSocket):
	# TODO: need to check to make sure there aren't too many args
	global database
	global lock
	global serverdb

	lock.acquire()
		#add the new record to the database if it exists
		#check arguments
		#if(len(user_input) > 4):
		#	connectionSocket.send("\n121: Input Error - Too many arguemnts. The put command takes three arguments: NAME, VALUE, and TYPE.")
		#	return;
	try:
		updated = 0
		new_record = record(user_input[2],user_input[3])


		#if user input has name and type already in the database, the entry will be updated
		if(search(user_input[2]) >= 0):
			database[search(user_input[2])] = new_record
			updated = 1
		#else the new record will be added
		else:
			database.append(new_record)

		f = open(serverdb,'w+')
		pickle.dump(database,f)
		f.close()

		if(updated == 1):
			connectionSocket.send("607 PUP " + user_input[2])
		else:
			connectionSocket.send("606 PIN " + user_input[2])


	#accounts for improper input of user commands for put i.e not enough commands provided. 
	#The user will be prompted to re enter a command on the client side.
	except IndexError:
		connectionSocket.send("121 ERR - Too few arguments. The put command takes three arguments: NAME, VALUE, and TYPE. Please re-enter the message in the proper format")
	
	lock.release()
Exemplo n.º 3
0
def put(user_input, connectionSocket):
    # TODO: need to check to make sure there aren't too many args
    global database
    global lock
    global serverdb

    lock.acquire()
    #add the new record to the database if it exists
    #check arguments
    #if(len(user_input) > 4):
    #	connectionSocket.send("\n121: Input Error - Too many arguemnts. The put command takes three arguments: NAME, VALUE, and TYPE.")
    #	return;
    try:
        updated = 0
        new_record = record(user_input[2], user_input[3])

        #if user input has name and type already in the database, the entry will be updated
        if (search(user_input[2]) >= 0):
            database[search(user_input[2])] = new_record
            updated = 1
        #else the new record will be added
        else:
            database.append(new_record)

        f = open(serverdb, 'w+')
        pickle.dump(database, f)
        f.close()

        if (updated == 1):
            connectionSocket.send("607 PUP " + user_input[2])
        else:
            connectionSocket.send("606 PIN " + user_input[2])

    #accounts for improper input of user commands for put i.e not enough commands provided.
    #The user will be prompted to re enter a command on the client side.
    except IndexError:
        connectionSocket.send(
            "121 ERR - Too few arguments. The put command takes three arguments: NAME, VALUE, and TYPE. Please re-enter the message in the proper format"
        )

    lock.release()
Exemplo n.º 4
0
 def setUp(self):
     record = Record.define('Ham', ('ham', 'spam', 'eggs'))
     self.ham = record(ham=1, spam=2, eggs=3)
Exemplo n.º 5
0
 def setUp(self):
     record = Record.define('Foo', ('foo', 'bar', 'baz'))
     self.foo = record(foo=1, bar=2, baz=3)
Exemplo n.º 6
0
def getUserInput(decoder, log_file):
    """ Uses autorecord and saves message.
        Then the decoder turns this message into a string.
        Then, we recognize the concepts and return a dictionary.
    """

    now = datetime.datetime.now().isoformat()

    log_directory_path = os.path.dirname(log_file.name)
    input_wav_path = log_directory_path + "/" + now + "_input.wav"

    record(thresh=250, verbose=True, path=input_wav_path)
    
    # Run the Recognizer
    fh = file(input_wav_path, 'rb')
    decoder.decode_raw(fh)
    result = decoder.get_hyp()[0]
    fh.close()
    
    print("result:")
    print(result)
    
    # write the result to the log
    log_file.write("User: "******" <" + now + "_input.wav>\n")

    if result == None:
        message = "Sorry, I didn't understand"
        speakMessage(message, log_file)
        # query again
        return getUserInput(decoder, log_file)

    concept_table = createConceptTable(result)
    
    # for text input
    #user_input = str(raw_input("User input: "))
    #user_input = user_input.upper()
    # strip punctuation (only necessary with typed input)
    #exclude = set(string.punctuation)
    #user_input = ''.join(ch for ch in user_input if ch not in exclude)
    #concept_table = createConceptTable(user_input)

    # create the concept dictionary
    concept_dict = {"Color": concept_table[0],
                    "Attribute": concept_table[1],
                    "Degree": concept_table[2],
                    "Direction": concept_table[3],
                    "Output Format": concept_table[4],
                    "Help": concept_table[5],
                    "Start Over": concept_table[6],
                    "Exit": concept_table[7],
                    "Undo": concept_table[8],
                    "Positive": concept_table[9],
                    "Negative": concept_table[10]}
    #print(concept_dict)
    
    # write the concept table to the log
    log_file.write("RECOGNIZED as:\n")
    for x in concept_dict.keys():
        if concept_dict[x] != None:
            log_file.write("\t'" + x + "': " + concept_dict[x] + "\n")

    log_file.write("\n")
    
    if all(val == None for val in concept_dict.values()):
        message = "Sorry, I didn't understand"
        speakMessage(message, log_file)
        # query again
        return getUserInput(decoder, log_file)
        
    return concept_dict
Exemplo n.º 7
0
 def setUp(self):
   record = Record.define('Ham', ('ham', 'spam', 'eggs'))
   self.ham = record(ham=1, spam=2, eggs=3)
Exemplo n.º 8
0
 def setUp(self):
   record = Record.define('Foo', ('foo', 'bar', 'baz'))
   self.foo = record(foo=1, bar=2, baz=3)
Exemplo n.º 9
0
def getUserInput(decoder, log_file):
    """ Uses autorecord and saves message.
        Then the decoder turns this message into a string.
        Then, we recognize the concepts and return a dictionary.
    """

    now = datetime.datetime.now().isoformat()

    log_directory_path = os.path.dirname(log_file.name)
    input_wav_path = log_directory_path + "/" + now + "_input.wav"

    record(thresh=250, verbose=True, path=input_wav_path)

    # Run the Recognizer
    fh = file(input_wav_path, 'rb')
    decoder.decode_raw(fh)
    result = decoder.get_hyp()[0]
    fh.close()

    print("result:")
    print(result)

    # write the result to the log
    log_file.write("User: "******" <" + now + "_input.wav>\n")

    if result == None:
        message = "Sorry, I didn't understand"
        speakMessage(message, log_file)
        # query again
        return getUserInput(decoder, log_file)

    concept_table = createConceptTable(result)

    # for text input
    #user_input = str(raw_input("User input: "))
    #user_input = user_input.upper()
    # strip punctuation (only necessary with typed input)
    #exclude = set(string.punctuation)
    #user_input = ''.join(ch for ch in user_input if ch not in exclude)
    #concept_table = createConceptTable(user_input)

    # create the concept dictionary
    concept_dict = {
        "Color": concept_table[0],
        "Attribute": concept_table[1],
        "Degree": concept_table[2],
        "Direction": concept_table[3],
        "Output Format": concept_table[4],
        "Help": concept_table[5],
        "Start Over": concept_table[6],
        "Exit": concept_table[7],
        "Undo": concept_table[8],
        "Positive": concept_table[9],
        "Negative": concept_table[10]
    }
    #print(concept_dict)

    # write the concept table to the log
    log_file.write("RECOGNIZED as:\n")
    for x in concept_dict.keys():
        if concept_dict[x] != None:
            log_file.write("\t'" + x + "': " + concept_dict[x] + "\n")

    log_file.write("\n")

    if all(val == None for val in concept_dict.values()):
        message = "Sorry, I didn't understand"
        speakMessage(message, log_file)
        # query again
        return getUserInput(decoder, log_file)

    return concept_dict