2011-12-15 18:09:05 +00:00
|
|
|
import r0ketrem0te.game
|
|
|
|
import r0ketrem0te.bridge
|
2011-12-14 16:59:32 +00:00
|
|
|
import r0ketrem0te.packets
|
2011-12-12 17:02:24 +00:00
|
|
|
import time
|
2011-12-14 16:59:32 +00:00
|
|
|
import Queue
|
|
|
|
|
2011-12-15 18:55:20 +00:00
|
|
|
maxplayer = 2
|
|
|
|
players = {}
|
|
|
|
|
2011-12-15 18:09:05 +00:00
|
|
|
def receivedPacket(packet):
|
|
|
|
if isinstance(packet, r0ketrem0te.packets.Join):
|
|
|
|
# flags = 1: join ok
|
|
|
|
# flags = 0: join not ok
|
2011-12-15 18:55:20 +00:00
|
|
|
flags = 0
|
|
|
|
if len(players) < maxplayer:
|
|
|
|
flags = 1
|
|
|
|
players[packet.id] = 10
|
|
|
|
ack = r0ketrem0te.packets.Ack(packet.id, packet.ctr, flags)
|
2011-12-15 18:09:05 +00:00
|
|
|
qp = r0ketrem0te.bridge.QueuePacket(game.channel, game.playermac, False, ack)
|
|
|
|
game.bridge.putInQueue(queue, qp)
|
2011-12-15 18:55:20 +00:00
|
|
|
elif packet.id in players:
|
|
|
|
players[packet.id] = 10
|
|
|
|
|
2011-12-15 18:09:05 +00:00
|
|
|
game = r0ketrem0te.game.Game('/dev/ttyACM0', "testgame", 83, 81, (1,2,3,2,1))
|
2011-12-14 16:59:32 +00:00
|
|
|
|
2011-12-15 18:09:05 +00:00
|
|
|
queue = Queue.Queue()
|
|
|
|
game.bridge.registerQueue(queue)
|
|
|
|
game.bridge.registerCallback(receivedPacket)
|
2011-12-12 17:02:24 +00:00
|
|
|
|
|
|
|
while True:
|
2011-12-15 18:09:05 +00:00
|
|
|
time.sleep(1)
|
2011-12-15 18:55:20 +00:00
|
|
|
toremove = []
|
|
|
|
for player in players:
|
|
|
|
players[player]-=1
|
|
|
|
if players[player] == 0:
|
|
|
|
toremove.append(player)
|
|
|
|
for player in toremove:
|
|
|
|
print "removing player", player
|
|
|
|
del players[player]
|