Beispiel #1
0
    def __init__(self, view):
        # 네트워크 확인하기
        self.ping = self.checkPing()

        self.downloaderMain = DownloaderMain.DownloaderMain(self.ping)
        self.musicPlay = MusicPlay.MusicPlay(self, view)
        self.view = view
Beispiel #2
0
 def __init_config(self):
     self.tableList = [0 for x in range(0, 25)]
     self.scoreList = {}
     self.timer = QTimer()
     self.loopCount = 40
     self.tickCount = 100
     self.FirstTime = True
     # self.musicPlay = wavPlay()
     self.bgPlay = MusicPlay()
     indll = 'lib/in_mp3.dll'
     outdll = 'lib/out_wave.dll'
     if winamp.init(indll, outdll):
         print 'cannot load plugins'
         sys.exit(0)
     self.bgPlay.play('music/bg.mp3')
     self.bgIsPlay = True
     self.bgPlay.IsPaused = False
     self.wavplay = wavPlay()
Beispiel #3
0
 def __init_config(self):
     self.tableList = [ 0 for x in range(0,25)]
     self.scoreList = {}
     self.timer = QTimer()
     self.loopCount = 40
     self.tickCount = 100
     self.FirstTime = True
     # self.musicPlay = wavPlay()
     self.bgPlay = MusicPlay()
     indll = 'lib/in_mp3.dll'
     outdll = 'lib/out_wave.dll'
     if winamp.init(indll, outdll):
         print 'cannot load plugins'
         sys.exit(0)
     self.bgPlay.play('music/bg.mp3')
     self.bgIsPlay = True
     self.bgPlay.IsPaused = False
     self.wavplay = wavPlay()
Beispiel #4
0
class GobangClient(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self, ip, port, username, ns):
        QtGui.QMainWindow.__init__(self, None)
        self.ip = ip
        self.port = port
        self.username = username
        self.ns = ns

    #初始化配置
    def __init_config(self):
        self.tableList = [ 0 for x in range(0,25)]
        self.scoreList = {}
        self.timer = QTimer()
        self.loopCount = 40
        self.tickCount = 100
        self.FirstTime = True
        # self.musicPlay = wavPlay()
        self.bgPlay = MusicPlay()
        indll = 'lib/in_mp3.dll'
        outdll = 'lib/out_wave.dll'
        if winamp.init(indll, outdll):
            print 'cannot load plugins'
            sys.exit(0)
        self.bgPlay.play('music/bg.mp3')
        self.bgIsPlay = True
        self.bgPlay.IsPaused = False
        self.wavplay = wavPlay()

    #初始化Ui
    def __init_ui(self):
        self.setupUi(self)
        self.setWindowTitle(self.username)
        self.userInfo = chessPlay(self.username, self.chessBoard, self.inforShow)
        self.setButtonStatus(False, False, False, False, False, False)
        #将两个聊天对话框设为只读
        self.groupTalk.setReadOnly(True)
        # self.groupTalk.moveCursor(QtGui.QTextCursor.End)
        self.singleTalk.setReadOnly(True)
        # self.singleTalk.moveCursor(QtGui.QTextCursor.End)

        self.connect(self.start, SIGNAL('clicked()'), self.startChess)
        self.connect(self.undo, SIGNAL('clicked()'), self.undoChess)
        self.connect(self.left, SIGNAL('clicked()'), self.leaveChess)
        self.connect(self.again, SIGNAL('clicked()'), self.againChess)
        self.connect(self.giveUp, SIGNAL('clicked()'), self.loseChess)

    def __connect(self):
        #进入房间
        self.room.itemDoubleClicked.connect(self.intoTable)
        #定时器触发
        self.connect(self.timer, SIGNAL("timeout()"), self.check)
        #发送群聊消息
        self.connect(self.groupSend, SIGNAL("clicked()"),self.sendGroupMessage)
        self.connect(self.groupEdit, SIGNAL("returnPressed()"), self.sendGroupMessage)
        #房间聊天
        self.connect(self.singleSend, SIGNAL("clicked()"),self.sendSingleMessage)
        self.connect(self.singleEdit, SIGNAL("returnPressed()"), self.sendSingleMessage)
        #背景音乐控制
        self.connect(self.bgMusic, SIGNAL("clicked()"), self.controlBgMusic)


    # 设置按钮状态
    def setButtonStatus(self, startStatus, giveUpStatus, undoStatus, againStatus, leftStatus, singleSendStatus):
        self.start.setEnabled(startStatus)
        self.giveUp.setEnabled(giveUpStatus)
        self.undo.setEnabled(undoStatus)
        self.again.setEnabled(againStatus)
        self.left.setEnabled(leftStatus)
        self.singleSend.setEnabled(singleSendStatus)

    #启动和服务端的连接
    def startup(self):
        # self.ns = netstream.netstream(8)
        # self.ns.connect(self.ip, self.port)
        self.__init_config()
        self.__init_ui()
        self.__connect()
        # self.login_success_caller('Connected to remote host. Start sending messages')
        self.timer.start(50)

    # 客户端轮询函数
    def check(self):
        # while not shutdown:
        self.clientConfig()
        # time.sleep(0.05)
        self.ns.process()
        if self.ns.status() == netstream.NET_STATE_ESTABLISHED:
            # while True:
            data = self.ns.recv()
            # print 'data:%s'%data
            if len(data) > 0:
                data = json.loads(data)
                #查询能否进入房间
                # print data
                if data['sid'] == 100:
                    if data['cid'] == 1001:
                        self.tableList = data['tableList']
                    elif data['cid'] == 1003:
                        if data['roomid'] == self.userInfo.roomid - 1 and data['tableid'] == self.userInfo.tableid - 1:
                            self.inforShow.setText("你的对手离开\n了房间".decode('utf-8'))
                            self.player2.setText("玩家2:".decode('utf-8'))
                            self.score_player2.setText("分数:".decode('utf-8'))
                            self.setButtonStatus(False,False,False,False,True,False)
                            self.userInfo.opponent = None
                    elif data['cid'] == 1004:
                        if data['opponent'] != '':
                            self.userInfo.opponent = data['opponent']
                            self.player2.setText(self.userInfo.opponent)
                            if self.userInfo.opponent in self.scoreList:
                                self.score_player2.setText("分数:".decode('utf-8')+str(self.scoreList[self.userInfo.opponent]))
                            self.setButtonStatus(True,False,False,False,True,True)
                    elif data['cid'] == 1005:
                        if data['message'] == u'begin':
                            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"可以开始比赛了".decode('utf-8') )
                            #开始比赛
                            self.beginChess(data)
                        else:
                            self.inforShow.setText("你们还有一\n方未准备".decode('utf-8'))
                             # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你们有一方还未准备".decode('utf-8') )
                    elif data['cid'] == 1006:
                        n = data['n']
                        m = data['m']
                        self.userInfo.updateChessBoard(n, m)
                    elif data['cid'] == 1007:
                        self.inforShow.setText("很遗憾,\n你输了".decode('utf-8'))
                        self.setButtonStatus(False, False, False, True, True, True)
                        self.wavplay.playLose()
                        # if self.userInfo.chessType == 2:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "白棋获胜,你输了".decode('utf-8'))
                        # else:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "黑棋获胜,你输了".decode('utf-8'))
                        self.userInfo.IsNext = False
                    elif data['cid'] == 1008:
                        self.scoreList = data['scoreList']
                    elif data['cid'] == 1009:
                        self.inforShow.setText("对方认输,\n你赢了".decode('utf-8'))
                        self.setButtonStatus(False, False, False, True, True, True)
                        self.userInfo.IsNext = False
                        self.wavplay.playWin()
                        # if self.userInfo.chessType == 2:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "白棋认输,你赢了".decode('utf-8'))
                        # else:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "黑棋认输,你赢了".decode('utf-8'))
                    else:
                        pass
                        # print self.tableList
                elif data['sid'] == 101:
                    self.inforShow.setText("欢迎你进入\n大厅".decode('utf-8'))
                    # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"欢迎你进入大厅".decode('utf-8') )
                    pass
                elif data['sid'] == 102:
                    if data['cid'] == 1001:
                        # print 'heh'
                        groupMsg = data['user']+': '+str(time.strftime('%H:%M:%S',time.localtime(time.time())))+'\n'+data['message']+'\n'
                        self.groupTalk.insertPlainText(groupMsg)
                        self.groupTalk.setTextCursor(self.groupTalk.textCursor())
                    elif data['cid'] == 1002:
                        singleMsg = data['user']+': '+str(time.strftime('%H:%M:%S',time.localtime(time.time())))+'\n'+data['message']+'\n'
                        self.singleTalk.insertPlainText(singleMsg)
                        self.singleTalk.setTextCursor(self.singleTalk.textCursor())
                elif data['sid'] == 104:
                    if data['cid'] == 1001:
                        reply = QtGui.QMessageBox.question(self, "悔棋".decode('utf-8'), "你的对手请求悔棋,是否同意?".decode('utf-8'),QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
                        if reply == QtGui.QMessageBox.Yes:
                            data = {'sid':104,'cid':1002,'reply':'yes','userlist':[self.userInfo.opponent]}
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                            self.userInfo.backmove()
                        else:
                            data = {'sid':104,'cid':1002,'reply':'no','userlist':[self.userInfo.opponent]}
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                    elif data['cid'] == 1002:
                        if data['reply'] == 'yes':
                            QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"对手同意了你的悔棋请求".decode('utf-8'))
                            self.userInfo.backmove()
                        else:
                            QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"对手拒绝了你的悔棋请求".decode('utf-8'))
                        self.userInfo.IsNext = True
                        self.inforShow.setText("我方下".decode('utf-8'))
                    elif data['cid'] == 1003:
                        reply = QtGui.QMessageBox.question(self, "再来一局".decode('utf-8'), "你的对手请求再来一局,是否同意?".decode('utf-8'),QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
                        if reply == QtGui.QMessageBox.Yes:
                            data = {'sid':104,'cid':1004,'reply':'yes','userlist':[self.userInfo.opponent],'white':self.userInfo.opponent}
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                            #清除棋盘
                            self.userInfo.clearChessBoard()
                            #正式开始比赛
                            self.beginChess(data)
                        else:
                            data = {'sid':104,'cid':1004,'reply':'no','userlist':[self.userInfo.opponent]}
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                    elif data['cid'] == 1004:
                        if data['reply'] == 'yes':
                            QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"对手同意再来一局".decode('utf-8'))
                            #清除棋盘
                            self.userInfo.clearChessBoard()
                            #正式开始比赛
                            self.beginChess(data)
                        else:
                            QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"对手拒绝再来一局".decode('utf-8'))

                elif data['sid'] == 105:
                    pass
                elif data == 'quit':
                    self.ns.close()
                    shutdown = True
                    # break
                else:
                    pass
            else:
                pass
        elif self.ns.status() == netstream.NET_STATE_STOP:
            pass

    #鼠标左键按下监听
    def releaseAction(self,event):
        if event.button() == Qt.LeftButton:
            self.paint(event.pos().x(), event.pos().y())

    #描绘棋子
    def paint(self, x, y):
        n, m = self.userInfo.pressEvent(x,y)
        if n != -1:
            data = {'sid':100,'cid':1006,'m':m,'n':n,'userlist':[self.userInfo.opponent]}
            self.ns.send(json.dumps(data))

        if self.userInfo.IsWin(n, m):
            self.userInfo.IsNext = False
            self.setButtonStatus(False, False, False, True, True, True)
            self.inforShow.setText("恭喜你赢了".decode('utf-8'))
            self.wavplay.playWin()
            data = {'sid':100,'cid':1007,'winner':self.userInfo.name,'loser':self.userInfo.opponent,'chessType':self.userInfo.chessType}
            self.ns.send(json.dumps(data))
            self.ns.process()
            # if self.userInfo.chessType == 1:
            #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "白棋获胜,你赢了".decode('utf-8'))
            # else:
            #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "黑棋获胜,你赢了".decode('utf-8'))

    #排行榜
    def rank(self):
        self.scoreRank.clear()
        data = sorted(self.scoreList.iteritems(), key=lambda d:d[1], reverse = True)
        self.scoreRank.addItem('玩家'.decode('utf-8').ljust(18, ' ') + '分数'.decode('utf-8'))
        for i in range(len(data)):
            if i >= 3:
                break
            self.scoreRank.addItem(str(data[i][0]).ljust(20,' ')+str(data[i][1]))

    # 客户端配置
    def clientConfig(self):
        #更新房间列表人数
        self.updateRoom()
        self.rank()
        #配对用户名和hid
        if self.FirstTime:
            data = {'sid':103,'cid':1001,'user':self.userInfo.name}
            self.ns.send(json.dumps(data))
            self.ns.process()
            self.FirstTime = False
        #如果用户还没对手,一直检索对手


        if self.userInfo.opponent == None  and self.loopCount == 0:
            self.loopCount = 40
            # print self.userInfo.opponent,self.userInfo.tableid
            if self.userInfo.tableid != -1:
                data = {'sid':100, 'cid':1004,'roomid':self.userInfo.roomid - 1,'tableid':self.userInfo.tableid - 1,'user':self.userInfo.name}
                self.ns.send(json.dumps(data))
                self.ns.process()
        else:
            if self.loopCount == 0:
                self.loopCount = 40
            self.loopCount -= 1
        #更新分数
        if self.userInfo.IsInto:
            if self.userInfo.name in self.scoreList:
                self.score_player1.setText("分数:".decode('utf-8')+str(self.scoreList[self.userInfo.name]))
            if self.userInfo.opponent != None and self.userInfo.opponent in self.scoreList:
                self.score_player2.setText("分数:".decode('utf-8')+str(self.scoreList[self.userInfo.opponent]))
        #每隔5秒发送心跳包
        if self.tickCount == 0:
            self.tickCount = 100
            data = {'sid':105,'cid':1001}
            self.ns.send(json.dumps(data))
            self.ns.process()
        else:
            self.tickCount -= 1

    #进入房间事件
    def intoTable(self, item):
        #如果已经进入房间,就不让点击房间桌子item了
        if self.userInfo.IsInto:
            return
        parent1 = item.parent()
        if parent1:
            num1 = parent1.indexOfChild(item)
        parent2 = parent1.parent()
        num2 = -1
        if parent2:
            num2 = parent2.indexOfChild(parent1)
        if num2 != -1:
            index = num2 * 5 + num1
            num =self.tableList[index]
            if num == 2:
                # QtGui.QMessageBox.information(self, "错误".decode('utf-8'),"桌子认输已满,请选择别的桌子".decode('utf-8'))
                pass
            elif num == 1:
                # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你已进入房间,你的对手已经坐下".decode('utf-8'))
                #用户进入房间
                data = {'sid':100, 'cid':1002,'roomid':num2,'tableid':num1,'user':self.username}
                # self.tableList[index] += 1
                self.ns.send(json.dumps(data))
                # self.ns.process()

                self.userInfo.IsInto = True
                self.setButtonStatus(True,False,False,False,True,True)
                self.userInfo.roomid = num2 + 1
                self.userInfo.tableid = num1 + 1
                self.roomName.setText('房间'.decode('utf-8')+str(self.userInfo.roomid)+'\n桌子'.decode('utf-8')+str(self.userInfo.tableid))
                self.inforShow.setText("欢迎你坐下\n".decode('utf-8'))
                self.player1.setText(self.userInfo.name)
                if self.userInfo.name in self.scoreList:
                    self.score_player1.setText("分数:".decode('utf-8')+str(self.scoreList[self.userInfo.name]))
                #用户获取的对手资料
                data = {'sid':100, 'cid':1004,'roomid':num2,'tableid':num1,'user':self.username}
                self.ns.send(json.dumps(data))
                self.ns.process()
            else:
                # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你已进入房间,等待你的对手中".decode('utf-8') )
                data = {'sid':100, 'cid':1002,'roomid':num2,'tableid':num1,'user':self.username}
                # self.tableList[index] += 1
                self.ns.send(json.dumps(data))
                self.ns.process()

                self.userInfo.IsInto = True
                self.userInfo.opponent = None
                self.setButtonStatus(False,False,False,False,True,False)
                self.userInfo.roomid = num2 + 1
                self.userInfo.tableid = num1 + 1
                self.roomName.setText('房间'.decode('utf-8')+str(self.userInfo.roomid)+'\n桌子'.decode('utf-8')+str(self.userInfo.tableid))
                self.inforShow.setText("欢迎你坐下\n".decode('utf-8'))
                self.player1.setText(self.userInfo.name)
                if self.userInfo.name in self.scoreList:
                    self.score_player1.setText("分数:".decode('utf-8')+str(self.scoreList[self.userInfo.name]))

    #控制背景音乐播放
    def controlBgMusic(self):
        self.bgPlay.pause()
        if self.bgIsPlay:
            self.bgMusic.setText('播放背景音乐'.decode('utf-8'))
            self.bgIsPlay = False
        else:
            self.bgMusic.setText('关闭背景音乐'.decode('utf-8'))
            self.bgIsPlay = True

    #更新房间桌子列表
    def updateRoom(self):
        item0 = self.room.invisibleRootItem()
        item1 = item0.child(0)
        childCount =  item1.childCount()
        for i in range(childCount):
            itemChild1 = item1.child(i)
            num = 0
            for j in range(0, 5):
                num += self.tableList[i * 5 + j]
                if itemChild1:
                    itemChild2 = itemChild1.child(j)
                    itemChild2.setText(0,'桌子'.decode('utf-8')+str(j+1)+'('+str(self.tableList[i*5 +j])+'/2)')
            if itemChild1:
                itemChild1.setText(0,'房间'.decode('utf-8')+ str(i+1) +'('+ str(num) +'/10)')

    #发送群聊消息
    def sendGroupMessage(self):
        text = self.groupEdit.text()
        text = unicode(text).strip()
        self.groupEdit.clear()
        if len(text) > 0:
            data = {'sid':102,'cid':1001,'message':text,'user':self.userInfo.name}
            self.ns.send(json.dumps(data))
            self.ns.process()

    #房间聊天
    def sendSingleMessage(self):
        if self.userInfo.opponent != None:
            text = self.singleEdit.text()
            text = unicode(text).strip()
            self.singleEdit.clear()
            if len(text) > 0:
                data = {'sid':102,'cid':1002,'message':text,'userlist':[self.userInfo.name,self.userInfo.opponent],'user':self.userInfo.name}
                self.ns.send(json.dumps(data))
                self.ns.process()

    # 开始准备
    def startChess(self):
        self.setButtonStatus(False, True, True, False, False, True)
        self.userInfo.IsReady = True
        message = {'sid':100,'cid':1005,'message':'start','user':self.userInfo.name,'opponent':self.userInfo.opponent}
        self.ns.send(json.dumps(message))

    # 再来一局
    def againChess(self):
        message = {'sid':104,'cid':1003,'message':'again','userlist':[self.userInfo.opponent],'user':self.userInfo.name}
        self.ns.send(json.dumps(message))

    # 认输
    def loseChess(self):
        self.setButtonStatus(False, False, False, True, True, True)
        self.userInfo.IsNext = False
        data = {'sid':100,'cid':1009,'winner':self.userInfo.opponent,'loser':self.userInfo.name,'chessType':self.userInfo.chessType}
        self.ns.send(json.dumps(data))
        self.ns.process()
        self.inforShow.setText("你认输了".decode('utf-8'))
        self.wavplay.playLose()

    # 悔棋
    def undoChess(self):
        if not self.userInfo.IsNext:
            return
        if len(self.userInfo.path) < 2:
            self.inforShow.setText("你还没下,\n不得悔棋".decode('utf-8'))
            return
        else:
            self.userInfo.IsNext = False
            self.inforShow.setText("悔棋等待中".decode('utf-8'))
            data = {'sid':104, 'cid':1001,'message':'undo','userlist':[self.userInfo.opponent],'user':self.userInfo.name}
            self.ns.send(json.dumps(data))
            self.ns.process()

    # 正式开始比赛
    def beginChess(self, data):
        self.inforShow.setText("可以开始\n比赛了".decode('utf-8'))
        self.wavplay.playStart()
        self.setButtonStatus(False,True,True,False,False,True)
        self.userInfo.IsBegin = True
        self.chessBoard.mouseReleaseEvent = self.releaseAction
        #如果白棋是自己的名字,那么自己的五子棋类型为白棋
        if data['white'] == self.userInfo.name:
            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你是白棋,你先下".decode('utf-8') )
            self.inforShow.setText("你是白棋,\n你先下".decode('utf-8'))
            self.userInfo.chessType = WHITE_FLAG  #白棋
            self.userInfo.IsNext = True
        else:
            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你是黑棋,你后手".decode('utf-8') )
            self.inforShow.setText("你是黑棋,\n你后手".decode('utf-8'))
            self.userInfo.chessType = BLACK_FLAG  #黑棋
            self.userInfo.IsNext = False

    # 离开房间
    def leaveChess(self):
        self.userInfo.clearChessBoard()
        self.player1.setText("玩家1:".decode('utf-8'))
        self.score_player1.setText("分数:".decode('utf-8'))
        self.player2.setText("玩家2:".decode('utf-8'))
        self.score_player2.setText("分数:".decode('utf-8'))
        self.userInfo.IsInto = False
        data = {'sid':100,'cid':1003,'roomid':self.userInfo.roomid - 1,'tableid':self.userInfo.tableid - 1,'user':self.userInfo.name,'opponent':self.userInfo.opponent}
        self.userInfo.opponent = None
        self.userInfo.tableid = -1
        self.userInfo.roomid = -1
        # self.tableList[index] += 1
        self.ns.send(json.dumps(data))
        self.ns.process()
        self.setButtonStatus(False,False,False,False,False,False)
        self.roomName.setText("暂未进\n入房间".decode('utf-8'))
        self.inforShow.setText("你已经离开\n了房间".decode('utf-8'))
Beispiel #5
0
class GobangClient(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self, ip, port, username, ns):
        QtGui.QMainWindow.__init__(self, None)
        self.ip = ip
        self.port = port
        self.username = username
        self.ns = ns

    #初始化配置
    def __init_config(self):
        self.tableList = [0 for x in range(0, 25)]
        self.scoreList = {}
        self.timer = QTimer()
        self.loopCount = 40
        self.tickCount = 100
        self.FirstTime = True
        # self.musicPlay = wavPlay()
        self.bgPlay = MusicPlay()
        indll = 'lib/in_mp3.dll'
        outdll = 'lib/out_wave.dll'
        if winamp.init(indll, outdll):
            print 'cannot load plugins'
            sys.exit(0)
        self.bgPlay.play('music/bg.mp3')
        self.bgIsPlay = True
        self.bgPlay.IsPaused = False
        self.wavplay = wavPlay()

    #初始化Ui
    def __init_ui(self):
        self.setupUi(self)
        self.setWindowTitle(self.username)
        self.userInfo = chessPlay(self.username, self.chessBoard,
                                  self.inforShow)
        self.setButtonStatus(False, False, False, False, False, False)
        #将两个聊天对话框设为只读
        self.groupTalk.setReadOnly(True)
        # self.groupTalk.moveCursor(QtGui.QTextCursor.End)
        self.singleTalk.setReadOnly(True)
        # self.singleTalk.moveCursor(QtGui.QTextCursor.End)

        self.connect(self.start, SIGNAL('clicked()'), self.startChess)
        self.connect(self.undo, SIGNAL('clicked()'), self.undoChess)
        self.connect(self.left, SIGNAL('clicked()'), self.leaveChess)
        self.connect(self.again, SIGNAL('clicked()'), self.againChess)
        self.connect(self.giveUp, SIGNAL('clicked()'), self.loseChess)

    def __connect(self):
        #进入房间
        self.room.itemDoubleClicked.connect(self.intoTable)
        #定时器触发
        self.connect(self.timer, SIGNAL("timeout()"), self.check)
        #发送群聊消息
        self.connect(self.groupSend, SIGNAL("clicked()"),
                     self.sendGroupMessage)
        self.connect(self.groupEdit, SIGNAL("returnPressed()"),
                     self.sendGroupMessage)
        #房间聊天
        self.connect(self.singleSend, SIGNAL("clicked()"),
                     self.sendSingleMessage)
        self.connect(self.singleEdit, SIGNAL("returnPressed()"),
                     self.sendSingleMessage)
        #背景音乐控制
        self.connect(self.bgMusic, SIGNAL("clicked()"), self.controlBgMusic)

    # 设置按钮状态
    def setButtonStatus(self, startStatus, giveUpStatus, undoStatus,
                        againStatus, leftStatus, singleSendStatus):
        self.start.setEnabled(startStatus)
        self.giveUp.setEnabled(giveUpStatus)
        self.undo.setEnabled(undoStatus)
        self.again.setEnabled(againStatus)
        self.left.setEnabled(leftStatus)
        self.singleSend.setEnabled(singleSendStatus)

    #启动和服务端的连接
    def startup(self):
        # self.ns = netstream.netstream(8)
        # self.ns.connect(self.ip, self.port)
        self.__init_config()
        self.__init_ui()
        self.__connect()
        # self.login_success_caller('Connected to remote host. Start sending messages')
        self.timer.start(50)

    # 客户端轮询函数
    def check(self):
        # while not shutdown:
        self.clientConfig()
        # time.sleep(0.05)
        self.ns.process()
        if self.ns.status() == netstream.NET_STATE_ESTABLISHED:
            # while True:
            data = self.ns.recv()
            # print 'data:%s'%data
            if len(data) > 0:
                data = json.loads(data)
                #查询能否进入房间
                # print data
                if data['sid'] == 100:
                    if data['cid'] == 1001:
                        self.tableList = data['tableList']
                    elif data['cid'] == 1003:
                        if data['roomid'] == self.userInfo.roomid - 1 and data[
                                'tableid'] == self.userInfo.tableid - 1:
                            self.inforShow.setText(
                                "你的对手离开\n了房间".decode('utf-8'))
                            self.player2.setText("玩家2:".decode('utf-8'))
                            self.score_player2.setText("分数:".decode('utf-8'))
                            self.setButtonStatus(False, False, False, False,
                                                 True, False)
                            self.userInfo.opponent = None
                    elif data['cid'] == 1004:
                        if data['opponent'] != '':
                            self.userInfo.opponent = data['opponent']
                            self.player2.setText(self.userInfo.opponent)
                            if self.userInfo.opponent in self.scoreList:
                                self.score_player2.setText(
                                    "分数:".decode('utf-8') +
                                    str(self.scoreList[self.userInfo.opponent])
                                )
                            self.setButtonStatus(True, False, False, False,
                                                 True, True)
                    elif data['cid'] == 1005:
                        if data['message'] == u'begin':
                            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"可以开始比赛了".decode('utf-8') )
                            #开始比赛
                            self.beginChess(data)
                        else:
                            self.inforShow.setText(
                                "你们还有一\n方未准备".decode('utf-8'))
                            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你们有一方还未准备".decode('utf-8') )
                    elif data['cid'] == 1006:
                        n = data['n']
                        m = data['m']
                        self.userInfo.updateChessBoard(n, m)
                    elif data['cid'] == 1007:
                        self.inforShow.setText("很遗憾,\n你输了".decode('utf-8'))
                        self.setButtonStatus(False, False, False, True, True,
                                             True)
                        self.wavplay.playLose()
                        # if self.userInfo.chessType == 2:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "白棋获胜,你输了".decode('utf-8'))
                        # else:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "黑棋获胜,你输了".decode('utf-8'))
                        self.userInfo.IsNext = False
                    elif data['cid'] == 1008:
                        self.scoreList = data['scoreList']
                    elif data['cid'] == 1009:
                        self.inforShow.setText("对方认输,\n你赢了".decode('utf-8'))
                        self.setButtonStatus(False, False, False, True, True,
                                             True)
                        self.userInfo.IsNext = False
                        self.wavplay.playWin()
                        # if self.userInfo.chessType == 2:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "白棋认输,你赢了".decode('utf-8'))
                        # else:
                        #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "黑棋认输,你赢了".decode('utf-8'))
                    else:
                        pass
                        # print self.tableList
                elif data['sid'] == 101:
                    self.inforShow.setText("欢迎你进入\n大厅".decode('utf-8'))
                    # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"欢迎你进入大厅".decode('utf-8') )
                    pass
                elif data['sid'] == 102:
                    if data['cid'] == 1001:
                        # print 'heh'
                        groupMsg = data['user'] + ': ' + str(
                            time.strftime('%H:%M:%S',
                                          time.localtime(time.time()))
                        ) + '\n' + data['message'] + '\n'
                        self.groupTalk.insertPlainText(groupMsg)
                        self.groupTalk.setTextCursor(
                            self.groupTalk.textCursor())
                    elif data['cid'] == 1002:
                        singleMsg = data['user'] + ': ' + str(
                            time.strftime('%H:%M:%S',
                                          time.localtime(time.time()))
                        ) + '\n' + data['message'] + '\n'
                        self.singleTalk.insertPlainText(singleMsg)
                        self.singleTalk.setTextCursor(
                            self.singleTalk.textCursor())
                elif data['sid'] == 104:
                    if data['cid'] == 1001:
                        reply = QtGui.QMessageBox.question(
                            self, "悔棋".decode('utf-8'),
                            "你的对手请求悔棋,是否同意?".decode('utf-8'),
                            QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
                        if reply == QtGui.QMessageBox.Yes:
                            data = {
                                'sid': 104,
                                'cid': 1002,
                                'reply': 'yes',
                                'userlist': [self.userInfo.opponent]
                            }
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                            self.userInfo.backmove()
                        else:
                            data = {
                                'sid': 104,
                                'cid': 1002,
                                'reply': 'no',
                                'userlist': [self.userInfo.opponent]
                            }
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                    elif data['cid'] == 1002:
                        if data['reply'] == 'yes':
                            QtGui.QMessageBox.information(
                                self, "提示".decode('utf-8'),
                                "对手同意了你的悔棋请求".decode('utf-8'))
                            self.userInfo.backmove()
                        else:
                            QtGui.QMessageBox.information(
                                self, "提示".decode('utf-8'),
                                "对手拒绝了你的悔棋请求".decode('utf-8'))
                        self.userInfo.IsNext = True
                        self.inforShow.setText("我方下".decode('utf-8'))
                    elif data['cid'] == 1003:
                        reply = QtGui.QMessageBox.question(
                            self, "再来一局".decode('utf-8'),
                            "你的对手请求再来一局,是否同意?".decode('utf-8'),
                            QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
                        if reply == QtGui.QMessageBox.Yes:
                            data = {
                                'sid': 104,
                                'cid': 1004,
                                'reply': 'yes',
                                'userlist': [self.userInfo.opponent],
                                'white': self.userInfo.opponent
                            }
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                            #清除棋盘
                            self.userInfo.clearChessBoard()
                            #正式开始比赛
                            self.beginChess(data)
                        else:
                            data = {
                                'sid': 104,
                                'cid': 1004,
                                'reply': 'no',
                                'userlist': [self.userInfo.opponent]
                            }
                            self.ns.send(json.dumps(data))
                            self.ns.process()
                    elif data['cid'] == 1004:
                        if data['reply'] == 'yes':
                            QtGui.QMessageBox.information(
                                self, "提示".decode('utf-8'),
                                "对手同意再来一局".decode('utf-8'))
                            #清除棋盘
                            self.userInfo.clearChessBoard()
                            #正式开始比赛
                            self.beginChess(data)
                        else:
                            QtGui.QMessageBox.information(
                                self, "提示".decode('utf-8'),
                                "对手拒绝再来一局".decode('utf-8'))

                elif data['sid'] == 105:
                    pass
                elif data == 'quit':
                    self.ns.close()
                    shutdown = True
                    # break
                else:
                    pass
            else:
                pass
        elif self.ns.status() == netstream.NET_STATE_STOP:
            pass

    #鼠标左键按下监听
    def releaseAction(self, event):
        if event.button() == Qt.LeftButton:
            self.paint(event.pos().x(), event.pos().y())

    #描绘棋子
    def paint(self, x, y):
        n, m = self.userInfo.pressEvent(x, y)
        if n != -1:
            data = {
                'sid': 100,
                'cid': 1006,
                'm': m,
                'n': n,
                'userlist': [self.userInfo.opponent]
            }
            self.ns.send(json.dumps(data))

        if self.userInfo.IsWin(n, m):
            self.userInfo.IsNext = False
            self.setButtonStatus(False, False, False, True, True, True)
            self.inforShow.setText("恭喜你赢了".decode('utf-8'))
            self.wavplay.playWin()
            data = {
                'sid': 100,
                'cid': 1007,
                'winner': self.userInfo.name,
                'loser': self.userInfo.opponent,
                'chessType': self.userInfo.chessType
            }
            self.ns.send(json.dumps(data))
            self.ns.process()
            # if self.userInfo.chessType == 1:
            #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "白棋获胜,你赢了".decode('utf-8'))
            # else:
            #     QtGui.QMessageBox.information(self, "结束".decode('utf-8'), "黑棋获胜,你赢了".decode('utf-8'))

    #排行榜
    def rank(self):
        self.scoreRank.clear()
        data = sorted(self.scoreList.iteritems(),
                      key=lambda d: d[1],
                      reverse=True)
        self.scoreRank.addItem('玩家'.decode('utf-8').ljust(18, ' ') +
                               '分数'.decode('utf-8'))
        for i in range(len(data)):
            if i >= 3:
                break
            self.scoreRank.addItem(
                str(data[i][0]).ljust(20, ' ') + str(data[i][1]))

    # 客户端配置
    def clientConfig(self):
        #更新房间列表人数
        self.updateRoom()
        self.rank()
        #配对用户名和hid
        if self.FirstTime:
            data = {'sid': 103, 'cid': 1001, 'user': self.userInfo.name}
            self.ns.send(json.dumps(data))
            self.ns.process()
            self.FirstTime = False
        #如果用户还没对手,一直检索对手

        if self.userInfo.opponent == None and self.loopCount == 0:
            self.loopCount = 40
            # print self.userInfo.opponent,self.userInfo.tableid
            if self.userInfo.tableid != -1:
                data = {
                    'sid': 100,
                    'cid': 1004,
                    'roomid': self.userInfo.roomid - 1,
                    'tableid': self.userInfo.tableid - 1,
                    'user': self.userInfo.name
                }
                self.ns.send(json.dumps(data))
                self.ns.process()
        else:
            if self.loopCount == 0:
                self.loopCount = 40
            self.loopCount -= 1
        #更新分数
        if self.userInfo.IsInto:
            if self.userInfo.name in self.scoreList:
                self.score_player1.setText(
                    "分数:".decode('utf-8') +
                    str(self.scoreList[self.userInfo.name]))
            if self.userInfo.opponent != None and self.userInfo.opponent in self.scoreList:
                self.score_player2.setText(
                    "分数:".decode('utf-8') +
                    str(self.scoreList[self.userInfo.opponent]))
        #每隔5秒发送心跳包
        if self.tickCount == 0:
            self.tickCount = 100
            data = {'sid': 105, 'cid': 1001}
            self.ns.send(json.dumps(data))
            self.ns.process()
        else:
            self.tickCount -= 1

    #进入房间事件
    def intoTable(self, item):
        #如果已经进入房间,就不让点击房间桌子item了
        if self.userInfo.IsInto:
            return
        parent1 = item.parent()
        if parent1:
            num1 = parent1.indexOfChild(item)
        parent2 = parent1.parent()
        num2 = -1
        if parent2:
            num2 = parent2.indexOfChild(parent1)
        if num2 != -1:
            index = num2 * 5 + num1
            num = self.tableList[index]
            if num == 2:
                # QtGui.QMessageBox.information(self, "错误".decode('utf-8'),"桌子认输已满,请选择别的桌子".decode('utf-8'))
                pass
            elif num == 1:
                # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你已进入房间,你的对手已经坐下".decode('utf-8'))
                #用户进入房间
                data = {
                    'sid': 100,
                    'cid': 1002,
                    'roomid': num2,
                    'tableid': num1,
                    'user': self.username
                }
                # self.tableList[index] += 1
                self.ns.send(json.dumps(data))
                # self.ns.process()

                self.userInfo.IsInto = True
                self.setButtonStatus(True, False, False, False, True, True)
                self.userInfo.roomid = num2 + 1
                self.userInfo.tableid = num1 + 1
                self.roomName.setText('房间'.decode('utf-8') +
                                      str(self.userInfo.roomid) +
                                      '\n桌子'.decode('utf-8') +
                                      str(self.userInfo.tableid))
                self.inforShow.setText("欢迎你坐下\n".decode('utf-8'))
                self.player1.setText(self.userInfo.name)
                if self.userInfo.name in self.scoreList:
                    self.score_player1.setText(
                        "分数:".decode('utf-8') +
                        str(self.scoreList[self.userInfo.name]))
                #用户获取的对手资料
                data = {
                    'sid': 100,
                    'cid': 1004,
                    'roomid': num2,
                    'tableid': num1,
                    'user': self.username
                }
                self.ns.send(json.dumps(data))
                self.ns.process()
            else:
                # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你已进入房间,等待你的对手中".decode('utf-8') )
                data = {
                    'sid': 100,
                    'cid': 1002,
                    'roomid': num2,
                    'tableid': num1,
                    'user': self.username
                }
                # self.tableList[index] += 1
                self.ns.send(json.dumps(data))
                self.ns.process()

                self.userInfo.IsInto = True
                self.userInfo.opponent = None
                self.setButtonStatus(False, False, False, False, True, False)
                self.userInfo.roomid = num2 + 1
                self.userInfo.tableid = num1 + 1
                self.roomName.setText('房间'.decode('utf-8') +
                                      str(self.userInfo.roomid) +
                                      '\n桌子'.decode('utf-8') +
                                      str(self.userInfo.tableid))
                self.inforShow.setText("欢迎你坐下\n".decode('utf-8'))
                self.player1.setText(self.userInfo.name)
                if self.userInfo.name in self.scoreList:
                    self.score_player1.setText(
                        "分数:".decode('utf-8') +
                        str(self.scoreList[self.userInfo.name]))

    #控制背景音乐播放
    def controlBgMusic(self):
        self.bgPlay.pause()
        if self.bgIsPlay:
            self.bgMusic.setText('播放背景音乐'.decode('utf-8'))
            self.bgIsPlay = False
        else:
            self.bgMusic.setText('关闭背景音乐'.decode('utf-8'))
            self.bgIsPlay = True

    #更新房间桌子列表
    def updateRoom(self):
        item0 = self.room.invisibleRootItem()
        item1 = item0.child(0)
        childCount = item1.childCount()
        for i in range(childCount):
            itemChild1 = item1.child(i)
            num = 0
            for j in range(0, 5):
                num += self.tableList[i * 5 + j]
                if itemChild1:
                    itemChild2 = itemChild1.child(j)
                    itemChild2.setText(
                        0, '桌子'.decode('utf-8') + str(j + 1) + '(' +
                        str(self.tableList[i * 5 + j]) + '/2)')
            if itemChild1:
                itemChild1.setText(
                    0, '房间'.decode('utf-8') + str(i + 1) + '(' + str(num) +
                    '/10)')

    #发送群聊消息
    def sendGroupMessage(self):
        text = self.groupEdit.text()
        text = unicode(text).strip()
        self.groupEdit.clear()
        if len(text) > 0:
            data = {
                'sid': 102,
                'cid': 1001,
                'message': text,
                'user': self.userInfo.name
            }
            self.ns.send(json.dumps(data))
            self.ns.process()

    #房间聊天
    def sendSingleMessage(self):
        if self.userInfo.opponent != None:
            text = self.singleEdit.text()
            text = unicode(text).strip()
            self.singleEdit.clear()
            if len(text) > 0:
                data = {
                    'sid': 102,
                    'cid': 1002,
                    'message': text,
                    'userlist': [self.userInfo.name, self.userInfo.opponent],
                    'user': self.userInfo.name
                }
                self.ns.send(json.dumps(data))
                self.ns.process()

    # 开始准备
    def startChess(self):
        self.setButtonStatus(False, True, True, False, False, True)
        self.userInfo.IsReady = True
        message = {
            'sid': 100,
            'cid': 1005,
            'message': 'start',
            'user': self.userInfo.name,
            'opponent': self.userInfo.opponent
        }
        self.ns.send(json.dumps(message))

    # 再来一局
    def againChess(self):
        message = {
            'sid': 104,
            'cid': 1003,
            'message': 'again',
            'userlist': [self.userInfo.opponent],
            'user': self.userInfo.name
        }
        self.ns.send(json.dumps(message))

    # 认输
    def loseChess(self):
        self.setButtonStatus(False, False, False, True, True, True)
        self.userInfo.IsNext = False
        data = {
            'sid': 100,
            'cid': 1009,
            'winner': self.userInfo.opponent,
            'loser': self.userInfo.name,
            'chessType': self.userInfo.chessType
        }
        self.ns.send(json.dumps(data))
        self.ns.process()
        self.inforShow.setText("你认输了".decode('utf-8'))
        self.wavplay.playLose()

    # 悔棋
    def undoChess(self):
        if not self.userInfo.IsNext:
            return
        if len(self.userInfo.path) < 2:
            self.inforShow.setText("你还没下,\n不得悔棋".decode('utf-8'))
            return
        else:
            self.userInfo.IsNext = False
            self.inforShow.setText("悔棋等待中".decode('utf-8'))
            data = {
                'sid': 104,
                'cid': 1001,
                'message': 'undo',
                'userlist': [self.userInfo.opponent],
                'user': self.userInfo.name
            }
            self.ns.send(json.dumps(data))
            self.ns.process()

    # 正式开始比赛
    def beginChess(self, data):
        self.inforShow.setText("可以开始\n比赛了".decode('utf-8'))
        self.wavplay.playStart()
        self.setButtonStatus(False, True, True, False, False, True)
        self.userInfo.IsBegin = True
        self.chessBoard.mouseReleaseEvent = self.releaseAction
        #如果白棋是自己的名字,那么自己的五子棋类型为白棋
        if data['white'] == self.userInfo.name:
            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你是白棋,你先下".decode('utf-8') )
            self.inforShow.setText("你是白棋,\n你先下".decode('utf-8'))
            self.userInfo.chessType = WHITE_FLAG  #白棋
            self.userInfo.IsNext = True
        else:
            # QtGui.QMessageBox.information(self, "提示".decode('utf-8'),"你是黑棋,你后手".decode('utf-8') )
            self.inforShow.setText("你是黑棋,\n你后手".decode('utf-8'))
            self.userInfo.chessType = BLACK_FLAG  #黑棋
            self.userInfo.IsNext = False

    # 离开房间
    def leaveChess(self):
        self.userInfo.clearChessBoard()
        self.player1.setText("玩家1:".decode('utf-8'))
        self.score_player1.setText("分数:".decode('utf-8'))
        self.player2.setText("玩家2:".decode('utf-8'))
        self.score_player2.setText("分数:".decode('utf-8'))
        self.userInfo.IsInto = False
        data = {
            'sid': 100,
            'cid': 1003,
            'roomid': self.userInfo.roomid - 1,
            'tableid': self.userInfo.tableid - 1,
            'user': self.userInfo.name,
            'opponent': self.userInfo.opponent
        }
        self.userInfo.opponent = None
        self.userInfo.tableid = -1
        self.userInfo.roomid = -1
        # self.tableList[index] += 1
        self.ns.send(json.dumps(data))
        self.ns.process()
        self.setButtonStatus(False, False, False, False, False, False)
        self.roomName.setText("暂未进\n入房间".decode('utf-8'))
        self.inforShow.setText("你已经离开\n了房间".decode('utf-8'))
Beispiel #6
0
    def StartDance(self):

        motionProxyOne = ALProxy("ALMotion", self.IPOne, 9559)
        motionProxyOne.wakeUp()
#        motionProxyOne.setStiffnesses('Body', self.stiffnesses)
        names = ["LShoulderPitch", "LShoulderRoll", "LElbowYaw", "LElbowRoll", "LWristYaw", "RShoulderPitch",
                 "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw", "LHipPitch", "LHipRoll", "LKneePitch",
                 "LAnklePitch", "LAnkleRoll", "RHipPitch", "RHipRoll", "RKneePitch", "RAnklePitch", "RAnkleRoll",
                 "HeadYaw", "HeadPitch", "LHipYawPitch", "RHipYawPitch"]
        # 手臂动作
        angles = [-0.010779857635498047, 0.5874800682067871, -1.0063457489013672, -0.4279439449310303,
                  1.2118180990219116, -0.007627964019775391, -0.527738094329834, 1.0492141246795654,
                  0.48018407821655273, -0.7210218906402588, 0.1304318904876709, 0.09975194931030273,
                  -0.08901405334472656, 0.09046411514282227, -0.1288139820098877, 0.12999999523162842,
                  -0.10000000149011612, -0.09000000357627869, 0.09000000357627869, 0.12999999523162842, 0.0,
                  -0.17000000178813934, -0.17023205757141113, -0.17023205757141113]

        angles1 = [0.0858621597290039, 0.1978440284729004, -1.0078802108764648, -0.21932005882263184,
                   1.6566780805587769, 0.13810205459594727, -0.17031598091125488, 0.8160459995269775,
                   0.2654240131378174, -1.1229300498962402, 0.1304318904876709, 0.09975194931030273,
                   -0.08901405334472656, 0.09046411514282227, -0.1288139820098877, 0.07512402534484863,
                   -0.09813404083251953, -0.09232791513204575, 0.11816000938415527, 0.12889790534973145, 0.0,
                   -0.17000000178813934, -0.17023205757141113, -0.17023205757141113]

        angles2 = [0.4893040657043457, -0.11202406883239746, -0.7777800559997559, -0.43868207931518555,
                   1.0231361389160156, 0.5001258850097656, 0.04904603958129883, 0.5936160087585449, 0.5507478713989258,
                   -0.8836259841918945, 0.12999999523162842, 0.10000000149011612, -0.09000000357627869,
                   0.09000000357627869, -0.12999999523162842, 0.12999999523162842, -0.10000000149011612,
                   -0.09000000357627869, 0.09000000357627869, 0.12999999523162842, -0.004643917083740234,
                   -0.18872404098510742, -0.17000000178813934, -0.17000000178813934]

        angles3 = [-0.2654240131378174, 0.3543119430541992, -0.8099939823150635, -0.1487560272216797,
                   1.3238000869750977, -0.2668740749359131, -0.3636000156402588, 0.9479701519012451,
                   0.35439586639404297, -1.4420018196105957, 0.12999999523162842, 0.10000000149011612,
                   -0.09000000357627869, 0.09000000357627869, -0.12999999523162842, 0.12999999523162842,
                   -0.10000000149011612, -0.09000000357627869, 0.09000000357627869, 0.12999999523162842,
                   -0.004643917083740234, -0.18872404098510742, -0.17000000178813934, -0.17000000178813934]

        angles4 = [-0.3497939109802246, 0.7255401611328125, -0.8636841773986816, -0.4049339294433594,
                   1.8238691091537476, -0.3941960334777832, -0.7777800559997559, 0.7439479827880859,
                   0.20713186264038086, -1.8238691091537476, 0.17184996604919434, -0.01683211326599121,
                   -0.09232791513204575, 0.06898808479309082, -0.10426998138427734, 0.13341593742370605,
                   -0.4141380786895752, -0.09232791513204575, 0.07520794868469238, 0.3467259407043457,
                   -0.004643917083740234, -0.18872404098510742, -0.1840381622314453, -0.1840381622314453]

        angles5 = [0.16716408729553223, 0.08739614486694336, -1.2533202171325684, -0.07972598075866699,
                   1.8238691091537476, 0.21173405647277832, -0.2915019989013672, 0.7546861171722412,
                   0.15497589111328125, -0.5890979766845703, 0.17184996604919434, -0.01683211326599121,
                   -0.09232791513204575, 0.06898808479309082, -0.10426998138427734, 0.1318819522857666,
                   -0.4141380786895752, -0.09232791513204575, 0.06600403785705566, 0.3467259407043457,
                   -0.004643917083740234, -0.18872404098510742, -0.1840381622314453, -0.1840381622314453]

        angles6 = [-0.04606199264526367, 0.4632260799407959, -1.5616540908813477, -0.28067994117736816,
                   -0.30223989486694336, 0.1733839511871338, -0.5737578868865967, 1.2240900993347168,
                   0.3037738800048828, 1.0185341835021973, 0.06600403785705566, 0.4096200466156006,
                   -0.09232791513204575, 0.14262008666992188, -0.3420400619506836, 0.13341593742370605,
                   -0.047512054443359375, -0.09232791513204575, 0.08748006820678711, 0.17798590660095215,
                   -0.004643917083740234, -0.18872404098510742, -0.16256213188171387, -0.16256213188171387]
        angles7 = [-1.5877318382263184, 0.4693620204925537, -0.902033805847168, -0.038308143615722656,
                   0.5429940223693848, -1.5477640628814697, -0.23321008682250977, 0.3451080322265625,
                   0.9480538368225098, -0.27922987937927246, 0.029187917709350586, 0.5461459159851074,
                   -0.09054803848266602, 0.13801813125610352, -0.3977605402469635, 0.14722204208374023,
                   -0.04444408416748047, -0.09232791513204575, 0.08748006820678711, 0.23014187812805176,
                   -0.015382051467895508, -0.20406389236450195, -0.10426998138427734, -0.10426998138427734]
        angles8 = [-1.3837099075317383, 0.06285214424133301, -0.4847860336303711, -0.7761621475219727,
                   0.5629360675811768, -1.5554341077804565, -0.6734678745269775, 0.45095396041870117,
                   0.052197933197021484, -0.30223989486694336, 0.17184996604919434, 0.09668397903442383,
                   -0.09232791513204575, 0.11347413063049316, -0.19937801361083984, 0.15335798263549805,
                   -0.4310121536254883, -0.09232791513204575, 0.11816000938415527, 0.3728039264678955,
                   -0.02151799201965332, -0.18719005584716797, -0.17176604270935059, -0.17176604270935059]

        angles9 = [0.0030260086059570312, 0.05518198013305664, -0.29610395431518555, -0.6273641586303711,
                   0.39573001861572266, -0.20858192443847656, -0.5369420051574707, 0.45555615425109863,
                   0.05526590347290039, -0.3436579704284668, 0.17184996604919434, 0.09668397903442383,
                   -0.09232791513204575, 0.11347413063049316, -0.19937801361083984, 0.15335798263549805,
                   -0.4310121536254883, -0.09232791513204575, 0.11816000938415527, 0.3728039264678955,
                   -0.5338740348815918, -0.2316758632659912, -0.17176604270935059, -0.17176604270935059]
        angles10 = [-0.774712085723877, 0.022968053817749023, -0.32218194007873535, -0.2239220142364502,
                    0.038308143615722656, 0.5308060646057129, -0.3758718967437744, 0.477031946182251,
                    0.05066394805908203, -0.2915019989013672, 0.17184996604919434, 0.09668397903442383,
                    -0.09232791513204575, 0.11347413063049316, -0.19937801361083984, 0.15335798263549805,
                    -0.4310121536254883, -0.09232791513204575, 0.11816000938415527, 0.3728039264678955,
                    -0.5338740348815918, -0.2316758632659912, -0.17176604270935059, -0.17176604270935059]
        angles11 = [0.20244598388671875, -0.2316758632659912, -0.32524991035461426, -0.07819199562072754,
                    0.17330002784729004, -0.7194039821624756, -0.36206603050231934, 0.46476006507873535,
                    0.04452800750732422, -0.6213119029998779, 0.17184996604919434, 0.12582993507385254,
                    -0.09208202362060547, 0.11347413063049316, -0.21625208854675293, 0.15335798263549805,
                    -0.4310121536254883, -0.09232791513204575, 0.11816000938415527, 0.3728039264678955,
                    -0.5338740348815918, -0.2316758632659912, -0.17176604270935059, -0.17176604270935059]
        angles12 = [-0.4418339729309082, 0.37885594367980957, 1.610658049583435, -0.07972598075866699,
                    -1.5892658233642578, 0.5415439605712891, 0.3141592741012573, 0.5920820236206055,
                    0.21480202674865723, -0.4126880168914795, 0.17184996604919434, 0.48325204849243164,
                    -0.09208202362060547, 0.1349501609802246, -0.3941960334777832, 0.2438640594482422,
                    -0.16563010215759277, -0.09232791513204575, 0.08901405334472656, 0.2838320732116699,
                    0.48163414001464844, -0.09821796417236328, -0.13034796714782715, -0.13034796714782715]
        angles13 = [0.4463520050048828, 0.34664201736450195, 1.610658049583435, -0.04904603958129883,
                    -1.756472110748291, -0.5276541709899902, 0.08893013000488281, 0.6933259963989258,
                    0.2286078929901123, -0.337522029876709, 0.17184996604919434, 0.48325204849243164,
                    -0.09208202362060547, 0.1349501609802246, -0.3941960334777832, 0.2438640594482422,
                    -0.16563010215759277, -0.09232791513204575, 0.08901405334472656, 0.2838320732116699,
                    0.3742539882659912, -0.09361600875854492, -0.13034796714782715, -0.13034796714782715]

        angles14 = [0.3021559715270996, 0.6273641586303711, 0.6258301734924316, -0.3052239418029785,
                    -0.9587922096252441, 0.7072160243988037, -0.6427879333496094, 0.8467259407043457,
                    0.5921659469604492, -0.6550600528717041, 0.17184996604919434, 0.32831788063049316,
                    -0.08901405334472656, 0.1088719367980957, -0.3313021659851074, 0.23619413375854492,
                    -0.32056403160095215, -0.09232791513204575, 0.033789873123168945, 0.3605320453643799,
                    -0.01691603660583496, -0.1043539047241211, -0.17330002784729004, -0.17330002784729004]

        angles15 = [1.0016601085662842, 0.4371480941772461, -0.8989658355712891, -1.1842060089111328,
                    -0.2945699691772461, 1.3070101737976074, -0.5538160800933838, 1.1734681129455566, 1.469614028930664,
                    0.0858621597290039, 0.17184996604919434, 0.32831788063049316, -0.08901405334472656,
                    0.1088719367980957, -0.3313021659851074, 0.23619413375854492, -0.32056403160095215,
                    -0.09232791513204575, 0.033789873123168945, 0.3605320453643799, -0.01691603660583496,
                    -0.1043539047241211, -0.17330002784729004, -0.17330002784729004]
        angles16 = [1.0016601085662842, 0.4371480941772461, -0.8989658355712891, -1.1842060089111328,
                    -0.2945699691772461, 0.7977218627929688, -0.40041589736938477, 1.0630199909210205,
                    1.239513874053955, 1.2378960847854614, 0.17184996604919434, 0.32831788063049316,
                    -0.08901405334472656, 0.1088719367980957, -0.3313021659851074, 0.23619413375854492,
                    -0.32056403160095215, -0.09232791513204575, 0.033789873123168945, 0.3605320453643799,
                    -0.14883995056152344, 0.32056403160095215, -0.17330002784729004, -0.17330002784729004]
        angles17 = [1.1029040813446045, 0.15642595291137695, -0.8621501922607422, -1.3544800281524658,
                    -0.30223989486694336, 0.3114440441131592, -0.7961878776550293, 1.213352084159851,
                    1.0937838554382324, 1.2409640550613403, 0.17184996604919434, 0.32831788063049316,
                    -0.08901405334472656, 0.1088719367980957, -0.3313021659851074, 0.23619413375854492,
                    -0.32056403160095215, -0.09232791513204575, 0.033789873123168945, 0.3605320453643799,
                    -0.561486005783081, 0.024502038955688477, -0.17330002784729004, -0.17330002784729004]
        angles18 = [1.1197781562805176, -0.09821796417236328, -0.771643877029419, -1.5201520919799805,
                    -0.4587080478668213, -0.3251659870147705, -1.1275320053100586, 1.2471001148223877,
                    0.7470998764038086, 1.2639740705490112, 0.17184996604919434, 0.32831788063049316,
                    -0.08901405334472656, 0.1088719367980957, -0.3313021659851074, 0.23619413375854492,
                    -0.32056403160095215, -0.09232791513204575, 0.033789873123168945, 0.3605320453643799,
                    -1.018618106842041, -0.44908607006073, -0.17330002784729004, -0.17330002784729004]
        angles19 = [0.4172060489654541, 0.5491299629211426, -1.5831298828125, -0.9188239574432373, -0.6857399940490723,
                    1.035491943359375, -0.023051977157592773, 1.0323400497436523, 1.5446163415908813,
                    0.34664201736450195, 0.17184996604919434, 0.32831788063049316, -0.08901405334472656,
                    0.1088719367980957, -0.3313021659851074, 0.23619413375854492, -0.32056403160095215,
                    -0.09232791513204575, 0.033789873123168945, 0.3605320453643799, 0.5322561264038086,
                    -0.1365680694580078, -0.17330002784729004, -0.17330002784729004]
        angles20 = [-0.5338740348815918, 0.5890140533447266, -1.619946002960205, -0.40646815299987793,
                    -0.8360719680786133, 1.0032777786254883, 0.3141592741012573, 0.7055981159210205, 1.5446163415908813,
                    0.7623560428619385, 0.17184996604919434, 0.32831788063049316, -0.08901405334472656,
                    0.1088719367980957, -0.3313021659851074, 0.23619413375854492, -0.32056403160095215,
                    -0.09232791513204575, 0.033789873123168945, 0.3605320453643799, 0.8467259407043457,
                    -0.5060315132141113, -0.17330002784729004, -0.17330002784729004]
        angles21 = [2.057982921600342, 0.7597230672836304, -0.8731288313865662, -1.5232244729995728,
                    -0.16264605522155762, 1.9845293760299683, -0.7604108452796936, 0.8513105511665344,
                    1.544303059577942, 0.11347413063049316, 0.17184996604919434, 0.32831788063049316,
                    -0.08901405334472656, 0.1088719367980957, -0.3313021659851074, 0.23619413375854492,
                    -0.32056403160095215, -0.09232791513204575, 0.033789873123168945, 0.3605320453643799,
                    -0.004643917083740234, 0.4494199752807617, -0.17330002784729004, -0.17330002784729004]
        angles22 = [-0.8268680572509766, 0.6150920391082764, -1.6322178840637207, -0.2960200309753418,
                    0.7838320732116699, 1.9845293760299683, -0.7604108452796936, 0.8513105511665344, 1.544303059577942,
                    0.11347413063049316, 0.17491793632507324, 0.5936999320983887, -0.08901405334472656,
                    0.1257460117340088, -0.3977605402469635, 0.30062198638916016, -0.1318819522857666,
                    -0.09199810028076172, 0.018450021743774414, 0.277695894241333, 0.5475959777832031,
                    -0.42649388313293457, -0.13955211639404297, -0.13955211639404297]
        angles23 = [-0.5553500652313232, 0.550663948059082, -0.9664621353149414, -1.0599520206451416,
                    0.7163360118865967, 1.9845293760299683, -0.7604108452796936, 0.8513105511665344, 1.544303059577942,
                    0.11347413063049316, 0.17491793632507324, 0.5936999320983887, -0.08901405334472656,
                    0.1257460117340088, -0.3977605402469635, 0.30062198638916016, -0.1318819522857666,
                    -0.09199810028076172, 0.018450021743774414, 0.277695894241333, 0.22852396965026855,
                    -0.507796049118042, -0.13955211639404297, -0.13955211639404297]
        angles24 = [1.9496721029281616, 0.7485499382019043, -0.7854499816894531, -1.5232200622558594,
                    -0.21173405647277832, -0.7945699691772461, -0.8728880882263184, 1.221022129058838,
                    0.24241399765014648, -1.038559913635254, 0.1795198917388916, 0.09054803848266602,
                    -0.08901405334472656, 0.11040592193603516, -0.2592041492462158, 0.18557214736938477,
                    -0.5997519493103027, -0.09199810028076172, 0.08287787437438965, 0.3978999853134155,
                    -0.8774900436401367, -0.49180054664611816, -0.16102814674377441, -0.16102814674377441]
        angles25 = [1.9496721029281616, 0.7485499382019043, -0.7854499816894531, -1.5232200622558594,
                    -0.21173405647277832, -0.6488399505615234, -0.5967679023742676, 0.7715599536895752,
                    0.8836259841918945, -0.9541897773742676, 0.1795198917388916, 0.09054803848266602,
                    -0.08901405334472656, 0.11040592193603516, -0.2592041492462158, 0.18557214736938477,
                    -0.5997519493103027, -0.09199810028076172, 0.08287787437438965, 0.3978999853134155,
                    -0.3267838954925537, -0.5047280788421631, -0.16102814674377441, -0.16102814674377441]
        namess = list()
        times = list()
        keys = list()

        namess.append("HeadPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([-0.154976, -0.14884, 0.00149202, 0.0291041, 0.00149202, 0.0291041, 0.0444441, 0.0689882, 0.0689882,
                     0.0398422, 0.093532, 0.107338])

        namess.append("HeadYaw")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([-0.016916, -0.00617791, 0.38806, -0.389678, 0.38806, -0.389678, -0.0291878, -0.635118, -0.199461,
                     -0.046062, 0.432547, 0.00302602])

        namess.append("LAnklePitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([-0.509331, 0.0873961, 0.0873961, 0.0873961, 0.0873961, 0.0890141, 0.0843279, 0.0797259, 0.0797259,
                     0.0797259, 0.0812599, 0.0873961])

        namess.append("LAnkleRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [4.19617e-05, -0.131882, -0.124212, -0.124212, -0.124212, -0.121228, -0.124212, -0.124212, -0.124212,
             -0.125746, -0.125746, -0.12728])

        namess.append("LElbowRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [-1.00319, -1.0891, -0.921892, -1.07989, -0.921892, -1.20116, -1.36522, -1.34528, -1.34528, -1.35601,
             -1.38209, -1.36062])

        namess.append("LElbowYaw")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [-1.10299, -0.722556, -1.69972, -0.184122, -1.69972, -0.467829, -0.897433, -0.894364, -0.894364, -0.023052,
             -1.72119, -0.434165])

        namess.append("LHand")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([0.314, 0.314, 0.5796, 0.5972, 0.5796, 0.4352, 0.1472, 0.1464, 0.1464, 0.1668, 0.0576, 0.0728])

        namess.append("LHipPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [-0.052836, 0.101966, 0.107364, 0.108898, 0.107364, 0.106484, 0.1035, 0.1035, 0.1135, 0.111966, 0.131966,
             0.12583])

        namess.append("LHipRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.00464392, 0.0966839, 0.090548, 0.0951499, 0.090548, 0.0951499, 0.093616, 0.093616, 0.093616, 0.093616,
             0.093616, 0.099752])

        namess.append("LHipYawPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [4.19617e-05, -0.167164, -0.164096, -0.164096, -0.164096, -0.164096, -0.159494, -0.159494, -0.159494,
             -0.161028, -0.161028, -0.164096])

        namess.append("LKneePitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.84826, -0.0923279, -0.092082, -0.0890141, -0.092082, -0.0890141, -0.0923279, -0.0923279, -0.0923279,
             -0.090548, -0.090548, -0.0890141])

        namess.append("LShoulderPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [1.43578, 1.44652, 0.246933, 1.05535, 0.246933, 1.21037, 1.22869, 1.24403, 1.24403, -0.389678, 0.315962,
             0.934165])

        namess.append("LShoulderRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([0.831386, 0.269941, 0.57214, 0.153358, 0.57214, 0.306841, 0.15796, 0.161028, 0.161028, -0.154976,
                     0.0889301, 0.332836])

        namess.append("LWristYaw")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.095066, 0.0152981, -0.0598679, -0.656595, -0.0598679, 0.04913, 0.216252, 0.225456, 0.225456, -0.566089,
             0.291418, 0.547595])

        namess.append("RAnklePitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([-0.521518, 0.0966839, 0.0844118, 0.0890141, 0.0844118, 0.0890141, 0.092082, 0.0844118, 0.0844118,
                     0.0859461, 0.0859461, 0.0828778])

        namess.append("RAnkleRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([0.00310993, 0.128898, 0.12583, 0.121228, 0.12583, 0.121228, 0.128898, 0.128898, 0.128898, 0.128898,
                     0.128898, 0.12583])

        namess.append("RElbowRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([1.16742, 0.382009, 1.18429, 1.20116, 1.18429, 1.20116, 1.34383, 1.31775, 1.25792, 1.04623, 1.21037,
                     1.23491])

        namess.append("RElbowYaw")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.730143, 1.15506, 0.452487, 0.467829, 0.452487, 0.467829, 0.369652, 2.06165, 0.805309, 0.21932, -0.030722,
             0.0122299])

        namess.append("RHand")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([0.3064, 0.3064, 0.4248, 0.4352, 0.4248, 0.4352, 0.1752, 0.05, 0.05, 0.1932, 0.0644, 0.0572])

        namess.append("RHipPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [-0.059852, 0.101882, 0.108814, 0.106484, 0.108814, 0.106484, 0.103416, 0.103416, 0.113416, 0.113416,
             0.133416, 0.124212])

        namess.append("RHipRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.00617791, -0.107338, -0.101202, -0.107338, -0.101202, -0.0951499, -0.102736, -0.101202, -0.101202,
             -0.0996681, -0.0996681, -0.107338])

        namess.append("RHipYawPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [4.19617e-05, -0.167164, -0.164096, -0.164096, -0.164096, -0.164096, -0.159494, -0.159494, -0.159494,
             -0.161028, -0.161028, -0.164096])

        namess.append("RKneePitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.852946, -0.0889301, -0.0812599, -0.0843279, -0.0812599, -0.0890141, -0.0889301, -0.0889301, -0.0889301,
             -0.0873961, -0.0873961, -0.0923279])

        namess.append("RShoulderPitch")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [1.42053, 1.30087, 1.22724, 1.21037, 1.22724, 1.21037, -0.262272, -0.0383082, 1.126, 0.828401, 0.564555,
             0.590632])

        namess.append("RShoulderRoll")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append([-0.253151, -0.392746, -0.289967, -0.306841, -0.289967, -0.306841, 0.124212, -0.179519, -0.128898,
                     -0.142704, -0.0782759, -0.211735])

        namess.append("RWristYaw")
        times.append([1.6, 3.2, 4.84, 6.6, 8, 9.4, 11, 12.6, 14.2, 15.8, 17.4, 19])
        keys.append(
            [0.176367, -0.619779, -0.066004, -0.04913, -0.066004, -0.04913, -0.107422, -0.377407, -1.04623, -0.197927,
             -0.306841, -0.345191])


        nplay = MusicPlay(self.IPOne)
        nplay.start()

        isEnable = True
        supportLeg = "Legs"
        motionProxyOne.wbEnableBalanceConstraint(isEnable, supportLeg)

        motionProxyOne.setStiffnesses("Head", 1)

#        motionProxyOne.setAnges("HeadYaw", 0.0, 0.2)

        n = 0
        while n < 2:  # 手部动作
            n = n + 1
            motionProxyOne.setAngles(names, angles, 0.06)
            time.sleep(0.6)
            motionProxyOne.setAngles(names, angles1, 0.06)
            time.sleep(0.6)
            motionProxyOne.setAngles(names, angles2, 0.06)
            time.sleep(0.9)
            motionProxyOne.setAngles(names, angles3, 0.06)
            time.sleep(1.6)
#        motionProxyOne.setAngles(names, angles, 0.06)
#        time.sleep(0.6)
#        motionProxyOne.setAngles(names, angles1, 0.06)
#        time.sleep(0.6)
#        motionProxyOne.setAngles(names, angles2, 0.06)
#        time.sleep(1.6)

        while n < 5:  # 扭腰
            n = n + 1
            motionProxyOne.setAngles(names, angles4, 0.1)  # 扭腰
            time.sleep(0.7)
            motionProxyOne.setAngles(names, angles5, 0.1)
            time.sleep(0.7)
            motionProxyOne.setAngles(names, angles6, 0.1)
            time.sleep(1.2)
        motionProxyOne.setAngles(names, angles4, 0.1)
        time.sleep(0.7)
        motionProxyOne.setAngles(names, angles5, 0.1)
        time.sleep(0.7)
        motionProxyOne.post.openHand(["RHand", "LHand"])
        while n < 10:  # 挥手
            n = n + 1
            motionProxyOne.setAngles(names, angles7, 0.15)
            time.sleep(1.1)
            motionProxyOne.setAngles(names, angles8, 0.13)
            time.sleep(1.1)
        motionProxyOne.post.closeHand(["RHand", "LHand"])

        # 摇手
        motionProxyOne.setAngles(names, angles9, 0.18)
        time.sleep(1)
        motionProxyOne.setAngles(names, angles10, 0.18)
        time.sleep(0.9)
        motionProxyOne.setAngles(names, angles11, 0.18)
        time.sleep(1)
        motionProxyOne.setAngles(names, angles12, 0.18)
        time.sleep(1)
        motionProxyOne.setAngles(names, angles13, 0.18)
        time.sleep(1)
        motionProxyOne.setAngles(names, angles14, 0.18)
        time.sleep(0.9)

        motionProxyOne.setAngles(names, angles15, 0.18)
        time.sleep(0.6)
        #  摆手动作

        motionProxyOne.setAngles(names, angles16, 0.18)
        time.sleep(0.5)
        motionProxyOne.setAngles(names, angles17, 0.12)
        time.sleep(0.3)
        motionProxyOne.setAngles(names, angles18, 0.12)
        time.sleep(1.3)
        motionProxyOne.setAngles(names, angles17, 0.12)
        time.sleep(0.4)
        motionProxyOne.setAngles(names, angles16, 0.12)
        time.sleep(0.3)
        motionProxyOne.setAngles(names, angles15, 0.12)
        time.sleep(0.4)
        motionProxyOne.setAngles(names, angles19, 0.12)
        time.sleep(0.4)
        motionProxyOne.setAngles(names, angles20, 0.12)
        time.sleep(1.5)
        motionProxyOne.setAngles(names, angles19, 0.12)
        time.sleep(0.4)
        motionProxyOne.setAngles(names, angles15, 0.14)
        time.sleep(0.4)


        # 手臂上扬
        motionProxyOne.setAngles(names, angles21, 0.16)
        time.sleep(0.9)
        motionProxyOne.setAngles(names, angles22, 0.18)
        time.sleep(2.6)
        motionProxyOne.setAngles(names, angles23, 0.14)
        time.sleep(1.1)
        motionProxyOne.setAngles(names, angles22, 0.16)
        time.sleep(0.7)
        motionProxyOne.setAngles(names, angles21, 0.13)
        time.sleep(2.6)

        motionProxyOne.setAngles(names, angles24, 0.16)
        time.sleep(2.6)
        motionProxyOne.setAngles(names, angles25, 0.13)
        time.sleep(0.9)
        motionProxyOne.setAngles(names, angles24, 0.12)
        time.sleep(0.9)
        motionProxyOne.setAngles(names, angles21, 0.13)
        time.sleep(2.6)


        try:
            motion = ALProxy("ALMotion", self.IPOne, 9559)
            # motion = ALProxy("ALMotion")
            motion.angleInterpolation(namess, keys, times, True)
        except BaseException, err:
            print err