Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/game.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-04-17 03:24:01 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2012-04-20 16:10:58 (GMT)
commit3c8e86e8ed4445457be91f2ebaca49ee0dc4f07b (patch)
tree3da5e04e3ef4b0f8dd8a289de9d1be1dfd8bc4fd /game.py
parentd4ab2f7d2db24319de36b29e455f7d30c3f8a90c (diff)
Collaboration: allow multiple users in the same XO
This is a workaround to the problem with the real nick on a jabber server[1]. Now, we are using the unique identifier (mesh.my_handle or event.handle) for each player in the game plus a "-%d" at the end of the uid. This value (Player.uid) is added only when the Activity is shared otherwise this field is None. This new workaround allow to distinguish between many users (up to 3) for each XO laptop -using the gamepad keys. [1] http://dev.laptop.org/ticket/10750 Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Rafael Ortiz <rafael@activitycentral.com>
Diffstat (limited to 'game.py')
-rw-r--r--game.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/game.py b/game.py
index b6319b1..85f6d7f 100644
--- a/game.py
+++ b/game.py
@@ -33,7 +33,9 @@ import pygame
import olpcgames
import logging
+logging.basicConfig()
log = logging.getLogger('Maze')
+log.setLevel(logging.DEBUG)
import olpcgames.pausescreen as pausescreen
import olpcgames.mesh as mesh
@@ -195,7 +197,7 @@ class MazeGame:
if len(self.remoteplayers) > 0:
mesh.broadcast("move:%s,%d,%d,%d,%d" % \
- (player.nick,
+ (player.uid,
player.position[0],
player.position[1],
player.direction[0],
@@ -245,6 +247,7 @@ class MazeGame:
elif event.type == mesh.CONNECT:
log.debug("Connected to the mesh")
+
elif event.type == mesh.PARTICIPANT_ADD:
log.debug('mesh.PARTICIPANT_ADD')
@@ -252,10 +255,19 @@ class MazeGame:
if event.handle == mesh.my_handle():
log.debug("Me: %s - %s", buddy.props.nick,
buddy.props.color)
+ # README: this is a workaround to use an unique
+ # identifier instead the nick of the buddy
+ # http://dev.laptop.org/ticket/10750
+ count = ''
+ for i, player in enumerate(self.localplayers):
+ if i > 0:
+ count = '-%d' % i
+ player.uid = mesh.my_handle() + count
else:
log.debug("Join: %s - %s", buddy.props.nick,
buddy.props.color)
player = Player(buddy)
+ player.uid = event.handle
self.remoteplayers[event.handle] = player
self.allplayers.append(player)
self.allplayers.extend(player.bonusPlayers())
@@ -269,8 +281,9 @@ class MazeGame:
self.maze.width, self.maze.height))
for player in self.localplayers:
if not player.hidden:
- mesh.send_to(event.handle, "move:%s,%d,%d,%d,%d" % \
- (player.nick,
+ mesh.send_to(event.handle,
+ "move:%s,%d,%d,%d,%d" % \
+ (player.uid,
player.position[0],
player.position[1],
player.direction[0],
@@ -367,7 +380,7 @@ class MazeGame:
return
if message.startswith("move:"):
# a player has moved
- nick, x, y, dx, dy = message[5:].split(",")[:5]
+ uid, x, y, dx, dy = message[5:].split(",")[:5]
# README: this function (player.bonusPlayer) sometimes
# returns None and the activity doesn't move the players.
@@ -377,7 +390,7 @@ class MazeGame:
# So, we have set remote users with this kind of name but
# we receive the reald child's name in the mesh message
- # player = player.bonusPlayer(nick)
+ player = player.bonusPlayer(uid)
player.hidden = False
self.markPointDirty(player.position)
@@ -400,8 +413,8 @@ class MazeGame:
self.reset()
elif message.startswith("finish:"):
# someone finished the maze
- nick, elapsed = message[7:].split(",")[:2]
- player = player.bonusPlayer(nick)
+ uid, elapsed = message[7:].split(",")[:2]
+ player = player.bonusPlayer(uid)
player.elapsed = float(elapsed)
self.markPointDirty(player.position)
else: