40623141 協同產品設計實習

玩家vs電腦 << Previous Next >> 程式優化

程式除錯

問題:

同時按下兩個鍵會造成衝突

解決方法 :

將兩桿子操作按鍵,使用try except分開寫成兩段程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
try:
if keyboard.is_pressed('v'):
vrep.simxSetJointTargetVelocity(clientID,BRev_handle,B_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('b'):
vrep.simxSetJointTargetVelocity(clientID,BRev_handle,R_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('z'):
vrep.simxSetJointTargetVelocity(clientID,BMo_handle,0.2,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('x'):
vrep.simxSetJointTargetVelocity(clientID,BMo_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('c'):
vrep.simxSetJointTargetVelocity(clientID,BMo_handle,-0.2,vrep.simx_opmode_oneshot_wait)
except:
break
try:
if keyboard.is_pressed('o'):
vrep.simxSetJointTargetVelocity(clientID,RRev_handle,R_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('p'):
vrep.simxSetJointTargetVelocity(clientID,RRev_handle,B_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('y'):
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0.2,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('u'):
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('i'):
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,-0.2,vrep.simx_opmode_oneshot_wait)
except:
break

玩家vs電腦 << Previous Next >> 程式優化