From 919f5eb3f0b24e25f7de56958a43c16d0b70abd9 Mon Sep 17 00:00:00 2001 From: schneider Date: Thu, 15 Dec 2011 19:56:00 +0100 Subject: [PATCH] remote: renamed simpletest to testgame --- tools/game/testgame.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tools/game/testgame.py diff --git a/tools/game/testgame.py b/tools/game/testgame.py new file mode 100644 index 0000000..54e608a --- /dev/null +++ b/tools/game/testgame.py @@ -0,0 +1,39 @@ +import r0ketrem0te.game +import r0ketrem0te.bridge +import r0ketrem0te.packets +import time +import Queue + +maxplayer = 2 +players = {} + +def receivedPacket(packet): + if isinstance(packet, r0ketrem0te.packets.Join): + # flags = 1: join ok + # flags = 0: join not ok + flags = 0 + if len(players) < maxplayer: + flags = 1 + players[packet.id] = 10 + ack = r0ketrem0te.packets.Ack(packet.id, packet.ctr, flags) + qp = r0ketrem0te.bridge.QueuePacket(game.channel, game.playermac, False, ack) + game.bridge.putInQueue(queue, qp) + elif packet.id in players: + players[packet.id] = 10 + +game = r0ketrem0te.game.Game('/dev/ttyACM0', "testgame", 83, 81, (1,2,3,2,1)) + +queue = Queue.Queue() +game.bridge.registerQueue(queue) +game.bridge.registerCallback(receivedPacket) + +while True: + time.sleep(1) + 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]