Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/game.py
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2009-10-06 11:27:27 (GMT)
committer Simon Schampijer <simon@schampijer.de>2009-10-06 11:27:27 (GMT)
commit9694e9551ae3c60f9af93eee6bfcfb349a357181 (patch)
tree52c979213a8f9aeee87a16f7cf5d22aa0f82e6fd /game.py
parentc895c1e658d616a6a52b274494aefce1a28abfe0 (diff)
Pylint cleanup
Diffstat (limited to 'game.py')
-rw-r--r--game.py133
1 files changed, 72 insertions, 61 deletions
diff --git a/game.py b/game.py
index b33c748..c1922e7 100644
--- a/game.py
+++ b/game.py
@@ -17,12 +17,9 @@
import logging
import gobject
-from os.path import join, dirname
+from os.path import join
from gettext import gettext as _
-from sugar import profile
-from dbus.service import method, signal
-from dbus.gobject_service import ExportedGObject
from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, GObject, timeout_add
from gobject import source_remove
@@ -69,6 +66,7 @@ class MemorizeGame(GObject):
self.current_player = None
self.last_flipped = -1
self.last_highlight = 1
+ self._flop_card_timeout = -1
self.messenger = None
self.sentitive = True
@@ -84,10 +82,11 @@ class MemorizeGame(GObject):
self.model.def_grid(size)
self.model.data['running'] = 'False'
self.model.data['mode'] = mode
- logging.debug(' Read setup file %s: %s '%(game_name, self.model.grid))
+ 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)
+ logging.error(' Reading setup file %s', game_name)
def load_remote(self, grid, data, mode, signal = False):
self.set_load_mode(_('Loading game...'))
@@ -118,7 +117,8 @@ class MemorizeGame(GObject):
elif card['state'] != '0':
stroke_color, fill_color = card['state'].split(',')
self.emit('flip-card', self.model.grid.index(card))
- self.emit('set-border', self.model.grid.index(card), stroke_color, fill_color)
+ self.emit('set-border', self.model.grid.index(card),
+ stroke_color, fill_color)
def add_buddy(self, buddy, score = 0):
_logger.debug('Buddy %r was added to game', buddy.props.nick)
@@ -135,9 +135,9 @@ class MemorizeGame(GObject):
_logger.debug('Buddy %r was removed from game', buddy.props.nick)
if self.current_player == buddy and len(self.players) >= 2:
if self.last_flipped != -1:
- self.emit('flop-card', self.last_flipped)
- self.model.grid[self.last_flipped]['state'] = '0'
- self.last_flipped = -1
+ self.emit('flop-card', self.last_flipped)
+ self.model.grid[self.last_flipped]['state'] = '0'
+ self.last_flipped = -1
self.change_turn()
index = self.players.index(buddy)
del self.players[index]
@@ -159,28 +159,31 @@ class MemorizeGame(GObject):
elif self.current_player == self.players[-1]:
self.current_player = self.players[0]
else:
- next = self.players[self.players.index(self.current_player)+1]
- self.current_player = next
+ next_player = self.players.index(self.current_player) + 1
+ self.current_player = self.players[next_player]
self.update_turn()
-
- def card_overflipped(self, widget, id):
- if self._flop_cards and id in self._flop_cards:
- self.card_flipped(widget, id)
- def card_flipped(self, widget, id, signal = False):
+ def card_overflipped(self, widget, identifier):
+ if self._flop_cards and identifier in self._flop_cards:
+ self.card_flipped(widget, identifier)
+
+ def card_flipped(self, widget, identifier, signal = False):
if self._flop_cards:
source_remove(self._flop_card_timeout)
self.flop_card(self._flop_cards[0], self._flop_cards[1])
# Check if is my turn
- if (not self.sentitive and not signal) or self.last_flipped == id:
+ if (not self.sentitive and not signal) or \
+ self.last_flipped == identifier:
return
# Handle groups if needed
if self.model.data.get('divided') == '1':
- if self.last_flipped == -1 and id >= (len(self.model.grid)/2):
+ if self.last_flipped == -1 and identifier \
+ >= (len(self.model.grid)/2):
return
- if self.last_flipped <> -1 and id < (len(self.model.grid)/2):
+ if self.last_flipped != -1 and identifier \
+ < (len(self.model.grid)/2):
return
# do not process flips when flipping back
@@ -191,57 +194,61 @@ class MemorizeGame(GObject):
self.model.data['running'] = 'True'
- snd = self.model.grid[id].get('snd', None)
+ snd = self.model.grid[identifier].get('snd', None)
if snd != None:
sound_file = join(self.model.data.get('pathsnd'), snd)
self.audio.play(sound_file)
- self.emit('flip-card', id)
+ self.emit('flip-card', identifier)
if not signal:
- self.emit('flip-card-signal', id)
+ self.emit('flip-card-signal', identifier)
# First card case
if self.last_flipped == -1:
- self.last_flipped = id
- self.model.grid[id]['state'] = '1'
+ self.last_flipped = identifier
+ self.model.grid[identifier]['state'] = '1'
self.flip_block = False
# Second card case
else:
# Pair matched
pair_key_1 = self.model.grid[self.last_flipped]['pairkey']
- pair_key_2 = self.model.grid[id]['pairkey']
+ pair_key_2 = self.model.grid[identifier]['pairkey']
if pair_key_1 == pair_key_2:
- 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)
+ stroke_color, fill_color = \
+ self.current_player.props.color.split(',')
+ self.emit('set-border', identifier, stroke_color, fill_color)
+ self.emit('set-border', self.last_flipped,
+ stroke_color, fill_color)
self.increase_point(self.current_player)
- self.model.grid[id]['state'] = self.current_player.props.color
- self.model.grid[self.last_flipped]['state'] = self.current_player.props.color
+ self.model.grid[identifier]['state'] = \
+ self.current_player.props.color
+ self.model.grid[self.last_flipped]['state'] = \
+ self.current_player.props.color
self.flip_block = False
- self.emit('cement-card', id)
+ self.emit('cement-card', identifier)
self.emit('cement-card', self.last_flipped)
# Pair didn't match
else:
- self.model.grid[id]['state'] = '1'
+ self.model.grid[identifier]['state'] = '1'
self.set_sensitive(False)
- self._flop_cards = (id, self.last_flipped)
+ self._flop_cards = (identifier, self.last_flipped)
self._flop_card_timeout = timeout_add(theme.FLOP_BACK_TIMEOUT,
- self.flop_card, id, self.last_flipped)
+ self.flop_card, identifier, self.last_flipped)
self.last_flipped = -1
- def flop_card(self, id, id2):
+ def flop_card(self, identifier, identifier2):
self._flop_card_timeout = -1
self._flop_cards = None
- self.emit('flop-card', id)
- self.model.grid[id]['state'] = '0'
- self.emit('flop-card', id2)
- self.model.grid[id2]['state'] = '0'
+ self.emit('flop-card', identifier)
+ self.model.grid[identifier]['state'] = '0'
+ self.emit('flop-card', identifier2)
+ self.model.grid[identifier2]['state'] = '0'
#if self.model.data['divided'] == '1':
# self.card_highlighted(widget, -1, False)
@@ -249,26 +256,28 @@ class MemorizeGame(GObject):
self.flip_block = False
self.change_turn()
- def card_highlighted(self, widget, id, mouse):
+ def card_highlighted(self, widget, identifier, mouse):
self.emit('highlight-card', self.last_highlight, False)
- self.last_highlight = id
+ self.last_highlight = identifier
- if id == -1 or not self.sentitive:
+ if identifier == -1 or not self.sentitive:
return
if self.model.data['divided'] == '1':
- if self.last_flipped == -1 and id >= (len(self.model.grid)/2):
+ if self.last_flipped == -1 and identifier \
+ >= (len(self.model.grid)/2):
return
- if self.last_flipped <> -1 and id < (len(self.model.grid)/2):
+ if self.last_flipped != -1 and identifier \
+ < (len(self.model.grid)/2):
return
- if mouse and self.model.grid[id]['state']=='0' or not mouse:
- self.emit('highlight-card', id, True)
+ if mouse and self.model.grid[identifier]['state'] == '0' or not mouse:
+ self.emit('highlight-card', identifier, True)
def increase_point(self, buddy, inc=1):
self.players_score[buddy] += inc
- for i in range(inc):
+ for i_ in range(inc):
self.emit('increase-score', buddy)
def get_grid(self):
@@ -281,10 +290,11 @@ class MemorizeGame(GObject):
self.model.data[str(index)] = str(score)
return self.model.data
- def change_game(self, widget, game_name, size, mode, title = None, color= None):
+ def change_game(self, widget, game_name, size, mode,
+ title = None, color= None):
if mode in ['file', 'demo']:
if self.model.read(game_name) != 0:
- logging.error(' Reading setup file %s'%game_name)
+ logging.error(' Reading setup file %s', game_name)
return
if size == None:
size = int(self.model.data['size'])
@@ -294,7 +304,7 @@ class MemorizeGame(GObject):
self.model.data['title'] = title
if color != None:
self.model.data['color'] = color
- self.load_remote(self.model.grid, self.model.data, mode, False)
+ self.load_remote(self.model.grid, self.model.data, mode, False)
def reset_game(self, size = None):
if size == None:
@@ -322,21 +332,22 @@ class MemorizeGame(GObject):
def get_players_data(self):
data = []
for player, score in self.players_score.items():
- data.append([player.props.key, player.props.nick, player.props.color, score])
+ data.append([player.props.key, player.props.nick,
+ player.props.color, score])
return data
-
- def set_wait_list(self, list):
- self.waiting_players = list
- for w in list:
+
+ def set_wait_list(self, wait_list):
+ self.waiting_players = wait_list
+ for w in wait_list:
for p in self.players:
if w[0] == p.props.key:
list.remove(w)
- for i in range(w[3]):
+ for i_ in range(w[3]):
self.increase_point(p)
-
+
def set_myself(self, buddy):
self.myself = buddy
-
+
def add_to_waiting_list(self, buddy):
self.players.remove(buddy)
self.waiting_players.append(buddy)
@@ -347,8 +358,8 @@ class MemorizeGame(GObject):
self.players.append(buddy)
self.emit('wait_mode_buddy', buddy, False)
- def load_waiting_list(self, list):
- for buddy in list:
+ def load_waiting_list(self, wait_list):
+ for buddy in wait_list:
self.add_to_waiting_list(buddy)
def empty_waiting_list(self):