diff options
-rw-r--r-- | activity/activity-memorize.svg (renamed from activity/activity-memosono.svg) | 0 | ||||
-rwxr-xr-x | cardtable.py | 18 | ||||
-rwxr-xr-x | game.py | 89 | ||||
-rw-r--r--[-rwxr-xr-x] | games/addition/addition.mem | 47 | ||||
-rw-r--r--[-rwxr-xr-x] | games/drumgit/drumgit.mem | 29 | ||||
-rwxr-xr-x | games/letters1/letters1.mem | 48 | ||||
-rwxr-xr-x | games/letters2/letters2.mem | 49 | ||||
-rwxr-xr-x | games/numbers/numbers.mem | 25 | ||||
-rwxr-xr-x | games/phonemes/phonemes.mem | 32 | ||||
-rw-r--r-- | memorize.dtd | 14 | ||||
-rwxr-xr-x | memorizetoolbar.py | 2 | ||||
-rw-r--r-- | messenger.py | 20 | ||||
-rw-r--r-- | misc/addition.mem | 23 | ||||
-rw-r--r-- | misc/drumgit.mem | 24 | ||||
-rw-r--r-- | model.py | 253 | ||||
-rwxr-xr-x | scoreboard.py | 3 |
16 files changed, 382 insertions, 294 deletions
diff --git a/activity/activity-memosono.svg b/activity/activity-memorize.svg index 5a5bf83..5a5bf83 100644 --- a/activity/activity-memosono.svg +++ b/activity/activity-memorize.svg diff --git a/cardtable.py b/cardtable.py index 5ce326d..dbde177 100755 --- a/cardtable.py +++ b/cardtable.py @@ -63,7 +63,7 @@ class CardTable(gtk.EventBox): self.table_positions = {} # Build the table - if data['divided']=='True': + if data['divided']=='1': text1 = str(self.data['face1']) text2 = str(self.data['face2']) else: @@ -71,24 +71,24 @@ class CardTable(gtk.EventBox): text2 = str(self.data['face']) buffer_card_1 = svgcard.SvgCard(-1, {'front_border':{'opacity':'0'}, 'front_h_border':{'opacity':'0.5'}, 'back_text':{'card_text':text1}}, {}, None, self.card_size) buffer_card_2 = svgcard.SvgCard(-1, {'front_border':{'opacity':'0'}, 'front_h_border':{'opacity':'0.5'}, 'back_text':{'card_text':text2}}, {}, None, self.card_size) - - self.game_dir = os.path.join(os.path.dirname(__file__), 'games') + x = 0 y = 0 id = 0 - for card in self.cards_data: - if card[1] <> '': - jpg = os.path.join(self.game_dir, self.data['game_name']+'/images/'+str(card[1])) + + for card in self.cards_data: + if card.get('img', None): + jpg = card['img'] else: jpg = None props = {} props['front_border'] = {'opacity':'1'} props['front_h_border'] ={'opacity':'1'} - props['front_text']= {'card_text':card[3], 'card_line1':card[4], 'card_line2':card[5], 'card_line3':card[6], 'card_line4':card[7]} + props['front_text']= {'card_text':card.get('char', ''), 'card_line1':'', 'card_line2':'', 'card_line3':'', 'card_line4':''} - if card[0]== '1': + if card['ab']== 'a': buffer_card = buffer_card_1 - else: + elif card['ab']== 'b': buffer_card = buffer_card_2 card = svgcard.SvgCard(id, props, buffer_card.get_cache(), jpg, self.card_size) @@ -29,6 +29,8 @@ from dbus.gobject_service import ExportedGObject import gobject +from model import Model + _logger = logging.getLogger('memorize-activity') SERVICE = "org.laptop.Memorize" @@ -68,13 +70,16 @@ class MemorizeGame(gobject.GObject): self.game_dir = os.path.join(os.path.dirname(__file__), 'games') self.messenger = None self.sentitive = True - - def load_game(self, game_name, size): - tuple = self.read_config(game_name, size) - self.data = tuple[0] - self.grid = tuple[1] - self.data['running'] = 'False' - self.emit('load_game', self.data, self.grid) + self.model = Model(os.path.dirname(__file__)) + + def load_game(self, game_name, size): + if self.model.read(game_name) == 0: + self.model.def_grid(size) + self.model.data['running'] = 'False' + logging.debug(' Read setup file %s: %s '%(game_name, self.model.grid)) + self.emit('load_game', self.model.data, self.model.grid) + else: + logging.error(' Reading setup file %s'%game_name) def add_buddy(self, buddy, score = 0): _logger.debug('Buddy %r was added to game', buddy.props.nick) @@ -87,11 +92,11 @@ class MemorizeGame(gobject.GObject): self.change_turn() def rem_buddy(self, buddy): - _logger.debug('Buddy %r was removed to game', buddy.props.nick) + _logger.debug('Buddy %r was removed from game', buddy.props.nick) index = self.players.index(buddy) del self.players[index] del (self.players_score[buddy]) - if self.current_player == buddy and len(self.players) <> 0: + if self.current_player == buddy and len(self.players) >= 2: ### fix from <> 0 self.change_turn() self.emit('rem_buddy', buddy) @@ -111,50 +116,50 @@ class MemorizeGame(gobject.GObject): return # Handle groups if needed - if self.data['divided'] == 'True': - if self.last_flipped == -1 and id >= (len(self.grid)/2): + if self.model.data['divided'] == '1': + if self.last_flipped == -1 and id >= (len(self.model.grid)/2): return - if self.last_flipped <> -1 and id < (len(self.grid)/2): + if self.last_flipped <> -1 and id < (len(self.model.grid)/2): return - self.data['running'] = 'True' + self.model.data['running'] = 'True' # First card case if self.last_flipped == -1: self.last_flipped = id - self.grid[id][8] = 1 + self.model.grid[id]['state'] = '1' self.emit('flip-card', id) if not signal: self.emit('flip-card-signal', id) - if self.data['divided'] == 'True': + if self.model.data['divided'] == '1': self.card_highlighted(widget, -1, False) - # Pair matched - elif self.grid[self.last_flipped][-1] == self.grid[id][-1]: + # Pair matched + elif self.model.grid[self.last_flipped]['pairkey'] == self.model.grid[id]['pairkey']: stroke_color, fill_color = self.current_player.props.color.split(',') self.emit('set-border', id, stroke_color, fill_color) self.emit('set-border', self.last_flipped, stroke_color, fill_color) self.increase_point(self.current_player) - self.grid[id][8] = 1 + self.model.grid[id]['state'] = '1' self.emit('flip-card', id) - if self.data['divided'] == 'True': + if self.model.data['divided'] == '1': self.card_highlighted(widget, -1, False) if not signal: self.emit('flip-card-signal', id) self.last_flipped = -1 # Pair don't match - elif self.grid[self.last_flipped][-1] <> self.grid[id][-1]: + elif self.model.grid[self.last_flipped]['pairkey'] != self.model.grid[id]['pairkey']: self.emit('flip-card', id) if not signal: self.emit('flip-card-signal', id) - self.grid[id][8] = 1 - time.sleep(2) + self.model.grid[id]['state'] = '1' + time.sleep(2) ### gobject.timeout() here? self.emit('flop-card', id) - self.grid[id][8] = 0 + self.model.grid[id]['state'] = '0' self.emit('flop-card', self.last_flipped) - if self.data['divided'] == 'True': + if self.model.data['divided'] == '1': self.card_highlighted(widget, -1, False) # self.emit('highlight-card', id, True) - self.grid[self.last_flipped][8] = 0 + self.model.grid[self.last_flipped]['state'] = '0' self.last_flipped = -1 self.change_turn() @@ -166,13 +171,13 @@ class MemorizeGame(gobject.GObject): if not self.sentitive: return - if self.data['divided'] == 'True': - if self.last_flipped == -1 and id >= (len(self.grid)/2): + if self.model.data['divided'] == '1': + if self.last_flipped == -1 and id >= (len(self.model.grid)/2): return - if self.last_flipped <> -1 and id < (len(self.grid)/2): + if self.last_flipped <> -1 and id < (len(self.model.grid)/2): return self.emit('highlight-card', self.last_highlight, False) - if mouse and self.grid[id][8]==0: + if mouse and self.model.grid[id]['state']=='0': self.emit('highlight-card', id, True) if not mouse: self.emit('highlight-card', id, True) @@ -182,8 +187,8 @@ class MemorizeGame(gobject.GObject): def increase_point(self, buddy): self.players_score[buddy] += 1 self.emit('increase-score', buddy) - - def read_config(self, game_name, size = 100): + + def read_config2(self, game_name, size = 100): filename = os.path.join(self.game_dir, game_name +'/'+game_name+'.mem') # seed = random.randint(0, 14567) temp1 = [] @@ -227,7 +232,7 @@ class MemorizeGame(gobject.GObject): fd.close() # Shuffle cards order - if data['divided']=='True': + if data['divided']==1: random.shuffle(temp1) random.shuffle(temp2) temp1.extend(temp2) @@ -238,21 +243,21 @@ class MemorizeGame(gobject.GObject): return data, temp1 def get_grid(self): - return self.grid + return self.model.grid def get_data(self): - return self.data + return self.model.data def change_game(self, game_name, size): - tuple = self.read_config(game_name, size) - data = tuple[0] - grid = tuple[1] - self.load_remote(grid, data, False) - + if self.model.read(game_name) == 0: + self.model.def_grid(size) + self.load_remote(self.model.grid, self.model.data, False) + else: + logging.error(' Reading setup file %s'%game_name) def load_remote(self, grid, data, signal = False): - self.grid = grid - self.data = data + self.model.grid = grid + self.model.data = data self.emit('reset_scoreboard') self.emit('change_game', self.get_data(), self.get_grid()) if not signal: @@ -263,7 +268,7 @@ class MemorizeGame(gobject.GObject): self.last_flipped = -1 self.last_highlight = 1 self.change_turn() - self.data['running'] = 'False' + self.model.data['running'] = 'False' def set_messenger(self, messenger): self.messenger = messenger diff --git a/games/addition/addition.mem b/games/addition/addition.mem index 9e41bcc..8d1f0eb 100755..100644 --- a/games/addition/addition.mem +++ b/games/addition/addition.mem @@ -1,24 +1,23 @@ -game_name=addition -score_sound=score.wav -win_sound=score.wav -divided=false -face= -# Cards -,,,,,,1+1,,,,,2,,,, -,,,,,,1+2,,,,,3,,,, -,,,,,,2+2,,,,,4,,,, -,,,,,,2+3,,,,,5,,,, -,,,,,,3+3,,,,,6,,,, -,,,,,,3+4,,,,,7,,,, -,,,,,,4+4,,,,,8,,,, -,,,,,,4+5,,,,,9,,,, -,,,,,,5+5,,,,,10,,,, -,,,,,,5+6,,,,,11,,,, -,,,,,,6+6,,,,,12,,,, -,,,,,,6+7,,,,,13,,,, -,,,,,,7+7,,,,,14,,,, -,,,,,,7+8,,,,,15,,,, -,,,,,,8+8,,,,,16,,,, -,,,,,,8+9,,,,,17,,,, -,,,,,,9+9,,,,,18,,,, -,,,,,,10+9,,,,,19,,,,
\ No newline at end of file +<?xml version="1.0"?> +<memorize name="addition" scoresnd="score.wav" winsnd="win.wav" divided="0" > + + <pair achar="1+1" bchar="2" bcharalign="2" /> + <pair achar="1+2" bchar="3" /> + <pair achar="2+2" bchar="4" /> + <pair achar="2+3" bchar="5" /> + <pair achar="3+3" bchar="6" /> + <pair achar="3+4" bchar="7" /> + <pair achar="4+4" acharalign="4" bchar="8" /> + <pair achar="4+5" bchar="9" /> + <pair achar="5+5" bchar="10" /> + <pair achar="5+6" bchar="11" /> + <pair achar="6+6" bchar="12" bcharalign="3"/> + <pair achar="6+7" bchar="13" /> + <pair achar="7+7" bchar="14" /> + <pair achar="7+8" bchar="15" /> + <pair achar="8+8" bchar="16" /> + <pair achar="8+9" bchar="17" /> + <pair achar="9+9" bchar="18" /> + <pair achar="10+9" bchar="19" /> + +</memorize> diff --git a/games/drumgit/drumgit.mem b/games/drumgit/drumgit.mem index 482005a..a563341 100755..100644 --- a/games/drumgit/drumgit.mem +++ b/games/drumgit/drumgit.mem @@ -1,3 +1,29 @@ +<?xml version="1.0"?> +<memorize name="drumgit" scoresnd="score.wav" winsnd="win.wav" divided="0" > + + <pair aimg="drumkit1_b.jpg" asnd="beat1_a.aiff" bimg="drumkit1_b.jpg" bsnd="beat1_a.aiff" color="100" /> + <pair aimg="drumkit2_b.jpg" asnd="beat1_b.aiff" bimg="drumkit2_b.jpg" bsnd="beat1_b.aiff" color="100" /> + <pair aimg="drumkit3_b.jpg" asnd="beat1_c.aiff" bimg="drumkit3_b.jpg" bsnd="beat1_c.aiff" color="100" /> + <pair aimg="drumkit4_b.jpg" asnd="beat8.aiff" bimg="drumkit4_b.jpg" bsnd="beat8.aiff" color="100" /> + + <pair aimg="drumkit6_b.jpg" asnd="beat3.aiff" bimg="drumkit6_b.jpg" bsnd="beat3.aiff" color="100" /> + <pair aimg="drumkit7_b.jpg" asnd="beat4.aiff" bimg="drumkit7_b.jpg" bsnd="beat4.aiff" color="100" /> + <pair aimg="drumkit8_b.jpg" asnd="beat14.aiff" bimg="drumkit8_b.jpg" bsnd="beat14.aiff" color="100" /> + <pair aimg="drumkit9_b.jpg" asnd="beat6_2.aiff" bimg="drumkit9_b.jpg" bsnd="beat6_2.aiff" color="100" /> + + <pair aimg="guitar1_2.jpg" asnd="bending_a.aiff" bimg="guitar1_2.jpg" bsnd="bending_a.aiff" color="100" /> + <pair aimg="guitar2_2.jpg" asnd="bending_b.aiff" bimg="guitar2_2.jpg" bsnd="bending_b.aiff" color="100" /> + <pair aimg="guitar3_2.jpg" asnd="flashcomp2a.aiff" bimg="guitar3_2.jpg" bsnd="flashcomp2a.aiff" color="100" /> + <pair aimg="guitar4_2.jpg" asnd="flashcomp2b.aiff" bimg="guitar4_2.jpg" bsnd="flashcomp2b.aiff" color="100" /> + + <pair aimg="guitar5_2.jpg" asnd="gedaempft.aiff" bimg="guitar5_2.jpg" bsnd="gedaempft.aiff" color="100" /> + <pair aimg="guitar6_2.jpg" asnd="gedaempft.aiff" bimg="guitar6_2.jpg" bsnd="gedaempft.aiff" color="100" /> + <pair aimg="guitar7_2.jpg" asnd="ungedaempft.aiff" bimg="guitar7_2.jpg" bsnd="ungedaempft.aiff" color="100" /> + <pair aimg="guitar8_2.jpg" asnd="jimi4.aiff" bimg="guitar8_2.jpg" bsnd="jimi4.aiff" color="100" /> + +</memorize> + +<!-- game_name=drumgit score_sound=score.wav win_sound=score.wav @@ -27,4 +53,5 @@ face= ,guitar9_2.jpg,git_hit4.wav,,,,,,,guitar9_2.jpg,git_hit4.wav,,,,, ,guitar10_2.jpg,guitcello.wav,,,,,,,guitar10_2.jpg,guitcello.wav,,,,, ,guitar11_2.jpg,flasholet4.wav,,,,,,,guitar11_2.jpg,flasholet4.wav,,,,, -,guitar12_2.jpg,jimi1.wav,,,,,,,guitar12_2.jpg,jimi1.wav,,,,,
\ No newline at end of file +,guitar12_2.jpg,jimi1.wav,,,,,,,guitar12_2.jpg,jimi1.wav,,,,, +-->
\ No newline at end of file diff --git a/games/letters1/letters1.mem b/games/letters1/letters1.mem index cda6e27..f8b7c66 100755 --- a/games/letters1/letters1.mem +++ b/games/letters1/letters1.mem @@ -1,25 +1,23 @@ -game_name=letters1 -score_sound=score.wav -win_sound=score.wav -divided=True -face1=1 -face2=2 -# Cards -1,,,A,,,,,2,,,a,,,, -1,,,E,,,,,2,,,e,,,, -1,,,I,,,,,2,,,i,,,, -1,,,O,,,,,2,,,o,,,, -1,,,U,,,,,2,,,u,,,, -1,,,B,,,,,2,,,b,,,, -1,,,C,,,,,2,,,c,,,, -1,,,D,,,,,2,,,d,,,, -1,,,F,,,,,2,,,f,,,, -1,,,G,,,,,2,,,g,,,, -1,,,H,,,,,2,,,h,,,, -1,,,J,,,,,2,,,j,,,, -1,,,K,,,,,2,,,k,,,, -1,,,L,,,,,2,,,l,,,, -1,,,M,,,,,2,,,m,,,, -1,,,N,,,,,2,,,n,,,, -1,,,P,,,,,2,,,p,,,, -1,,,Q,,,,,2,,,q,,,,
\ No newline at end of file +<?xml version="1.0"?> +<memorize name="letters1" scoresnd="score.wav" winsnd="win.wav" divided="1" face1="1" face2="2" > + + <pair achar="A" bchar="a" /> + <pair achar="E" bchar="e" /> + <pair achar="I" bchar="i" /> + <pair achar="O" bchar="o" /> + <pair achar="U" bchar="u" /> + <pair achar="B" bchar="b" /> + <pair achar="C" bchar="c" /> + <pair achar="D" bchar="d" /> + <pair achar="F" bchar="f" /> + <pair achar="G" bchar="g" /> + <pair achar="H" bchar="h" /> + <pair achar="J" bchar="j" /> + <pair achar="K" bchar="k" /> + <pair achar="L" bchar="l" /> + <pair achar="M" bchar="m" /> + <pair achar="N" bchar="n" /> + <pair achar="P" bchar="p" /> + <pair achar="Q" bchar="q" /> + +</memorize> diff --git a/games/letters2/letters2.mem b/games/letters2/letters2.mem index ff806a9..793696a 100755 --- a/games/letters2/letters2.mem +++ b/games/letters2/letters2.mem @@ -1,25 +1,24 @@ -game_name=letters2 -score_sound=score.wav -win_sound=score.wav -divided=True -face1=1 -face2=2 -# Cards -1,,,A,,,,,2,,,a,,,, -1,,,E,,,,,2,,,e,,,, -1,,,I,,,,,2,,,i,,,, -1,,,O,,,,,2,,,o,,,, -1,,,U,,,,,2,,,u,,,, -1,,,L,,,,,2,,,l,,,, -1,,,M,,,,,2,,,m,,,, -1,,,N,,,,,2,,,n,,,, -1,,,P,,,,,2,,,p,,,, -1,,,Q,,,,,2,,,q,,,, -1,,,R,,,,,2,,,r,,,, -1,,,S,,,,,2,,,s,,,, -1,,,T,,,,,2,,,t,,,, -1,,,V,,,,,2,,,v,,,, -1,,,W,,,,,2,,,w,,,, -1,,,X,,,,,2,,,x,,,, -1,,,Y,,,,,2,,,y,,,, -1,,,Z,,,,,2,,,z,,,,
\ No newline at end of file +<?xml version="1.0"?> +<memorize name="letters2" scoresnd="score.wav" winsnd="win.wav" divided="1" face1="1" face2="2" > + + <pair achar="A" bchar="a" /> + <pair achar="E" bchar="e" /> + <pair achar="I" bchar="i" /> + <pair achar="O" bchar="o" /> + <pair achar="U" bchar="u" /> + + <pair achar="L" bchar="l" /> + <pair achar="M" bchar="m" /> + <pair achar="N" bchar="n" /> + <pair achar="P" bchar="p" /> + <pair achar="Q" bchar="q" /> + <pair achar="R" bchar="r" /> + <pair achar="S" bchar="s" /> + <pair achar="T" bchar="t" /> + <pair achar="V" bchar="v" /> + <pair achar="W" bchar="w" /> + <pair achar="X" bchar="x" /> + <pair achar="Y" bchar="y" /> + <pair achar="Z" bchar="z" /> + +</memorize>
\ No newline at end of file diff --git a/games/numbers/numbers.mem b/games/numbers/numbers.mem index b1a3839..ba7fa05 100755 --- a/games/numbers/numbers.mem +++ b/games/numbers/numbers.mem @@ -1,3 +1,25 @@ +<?xml version="1.0"?> +<memorize name="numbers" scoresnd="score.wav" winsnd="win.wav" divided="1" face1="1" face2="2" > + + <pair achar="1" asnd="01.wav" bimg="01x.jpg" bsnd="01.wav" /> + <pair achar="2" asnd="02.wav" bimg="02x.jpg" bsnd="02.wav" /> + <pair achar="3" asnd="03.wav" bimg="03x.jpg" bsnd="03.wav" /> + <pair achar="4" asnd="04.wav" bimg="04x.jpg" bsnd="04.wav" /> + <pair achar="5" asnd="05.wav" bimg="05x.jpg" bsnd="05.wav" /> + <pair achar="6" asnd="06.wav" bimg="06x.jpg" bsnd="06.wav" /> + <pair achar="7" asnd="07.wav" bimg="07x.jpg" bsnd="07.wav" /> + <pair achar="8" asnd="08.wav" bimg="08x.jpg" bsnd="08.wav" /> + <pair achar="9" asnd="09.wav" bimg="09x.jpg" bsnd="09.wav" /> + <pair achar="10" asnd="10.wav" bimg="10x.jpg" bsnd="10.wav" /> + <pair achar="11" asnd="11.wav" bimg="11x.jpg" bsnd="11.wav" /> + <pair achar="12" asnd="12.wav" bimg="12x.jpg" bsnd="12.wav" /> + <pair achar="13" asnd="13.wav" bimg="13x.jpg" bsnd="13.wav" /> + <pair achar="14" asnd="14.wav" bimg="14x.jpg" bsnd="14.wav" /> + <pair achar="15" asnd="15.wav" bimg="15x.jpg" bsnd="15.wav" /> + +</memorize> + +<!-- game_name=numbers score_sound=score.wav win_sound=score.wav @@ -19,4 +41,5 @@ face2=2 1,,12.wav,12,,,,,2,12x.jpg,12.wav,,,,, 1,,13.wav,13,,,,,2,13x.jpg,13.wav,,,,, 1,,14.wav,14,,,,,2,14x.jpg,14.wav,,,,, -1,,15.wav,15,,,,,2,15x.jpg,15.wav,,,,,
\ No newline at end of file +1,,15.wav,15,,,,,2,15x.jpg,15.wav,,,,, +-->
\ No newline at end of file diff --git a/games/phonemes/phonemes.mem b/games/phonemes/phonemes.mem index a28d4ba..12b67d9 100755 --- a/games/phonemes/phonemes.mem +++ b/games/phonemes/phonemes.mem @@ -1,10 +1,25 @@ -game_name=phonemes -score_sound=score.wav -win_sound=score.wav -divided=True -face1=1 -face2=2 -# Cards +<?xml version="1.0"?> +<memorize name="phonemes" scoresnd="score.wav" winsnd="win.wav" divided="1" face1="1" face2="2" > + + <pair aimg="agua1.jpg" asnd="agua1.wav" bimg="agua2.jpg" bsnd="agua2.wav" /> + <pair aimg="bola1.jpg" asnd="bola1.wav" bimg="bola2.jpg" bsnd="bola2.wav" /> + <pair aimg="casa1.jpg" asnd="casa1.wav" bimg="casa2.jpg" bsnd="casa2.wav" /> + <pair aimg="ema1.jpg" asnd="ema1..wav" bimg="ema2.jpg" bsnd="ema2.wav" /> + <pair aimg="frutas1.jpg" asnd="frutas1.wav" bimg="frutas2.jpg" bsnd="frutas2.wav" /> + <pair aimg="homem1.jpg" asnd="homem1.wav" bimg="homem2.jpg" bsnd="homem2.wav" /> + <pair aimg="ioio1.jpg" asnd="ioio1.wav" bimg="ioio2.jpg" bsnd="ioio2.wav" /> + <pair aimg="kiwi1.jpg" asnd="kiwi1.wav" bimg="kiwi2.jpg" bsnd="kiwi2.wav" /> + <pair aimg="ovo1.jpg" asnd="ovo1.wav" bimg="ovo2.jpg" bsnd="ovo2.wav" /> + <pair aimg="peixe1.jpg" asnd="peixe1.wav" bimg="peixe2.jpg" bsnd="peixe2.wav" /> + <pair aimg="queijo1.jpg" asnd="queijo1.wav" bimg="queijo2.jpg" bsnd="queijo2.wav" /> + <pair aimg="roda1.jpg" asnd="roda1.wav" bimg="roda2.jpg" bsnd="roda2.wav" /> + <pair aimg="sapo1.jpg" asnd="sapo1.wav" bimg="sapo2.jpg" bsnd="sapo2.wav" /> + <pair aimg="uva1.jpg" asnd="uva1.wav" bimg="uva2.jpg" bsnd="uva2.wav" /> + <pair aimg="zebra1.jpg" asnd="zebra1.wav" bimg="zebra2.jpg" bsnd="zebra2.wav" /> + +</memorize> + +<!-- 1,agua1.jpg,agua1.wav,,,,,Á_ _ _,2,agua2.jpg,agua2.wav,,,,,_GUA 1,bola1.jpg,bola1.wav,,,,,BO_ _,2,bola2.jpg,bola2.wav,,,,,_ _LA 1,casa1.jpg,casa1.wav,,,,,CA_ _,2,casa2.jpg,casa2.wav,,,,,_ _SA @@ -19,4 +34,5 @@ face2=2 1,roda1.jpg,roda1.wav,,,,,RO_ _,2,roda2.jpg,roda2.wav,,,,,_ _DA 1,sapo1.jpg,sapo1.wav,,,,,SA_ _,2,sapo2.jpg,sapo2.wav,,,,,_ _PO 1,uva1.jpg,uva1.wav,,,,,U_ _,2,uva2.jpg,uva2.wav,,,,,_VA -1,zebra1.jpg,zebra1.wav,,,,,ZE_ _ _,2,zebra2.jpg,zebra2.wav,,,,,_ _BRA
\ No newline at end of file +1,zebra1.jpg,zebra1.wav,,,,,ZE_ _ _,2,zebra2.jpg,zebra2.wav,,,,,_ _BRA +-->
\ No newline at end of file diff --git a/memorize.dtd b/memorize.dtd index 40542e8..05a4312 100644 --- a/memorize.dtd +++ b/memorize.dtd @@ -2,11 +2,13 @@ <!ELEMENT memorize (#PCDATA|pair)*> <!ATTLIST memorize - name CDATA #REQUIRED - scoresnd CDATA #IMPLIED - winsnd CDATA #IMPLIED - divided CDATA #IMPLIED - face CDATA #IMPLIED + name CDATA #REQUIRED + scoresnd CDATA #IMPLIED + winsnd CDATA #IMPLIED + divided CDATA #IMPLIED + face CDATA #IMPLIED + face1 CDATA #IMPLIED + face2 CDATA #IMPLIED > <!ELEMENT pair (#PCDATA)* > @@ -18,4 +20,6 @@ bsnd CDATA #IMPLIED bchar CDATA #IMPLIED color CDATA #IMPLIED + acharalign CDATA #IMPLIED + bcharalign CDATA #IMPLIED > diff --git a/memorizetoolbar.py b/memorizetoolbar.py index 06bca43..0caf34c 100755 --- a/memorizetoolbar.py +++ b/memorizetoolbar.py @@ -87,7 +87,7 @@ class MemorizeToolbar(gtk.Toolbar): self.activity.change_game(game_name, game_size) def update_toolbar(self, widget, data, grid): - game = data.get('game_name') + game = data.get('name') size = data.get('size') self._lock = True game_index = self.games.index(game) diff --git a/messenger.py b/messenger.py index ee69516..3237b00 100644 --- a/messenger.py +++ b/messenger.py @@ -40,6 +40,8 @@ class Messenger(ExportedGObject): self._tube.watch_participants(self.participant_change_cb) def participant_change_cb(self, added, removed): + _logger.debug('Participants change add=%s rem=%s' %(added, removed)) + if not self.entered: self._tube.add_signal_receiver(self._flip_receiver, '_flip_signal', IFACE, path=PATH, sender_keyword='sender') self._tube.add_signal_receiver(self._change_game_receiver, '_change_game_signal', IFACE, path=PATH, sender_keyword='sender') @@ -61,13 +63,18 @@ class Messenger(ExportedGObject): ''' Someone joined the game, so sync the new player ''' _logger.debug('The new player %s has joined', sender) self.ordered_bus_names.append(sender) + _logger.debug('The grid to send: %s', self.game.get_grid()) + _logger.debug('The data to send: %s', self.game.get_data()) self._tube.get_object(sender, PATH).load_game(self.ordered_bus_names, self.game.get_grid(), self.game.get_data(), self.game.waiting_players, dbus_interface=IFACE) + _logger.debug('Sent the game state') #@dbus.service.method(dbus_interface=IFACE, in_signature='asss', out_signature='') - @dbus.service.method(dbus_interface=IFACE, in_signature='asa(ssssssssiii)a{ss}av', out_signature='') + #@dbus.service.method(dbus_interface=IFACE, in_signature='asa(ssssssssiii)a{ss}av', out_signature='') + @dbus.service.method(dbus_interface=IFACE, in_signature='asaa{ss}a{ss}av', out_signature='') def load_game(self, bus_names, grid, data,list): ''' Sync the game with with players ''' _logger.debug('Data received to sync game data') + _logger.debug('grid %s '%grid) self.ordered_bus_names = bus_names self.player_id = bus_names.index(self._tube.get_unique_name()) self._change_game_receiver(grid,data,self.ordered_bus_names[0]) @@ -96,7 +103,8 @@ class Messenger(ExportedGObject): _logger.debug('Sending changed game message') self._change_game_signal(grid, data) - @dbus.service.signal(IFACE, signature='a(ssssssssiii)a{ss}') + #@dbus.service.signal(IFACE, signature='a(ssssssssiii)a{ss}') + @dbus.service.signal(IFACE, signature='aa{ss}a{ss}') def _change_game_signal(self, grid, data): _logger.debug('Notifing other players that you changed the game') ''' Notify current players that you changed the game ''' @@ -107,8 +115,8 @@ class Messenger(ExportedGObject): if self._tube.self_handle <> handle: _logger.debug('Game changed by other player') - new_grid = [] - for card in grid: - new_grid.append(map(lambda x: str(x), card[:8])+[int(card[8]), int(card[9]), int(card[10])]) - self.game.load_remote(new_grid, data, True) + #new_grid = [] + #for card in grid: + # new_grid.append(map(lambda x: str(x), card[:8])+[int(card[8]), int(card[9]), int(card[10])]) + self.game.load_remote(grid, data, True) diff --git a/misc/addition.mem b/misc/addition.mem deleted file mode 100644 index 9521cb7..0000000 --- a/misc/addition.mem +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0"?> -<memorize name="addition" scoresnd="score.wav" winsnd="win.wav" divided="False" face="" > - - <pair achar="1+1" bchar="2" /> - <pair achar="1+2" bchar="3" /> - <pair achar="2+2" bchar="4" /> - <pair achar="2+3" bchar="5" /> - <pair achar="3+3" bchar="6" /> - <pair achar="3+4" bchar="7" /> - <pair achar="4+4" bchar="8" /> - <pair achar="4+5" bchar="9" /> - <pair achar="5+5" bchar="10" /> - <pair achar="5+6" bchar="11" /> - <pair achar="6+6" bchar="12" /> - <pair achar="6+7" bchar="13" /> - <pair achar="7+7" bchar="14" /> - <pair achar="7+8" bchar="15" /> - <pair achar="8+8" bchar="16" /> - <pair achar="8+9" bchar="17" /> - <pair achar="9+9" bchar="18" /> - <pair achar="10+9" bchar="19" /> - -</memorize> diff --git a/misc/drumgit.mem b/misc/drumgit.mem deleted file mode 100644 index 67efec4..0000000 --- a/misc/drumgit.mem +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0"?> -<memorize name="drumgit" scoresnd="score.wav" winsnd="win.wav" divided="False" face="" > - - <pair aimg="drumkit1_b.jpg" asnd="beat1_a.aiff" bimg="drumkit1_b.jpg" bsnd="beat1_a.aiff" color="100" /> - <pair aimg="drumkit2_b.jpg" asnd="beat1_b.aiff" bimg="drumkit2_b.jpg" bsnd="beat1_b.aiff" color="100" /> - <pair aimg="drumkit3_b.jpg" asnd="beat1_c.aiff" bimg="drumkit3_b.jpg" bsnd="beat1_c.aiff" color="100" /> - <pair aimg="drumkit4_b.jpg" asnd="beat8.aiff" bimg="drumkit4_b.jpg" bsnd="beat8.aiff" color="100" /> - - <pair aimg="drumkit6_b.jpg" asnd="beat3.aiff" bimg="drumkit6_b.jpg" bsnd="beat3.aiff" color="100" /> - <pair aimg="drumkit7_b.jpg" asnd="beat4.aiff" bimg="drumkit7_b.jpg" bsnd="beat4.aiff" color="100" /> - <pair aimg="drumkit8_b.jpg" asnd="beat14.aiff" bimg="drumkit8_b.jpg" bsnd="beat14.aiff" color="100" /> - <pair aimg="drumkit9_b.jpg" asnd="beat6_2.aiff" bimg="drumkit9_b.jpg" bsnd="beat6_2.aiff" color="100" /> - - <pair aimg="guitar1_2.jpg" asnd="bending_a.aiff" bimg="guitar1_2.jpg" bsnd="bending_a.aiff" color="100" /> - <pair aimg="guitar2_2.jpg" asnd="bending_b.aiff" bimg="guitar2_2.jpg" bsnd="bending_b.aiff" color="100" /> - <pair aimg="guitar3_2.jpg" asnd="flashcomp2a.aiff" bimg="guitar3_2.jpg" bsnd="flashcomp2a.aiff" color="100" /> - <pair aimg="guitar4_2.jpg" asnd="flashcomp2b.aiff" bimg="guitar4_2.jpg" bsnd="flashcomp2b.aiff" color="100" /> - - <pair aimg="guitar5_2.jpg" asnd="gedaempft.aiff" bimg="guitar5_2.jpg" bsnd="gedaempft.aiff" color="100" /> - <pair aimg="guitar6_2.jpg" asnd="gedaempft.aiff" bimg="guitar6_2.jpg" bsnd="gedaempft.aiff" color="100" /> - <pair aimg="guitar7_2.jpg" asnd="ungedaempft.aiff" bimg="guitar7_2.jpg" bsnd="ungedaempft.aiff" color="100" /> - <pair aimg="guitar8_2.jpg" asnd="jimi4.aiff" bimg="guitar8_2.jpg" bsnd="jimi4.aiff" color="100" /> - -</memorize> @@ -23,27 +23,25 @@ import logging import random import gobject -IMAGES_PATH = 'games/drumgit/images' -SOUNDS_PATH = 'games/drumgit/sounds' -GAME_PATH = '' - _logger = logging.getLogger('model') - class Pair(gobject.GObject): __gproperties__ = { 'aimg' : (str, None, None, None, gobject.PARAM_READWRITE), 'asnd' : (str, None, None, None, gobject.PARAM_READWRITE), 'achar' : (str, None, None, None, gobject.PARAM_READWRITE), + 'acharalign' : (str, None, None, None, gobject.PARAM_READWRITE), 'bimg' : (str, None, None, None, gobject.PARAM_READWRITE), 'bsnd' : (str, None, None, None, gobject.PARAM_READWRITE), 'bchar' : (str, None, None, None, gobject.PARAM_READWRITE), + 'bcharalign': (str, None, None, None, gobject.PARAM_READWRITE), 'color': (gobject.TYPE_INT, 'Base', 'Base', 0, 10, 0, gobject.PARAM_READWRITE) } def __init__(self): gobject.GObject.__init__(self) - self._properties = {'aimg':None, 'asnd':None, 'bimg':None, 'bsnd':None, 'color':100} + self._properties = {'aimg':None, 'asnd':None, 'achar':None, 'acharalign':'1', 'bimg':None, + 'bsnd':None, 'bchar':None, 'bcharalign':1, 'color':100} def do_get_property(self, pspec): """Retrieve a particular property from our property dictionary @@ -54,12 +52,16 @@ class Pair(gobject.GObject): return self._properties["asnd"] elif pspec.name == "achar": return self._properties["achar"] + elif pspec.name == "acharalign": + return self._properties["acharalign"] elif pspec.name == "bimg": return self._properties["bimg"] elif pspec.name == "bsnd": return self._properties["bsnd"] elif pspec.name == "bchar": return self._properties["bchar"] + elif pspec.name == "bcharalign": + return self._properties["bcharalign"] elif pspec.name == "color": return self._properties["color"] @@ -70,30 +72,32 @@ class Pair(gobject.GObject): self._properties["asnd"] = value elif name == "achar": self._properties["achar"] = value + elif name == "acharalign": + self._properties["acharalign"] = int(value) elif name == "bimg": self._properties["bimg"] = value elif name == "bsnd": self._properties["bsnd"] = value elif name == "bchar": self._properties["bchar"] = value + elif name == "bcharalign": + self._properties["bcharalign"] = value elif name == "color": - self._properties["color"] = int(value) - ''' - def do_set_property(self, props, value): - if props.name == 'a_img': - self._properties['a_img'] = value - ''' + self._properties["color"] = value + class Model(object): ''' The model of the activity. Contains methods to read and save the configuration for a game from xml. Stores the pairs and grid information. - ''' - def __init__(self, gamepath, dtdpath, name='noname'): + ''' + _GAMES_PATH = os.path.join(os.path.dirname(__file__), 'games') + + def __init__(self, dtdpath): self.data = {} - self.gamepath = gamepath self.dtdpath = dtdpath - + self.data['face'] = '' + try: self.dtd = libxml2.parseDTD(None, os.path.join(self.dtdpath, 'memorize.dtd')) except libxml2.parserError, e: @@ -112,10 +116,15 @@ class Model(object): self.started = 0 self.count = 0 - def read(self, filename): + def read(self, gamename): ''' reades the configuration from an xml file ''' + self.data['path'] = os.path.join( self._GAMES_PATH, gamename) + self.data['pathimg'] = os.path.join(self.data['path'], 'images') + self.data['pathsnd'] = os.path.join(self.data['path'], 'sounds') + self.pairs = {} + try: - doc = libxml2.parseFile(os.path.join(self.gamepath, filename)) + doc = libxml2.parseFile(os.path.join(self.data['path'], gamename+'.mem')) if doc.validateDtd(self.ctxt, self.dtd): # get the requested nodes @@ -133,41 +142,41 @@ class Model(object): pass else: pair.set_property(attribute.name, attribute.content) - self.pairs[self.idpair] = pair + self.pairs[str(self.idpair)] = pair self.idpair+=1 elif( elem.name == 'memorize' ): for attribute in attributes: if(attribute.name == 'text'): pass elif(attribute.name == 'name'): - self.data['game_name'] = attribute.content + self.data['name'] = attribute.content elif(attribute.name == 'scoresnd'): self.data['scoresnd'] = attribute.content elif(attribute.name == 'winsnd'): self.data['winsnd'] = attribute.content elif(attribute.name == 'divided'): self.data['divided'] = attribute.content - elif(attribute.name == 'divided'): - self.data['divided'] = attribute.content elif(attribute.name == 'face'): self.data['face'] = attribute.content elif(attribute.name == 'face1'): self.data['face1'] = attribute.content elif(attribute.name == 'face2'): - self.data['face2'] = attribute.content + self.data['face2'] = attribute.content xpa.xpathFreeContext() else: _logger.error('Error in validation of the file') + return 1 doc.freeDoc() + return 0 except libxml2.parserError, e: _logger.error('Error parsing file ' +str(e)) - + return 2 def save(self, filename): ''' saves the configuration to an xml file ''' doc = libxml2.newDoc("1.0") root = doc.newChild(None, "memorize", None) - root.setProp("name", self.data['game_name']) + root.setProp("name", self.data['name']) ### Fixme: add other attributes here for key in self.pairs: @@ -194,97 +203,143 @@ class Model(object): def def_grid(self, size): ''' create the grid for the play from the pairs information and shuffles the grid so they always appear in a different - place - grid [pair_key, a_or_b, flipstatus] + place ''' - _logger.debug(' pairs: %s', self.pairs) + psize=(size*size/2) + _logger.debug('Size requested: %d' %psize) + self.grid = [] + temp1 = [] + temp2 = [] i=0 for key in self.pairs.iterkeys(): - if i < size: - self.grid.append([key, 0, 0]) - self.grid.append([key, 1, 0]) + if i < psize: + elem = {} + elem['pairkey'] = key + elem['state'] = '0' + elem['ab'] = 'a' + if self.pairs[key].props.aimg != None: + elem['img'] = os.path.join(self.data['pathimg'], self.pairs[key].props.aimg) + if self.pairs[key].props.asnd != None: + elem['snd'] = os.path.join(self.data['pathsnd'], self.pairs[key].props.asnd) + if self.pairs[key].props.achar != None: + elem['char'] = self.pairs[key].props.achar + elem['charalign'] = self.pairs[key].props.acharalign + temp1.append(elem) + + elem = {} + elem['pairkey'] = key + elem['state'] = '0' + elem['ab'] = 'b' + if self.pairs[key].props.bimg != None: + elem['img'] = os.path.join(self.data['pathimg'], self.pairs[key].props.bimg) + if self.pairs[key].props.bsnd != None: + elem['snd'] = os.path.join(self.data['pathsnd'], self.pairs[key].props.bsnd) + if self.pairs[key].props.bchar != None: + elem['char'] = self.pairs[key].props.bchar + elem['charalign'] = self.pairs[key].props.bcharalign + temp2.append(elem) i+=1 else: break - + numpairs = len(self.pairs) - if numpairs < size: - _logger.debug('We did not have enough pairs. requested=%s had=%s' %(numpairs, size)) + if numpairs < psize: + _logger.debug('We did not have enough pairs. requested=%s had=%s' %(psize, numpairs)) + self.data['size'] = str(size) - self.data['size'] = numpairs - - random.shuffle(self.grid) - _logger.debug(' grid: %s', self.grid) + if self.data['divided'] == '1': + random.shuffle(temp1) + random.shuffle(temp2) + temp1.extend(temp2) + else: + temp1.extend(temp2) + random.shuffle(temp1) + self.grid = temp1 + _logger.debug(' grid( size=%s ): %s' %(self.data['size'], self.grid)) + + + +if __name__ == '__main__': + model = Model(os.path.dirname(__file__)) + model.read('drumgit') + + print 'name=%s scoresnd=%s winsnd=%s div=%s' %(model.data['name'], model.data['scoresnd'], + model.data['winsnd'], model.data['divided']) + model.def_grid(4) + print 'grid %s'%model.grid #['size'] - def gettile(self, tilenum): - ''' gets the information of an object associated with a tile number ''' - img = None - snd = None - char = None - pairkey, moch, state = self.grid[tilenum] - if moch == 0: - if self.pairs[pairkey].props.aimg != None: - img = os.path.join(IMAGES_PATH, self.pairs[pairkey].props.aimg) - if self.pairs[pairkey].props.asnd != None: - snd = os.path.join(SOUNDS_PATH, self.pairs[pairkey].props.asnd) - char = self.pairs[pairkey].props.achar - if moch == 1: - if self.pairs[pairkey].props.bimg != None: - img = os.path.join(IMAGES_PATH, self.pairs[pairkey].props.bimg) - if self.pairs[pairkey].props.bsnd != None: - snd = os.path.join(SOUNDS_PATH, self.pairs[pairkey].props.bsnd) - char = self.pairs[pairkey].props.bchar - color = self.pairs[pairkey].props.color - return (img, snd, char, color) + print 'Test set state of tile 7:' + tilenum = 7 + model.grid[tilenum]['state'] = '1' + print ' %s' %model.grid[tilenum] + print 'Test sound:' + snd = model.grid[tilenum].get('snd', None) + if snd == None: + print ' no sound' + else: + print ' play sound=%s'%snd - def same(self, a, b): - ''' checks wether two tiles are matching ''' - pairkeya, moch, state = self.grid[a] - pairkeyb, moch, state = self.grid[b] - return (pairkeya == pairkeyb) + print 'Test the same function: 0 1' + if model.grid[0]['pairkey'] == model.grid[1]['pairkey']: + print ' they are the same' + else: + print ' they are NOT the same' + for tile in model.grid: + id = model.grid.index(tile) + if tile.get('img', None): + print 'we got an image=%s '%tile['img'] + elif tile.get('char', None): + print 'we got an char=%s'%tile.get('char') + else: + print 'we got no pic so prepare for sound game' + + print '\n_______________________________\n' + ''' + if model.read('addition') == 0: + print '%s' %model.pairs[0]._properties + print 'name=%s' %model.data['name'] + print 'scoresnd=%s' %model.data['scoresnd'] + print 'winsnd=%s' %model.data['winsnd'] + print 'div=%d' %model.data['divided'] + model.def_grid(12) + for tile in model.grid: + id = model.grid.index(tile) + if tile.get('img', None): + print 'we got an image=%s '%tile.get('img') + elif tile.get('char', None): + print 'we got an char=%s'%tile.get('char') + else: + print 'we got no img so prepare for sound game' -if __name__ == '__main__': - model = Model(GAME_PATH, os.path.dirname(__file__)) - model.read('drumgit.mem') - print '%s' %model.pairs[0]._properties - print 'name=%s' %model.data['game_name'] - print 'scoresnd=%s' %model.data['scoresnd'] - print 'winsnd=%s' %model.data['winsnd'] - print 'div=%s' %model.data['divided'] - model.def_grid(8) - print 'grid size=%d'%model.data['size'] - print model.grid + else: + print 'error during reading of the game' - i=0 - while i < model.data['size']: - pairkey, moch, state = model.grid[i] - if moch == 0: - if model.pairs[pairkey].props.aimg != None: - print model.pairs[pairkey].props.aimg - if moch == 1: - if model.pairs[pairkey].props.bimg != None: - print model.pairs[pairkey].props.bimg - i+=1 - - ''' - print '\n_______________________________\n' - - model.read('addition.mem') - print '%s' %model.pairs[0]._properties - print 'name=%s' %model.data['game_name'] - print 'scoresnd=%s' %model.data['scoresnd'] - print 'winsnd=%s' %model.data['winsnd'] - print 'div=%s' %model.data['divided'] + print '\n_______________________________\n' + if model.read('numbers') == 0: + print '%s' %model.pairs[0]._properties + print 'name=%s' %model.data['name'] + print 'scoresnd=%s' %model.data['scoresnd'] + print 'winsnd=%s' %model.data['winsnd'] + print 'div=%d' %model.data['divided'] + print 'face1=%s' %model.data['face1'] + print 'face2=%s' %model.data['face2'] - model.def_grid(12) - print model.grid - print model.gettile(0) - print model.gettile(1) - model.save('/tmp/mod.txt') + model.def_grid(12) + for tile in model.grid: + id = model.grid.index(tile) + if tile.get('img', None): + print 'we got an image=%s '%tile.get('img') + elif tile.get('char', None): + print 'we got an char=%s'%tile.get('char') + else: + print 'we got no img so prepare for sound game' + + else: + print 'error during reading of the game' ''' diff --git a/scoreboard.py b/scoreboard.py index 0527b34..9b88c27 100755 --- a/scoreboard.py +++ b/scoreboard.py @@ -45,6 +45,7 @@ class Scoreboard(gtk.EventBox): self.show() def add_buddy(self, widget, buddy, score): + ### FIXME: this breaks when the body is empty nick = buddy.props.nick stroke_color, fill_color = buddy.props.color.split(',') player = PlayerScoreboard(nick, fill_color, stroke_color, score) @@ -59,7 +60,7 @@ class Scoreboard(gtk.EventBox): def rem_buddy(self, widget, buddy): self.vbox.remove(self.players[buddy]) - del self.players[id] + del self.players[buddy] ### fix for self.players[id] def set_selected(self, widget, buddy): if self.current_buddy <> None: |