示例#1
0
def shoe_listener(request):
    x = request['x']
    y = request['y']
    state = request['state']
    if state == 'left-check':
        client.speak('left')
        client.left(20)
    elif state == 'right-check':
        client.speak('right')
        client.right(20)
    client.get_shoe(shoe_listener)
示例#2
0
def getting_face(faces):
    """start app and recognize player."""
    keys = faces.keys()
    if len(keys) != 0:
        player['name'] = faces[keys[0]]['name']
        client.speak('"Hi"')
        time.sleep(0.5)
        client.speak(player['name'])
        time.sleep(1)
        status['name'] = 'explain'
        explain()
    else:
        client.get_face_positions(camera_listener)
示例#3
0
def change_direction():
    """turn random."""
    status['ready'] = True
    word = status['word']
    if word == 'left':
        player['direction'] = 'left'
    elif word == 'right':
        player['direction'] = 'right'
    elif word == 'front':
        player['direction'] = 'front'
    #elif word == 'back':
    #    player['direction'] = 'back'
    else:
        status['ready'] = False

    if status['ready'] == False:
        client.speak('"Please say direction, Again"')
        time.sleep(3)
        status['name'] = 'game-start'
        status['word'] = ''
        game_start()
    else:
        status['ready'] = False
        i = random.randint(1, 3)
        if i == 1:
            maid['direction'] = 'left'
            maid['angle'] = -45
        elif i == 2:
            maid['direction'] = 'right'
            maid['angle'] = 45
        elif i == 3:
            maid['direction'] = 'front'
            maid['angle'] = 0
        #elif i == 4:
        #    maid['direction'] = 'back'
        #    maid['angle'] = 180
        client.left(maid['angle'])
        if maid['direction'] == 'front':
            time.sleep(1)
        else:
            time.sleep(3)
        client.right(maid['angle'])
        if maid['direction'] == 'front':
            time.sleep(1)
        else:
            time.sleep(3)
        # adjust_face_position()
        judge_game()
示例#4
0
def camera_listener(request):
    keys = request['faces'].keys()
    if len(keys) > 0:
        face = request['faces'][keys[0]]
        if face['name'] == '':
            client.speak('"I dont know you"')
        else:
            client.speak(face['name'])
        x = face['x']
        if x > 0:
            client.right(int(30 * x))
            time.sleep(2)
            client.move_acc(int(face['distance']))
        else:
            client.left(int(-30 * x))
            time.sleep(2)
            client.move_acc(int(face['distance']))
    client.get_face_positions(camera_listener)
示例#5
0
def facing_haruki(faces):
    keys = faces.keys()
    if len(keys) == 0:
        client.get_face_positions(camera_listener)
        return
    keys = filter(lambda k: faces[k]['name'] == 'haruki', keys)
    if len(keys) == 0:
        client.get_face_positions(camera_listener)
        return
    masakiFace = faces[keys[0]]
    if math.fabs(masakiFace['x']) < 0.1:
        client.move_acc(int(masakiFace['distance']))
        time.sleep(2)
        client.speak('"Hi, haruki."')
        time.sleep(1)
        client.speak('"I have coke for you"')
        status['name'] = 'finished'
    else:
        face_direction(masakiFace)
        client.get_face_positions(camera_listener)
示例#6
0
    def run(self):
        flg = True
        #sound = pygame.mixer.Sound("./sound/tempo_120.wav")
        tempo = 120.0 / 60

        #wf = wave.open('./sound/tempo_120.wav')
        pygame.mixer.init()
        pygame.mixer.music.load("./apps/sound/tempo_120.wav")
        pygame.mixer.music.play(-1)
        time.sleep(2)
        #sound.play()
        for i in range(5):
            flg = not flg
            if flg:
                client.right(30)
            else:
                client.left(30)
            time.sleep(tempo)

        pygame.mixer.music.stop()
        time.sleep(1)
        client.speak('"I am so tired"')
示例#7
0
def game_start():
    client.speak('"Look"')
    time.sleep(1)
    client.speak('"This"')
    time.sleep(1)
    client.speak('"Way!"')
    time.sleep(0.2)
    status['name'] = 'change-direction'
    change_direction()
示例#8
0
def explain():
    """explain rules of the game."""
    client.speak('"Lets play Look This Way!"')
    time.sleep(3)
    client.speak('"If I turn the direction you said, you win."')
    time.sleep(4)
    client.speak('"If you failed three times, you lose."')
    time.sleep(4)
    client.speak('"OK?"')
    status['word'] = ''
    time.sleep(0.5)
    status['name'] = 'waiting-explain-response'
    while True:
        word = status['word']
        if word == 'yes':
            client.speak('"game start"')
            time.sleep(1)
            status['name'] = 'game-start'
            status['word'] = ''
            game_start()
        elif word == 'no':
            status['name'] = 'explain'
            explain()
        status['word'] = ''
示例#9
0
def judge_game():
    maid['count'] += 1
    if player['direction'] == maid['direction']:
        client.speak('"You Win"')
        time.sleep(3)
        status['name'] = 'game-end'
    elif maid['count'] >= 3:
        client.speak('"You lose"')
        time.sleep(3)
        status['name'] = 'game-end'
    else:
        client.speak('"Once more chance"')
        time.sleep(3)
        status['name'] = 'game-start'
        status['word'] = ''
        game_start()
示例#10
0
文件: app1.py 项目: ROBOTEX3/robot
 def run(self):
     client.speak('hello')
示例#11
0
文件: app2.py 项目: ROBOTEX3/robot
 def run(self):
     client.speak('bye')
示例#12
0
def voice_listener(request):
    client.speak(request)
    client.get_voice(voice_listener)