本文整理汇总了Python中car.Car.right方法的典型用法代码示例。如果您正苦于以下问题:Python Car.right方法的具体用法?Python Car.right怎么用?Python Car.right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类car.Car
的用法示例。
在下文中一共展示了Car.right方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mainloop
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import right [as 别名]
def mainloop(self, port):
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sck.bind(('0.0.0.0', port))
sck.listen(1)
sck.setblocking(0)
dt = datetime.datetime.now()
idle = 0
while True:
try:
client, addr = sck.accept()
client.setblocking(0)
except socket.error:
time.sleep(0.1)
continue
while True:
try:
t = client.recv(1)
if len(t) == 1: char = ord(t)
elif len(t) == 0:
break
except socket.error:
char = -1
if char != -1:
if char == ord('d'): Car.right()
elif char == ord('a'): Car.left()
elif char == ord('w'):
if True or not bb.is_blocked():
Car.up()
else:
Car.stop()
elif char == ord('s'): Car.down()
elif char == ord('q'): Car.stop()
dt = datetime.datetime.now()
idle = 0
elif idle >= 2:
if Car.moving:
Car.stop()
else:
time.sleep(0.1)
else:
idle += 1
time.sleep(0.1)