if EVENT_MODE == 1: devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) board = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % board.getVendorName() print "*** Device name: %s" % board.getDeviceName() running = 1 print "Adjust min-max light value, press the switch when done." while(running): for i in range(0, 3): light = board.getLight(i) running = not board.getSwitch() if light > maxLight[i]: maxLight[i] = light if light < minLight[i]: minLight[i] = light ########################################################### displayMode = 1 # 0 = exit, 1 = welcome, 2 = play, 3 = game over pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption(TITLE) clock = pygame.time.Clock() pygame.mixer.music.load("src/sounds/BackgroundSong.wav") pygame.mixer.music.set_volume(0.4)
print "*** Device name: %s" % b.getDeviceName() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) round = 0 oldLight = False newLight = False oldSwitch = False newSwitch = False checkVal = randrange(1000) # Run after server start s.sendall('JoinGame|' + b.getDeviceName() + '|' + str(checkVal) + '|' + b.getVendorName()) while True : try : newLight = b.getLight() < 400; if newLight != oldLight : s.sendall('TurnShipToggle|' + str(b.getDeviceName()) + '|' + str(checkVal) + '|' + (b.getVendorName())) newSwitch = b.getSwitch() if newSwitch != oldSwitch : if newSwitch : s.sendall('ShootingToggle|' + str(b.getDeviceName()) + '|' + str(checkVal) + '|' + str(b.getVendorName())) oldSwitch = newSwitch print "Round %d ----> Switch state: %-8s | Light value: %d" % (round, b.getSwitch(), b.getLight()) round += 1 except : print 'bomb' data = s.recv(1024) s.close() print 'Received', repr(data)