Delivered-To: godiard@gmail.com
Received: by 10.204.155.92 with SMTP id r28csp91523bkw;
Thu, 10 Jan 2013 06:44:44 -0800 (PST)
X-Received: by 10.224.186.82 with SMTP id cr18mr58044098qab.64.1357829083499;
Thu, 10 Jan 2013 06:44:43 -0800 (PST)
Return-Path: <sugar-devel-bounces@lists.sugarlabs.org>
Received: from sunjammer.sugarlabs.org ([2001:4830:134:7::11])
by mx.google.com with ESMTP id o18si750450qct.44.2013.01.10.06.44.42;
Thu, 10 Jan 2013 06:44:43 -0800 (PST)
Received-SPF: neutral (google.com: 2001:4830:134:7::11 is neither permitted nor denied by best guess record for domain of sugar-devel-bounces@lists.sugarlabs.org) client-ip=2001:4830:134:7::11;
Authentication-Results: mx.google.com;
spf=neutral (google.com: 2001:4830:134:7::11 is neither permitted nor denied by best guess record for domain of sugar-devel-bounces@lists.sugarlabs.org) smtp.mail=sugar-devel-bounces@lists.sugarlabs.org;
dkim=neutral (body hash did not verify) header.i=@gmail.com
Received: from sunjammer.sugarlabs.org (localhost [127.0.0.1])
by sunjammer.sugarlabs.org (Postfix) with ESMTP id BB874120546;
Thu, 10 Jan 2013 09:44:40 -0500 (EST)
Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com
[209.85.216.181])
by sunjammer.sugarlabs.org (Postfix) with ESMTPS id 0BB7A120734
for <sugar-devel@lists.sugarlabs.org>;
Thu, 10 Jan 2013 09:44:34 -0500 (EST)
Received: by mail-qc0-f181.google.com with SMTP id x40so390723qcp.26
for <sugar-devel@lists.sugarlabs.org>;
Thu, 10 Jan 2013 06:44:34 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
h=x-received:from:to:cc:subject:date:message-id:x-mailer:organization;
bh=5BqCKrLa8MnvaDsD4xTjj8J3WZDUfLJZ3bUXuXpD9OY=;
b=IFgwkSpCVn4J7zfEZKRfZBvgGPgKCe7Q5j5SquZ3hxtYl1H9+mfr3MztquBccOkzzI
NrQCfekpzNyvJBKgETPEkX8lVePoAr8G20mKGgVlLwl+9opUBFNZJPgsPaZL9JeI9q/e
D7vSm+9ikjXOeuBQn10jKa2PNOu4aRcRKHZS15/LCqgn3etUkaEWGLFV8/qu7a4Vllws
foJJB/ONcun/Ap3Awak8jDWj2koAbDuiBkq8QlugYyrVZLH2sS3BCZ2so5Ceu1KiBPZ7
w5CXOxGhRbFpIyoe0/CF3lwh7+I1JJdKcVI7+v4JF3JtD9IXXbaqTqMv+yLCsVwt1lXd
KpJA==
X-Received: by 10.224.222.15 with SMTP id ie15mr22464683qab.75.1357829074058;
Thu, 10 Jan 2013 06:44:34 -0800 (PST)
Received: from localhost.localdomain ([190.99.138.244])
by mx.google.com with ESMTPS id cy2sm1223590qeb.9.2013.01.10.06.44.31
(version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
Thu, 10 Jan 2013 06:44:33 -0800 (PST)
From: Ariel Calzada <ariel.calzada@gmail.com>
To: ariel@activitycentral.com
Date: Thu, 10 Jan 2013 09:44:18 -0500
Message-Id: <1357829058-13107-1-git-send-email-ariel@acivitycentral.com>
X-Mailer: git-send-email 1.7.10.4
Organization: Sugar Labs Foundation
X-Spam-Status: No, score=-0.7 required=3.5 tests=FREEMAIL_FROM,
RCVD_IN_DNSWL_LOW, SPF_PASS,
T_DKIM_INVALID autolearn=unavailable version=3.3.2
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on
sunjammer.sugarlabs.org
X-Topics: Patches and patch reviews
Cc: Ajay Garg <ajay@activitycentral.com>, team@lists.activitycentral.com,
sugar-devel@lists.sugarlabs.org, ariel.calzada@gmail.com
Subject: [Sugar-devel] [PATCH] SDXO#2620 Add ability to save unfinished
games in Memorize.
X-BeenThere: sugar-devel@lists.sugarlabs.org
X-Mailman-Version: 2.1.13
Precedence: list
List-Id: "Discussion of Sugar development and other technical matters."
<sugar-devel.lists.sugarlabs.org>
List-Unsubscribe: <http://lists.sugarlabs.org/options/sugar-devel>,
<mailto:sugar-devel-request@lists.sugarlabs.org?subject=unsubscribe>
List-Archive: <http://lists.sugarlabs.org/archive/sugar-devel>
List-Post: <mailto:sugar-devel@lists.sugarlabs.org>
List-Help: <mailto:sugar-devel-request@lists.sugarlabs.org?subject=help>
List-Subscribe: <http://lists.sugarlabs.org/listinfo/sugar-devel>,
<mailto:sugar-devel-request@lists.sugarlabs.org?subject=subscribe>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: sugar-devel-bounces@lists.sugarlabs.org
Errors-To: sugar-devel-bounces@lists.sugarlabs.org
From: Ajay Garg <ajay@activitycentral.com>
The approach followed has been simply to save the current-game image
when closing the game. The game resumes from that image next time
onwards.
Tests conducted ::
a)
(i)
User exits, without finishing the current game.
(ii)
When she next starts, she will proceed from the same game, from the same stage.
b)
(i)
User exits, without finishing the current game.
(ii)
She then transfers the journal-entry to another XO.
(iii)
Tries to resume the game, from the (transferred) journal entry.
(iv)
Game resumes, from the same stage.
Signed-off-by: Ajay Garg <ajay@activitycentral.com>
---
activity.py | 16 ++++++++++++++--
cardlist.py | 3 ++-
game.py | 14 ++++++++++++--
memorizetoolbar.py | 2 +-
model.py | 12 +++++++++++-
5 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/activity.py b/activity.py
index 8bfd758..8bc679d 100644
a
|
b
|
class MemorizeActivity(Activity): |
107 | 107 | # Play game mode |
108 | 108 | self.table = cardtable.CardTable() |
109 | 109 | self.scoreboard = scoreboard.Scoreboard() |
110 | | self.cardlist = cardlist.CardList() |
| 110 | self.cardlist = cardlist.CardList(self) |
111 | 111 | self.createcardpanel = createcardpanel.CreateCardPanel() |
112 | 112 | self.cardlist.connect('pair-selected', |
113 | 113 | self.createcardpanel.pair_selected) |
… |
… |
class MemorizeActivity(Activity): |
127 | 127 | self._memorizeToolbarBuilder.reset) |
128 | 128 | self._createToolbarBuilder.connect('create_equal_pairs', |
129 | 129 | self.change_equal_pairs) |
130 | | self.game = game.MemorizeGame() |
| 130 | self.game = game.MemorizeGame(self) |
131 | 131 | |
132 | 132 | self._edit_button.connect('toggled', self._change_mode_bt) |
133 | 133 | |
… |
… |
class MemorizeActivity(Activity): |
232 | 232 | |
233 | 233 | def write_file(self, file_path): |
234 | 234 | logging.debug('WRITE_FILE is_demo %s', self.game.model.is_demo) |
| 235 | |
| 236 | # We want to save the game-image for demo games too !!! |
| 237 | """ |
235 | 238 | if self.game.model.is_demo: |
236 | 239 | # if is a demo game only want keep the metadata |
237 | 240 | self._jobject.set_file_path(None) |
238 | 241 | raise NotImplementedError |
239 | 242 | return |
| 243 | """ |
| 244 | |
240 | 245 | if self.cardlist.pair_list_modified: |
241 | 246 | self.cardlist.update_model(self.game.model) |
242 | 247 | |
… |
… |
class MemorizeActivity(Activity): |
285 | 290 | game_zip.close() |
286 | 291 | self.metadata['mime_type'] = 'application/x-memorize-project' |
287 | 292 | |
| 293 | # Store the game image as a string - that is simpler instead of |
| 294 | # having to deal with the dbus-converted list. |
| 295 | # When reading back, we use "eval" to convert the string into |
| 296 | # the correct type ("list" in this case). |
| 297 | self.metadata['saved_game_data_image'] = str(self.game.model.grid) |
| 298 | self.metadata['size'] = int(self.game.model.data['size']) |
| 299 | |
288 | 300 | def _complete_close(self): |
289 | 301 | self._remove_temp_files() |
290 | 302 | Activity._complete_close(self) |
diff --git a/cardlist.py b/cardlist.py
index 6bc781c..65e44f1 100644
a
|
b
|
class CardList(gtk.EventBox): |
40 | 40 | 'update-create-toolbar': (SIGNAL_RUN_FIRST, None, 3 * [TYPE_PYOBJECT]), |
41 | 41 | } |
42 | 42 | |
43 | | def __init__(self): |
| 43 | def __init__(self, activity_instance): |
44 | 44 | gtk.EventBox.__init__(self) |
| 45 | self._activity_instance = activity_instance |
45 | 46 | self.pairs = [] |
46 | 47 | self.current_pair = None |
47 | 48 | self.current_game_key = None |
diff --git a/game.py b/game.py
index c5e54d1..9d21b4b 100644
a
|
b
|
class MemorizeGame(GObject): |
57 | 57 | 'change-turn': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]), |
58 | 58 | } |
59 | 59 | |
60 | | def __init__(self): |
| 60 | def __init__(self, activity_instance): |
61 | 61 | gobject.GObject.__init__(self) |
62 | 62 | self.myself = None |
63 | 63 | self.players_score = {} |
… |
… |
class MemorizeGame(GObject): |
70 | 70 | self.messenger = None |
71 | 71 | self.sentitive = True |
72 | 72 | |
73 | | self.model = Model() |
| 73 | self.model = Model(activity_instance=activity_instance) |
74 | 74 | self.flip_block = False |
75 | 75 | self._flop_cards = None |
76 | 76 | |
… |
… |
class MemorizeGame(GObject): |
109 | 109 | self.change_turn() |
110 | 110 | self.model.data['running'] = 'False' |
111 | 111 | |
| 112 | # Card 'state' is an aawesome field. |
| 113 | # Its takes on the following values :: |
| 114 | # |
| 115 | # 0 ==> for flopped cards. |
| 116 | # |
| 117 | # 1 ==> for flipped unmatched cards |
| 118 | # (can be a maximum of 1 such card). |
| 119 | # |
| 120 | # <stroke_color>, <fill_color> ==> for flipped matched cards |
| 121 | |
112 | 122 | for card in self.model.grid: |
113 | 123 | if card['state'] == '1': |
114 | 124 | self.emit('flip-card', self.model.grid.index(card), False) |
diff --git a/memorizetoolbar.py b/memorizetoolbar.py
index 1a06da7..07ceecf 100644
a
|
b
|
class MemorizeToolbarBuilder(gobject.GObject): |
135 | 135 | self._demo_games.props.icon_name = 'memorize-collection' |
136 | 136 | |
137 | 137 | def update_toolbar(self, widget, data, grid): |
138 | | size = data.get('size') |
| 138 | size = str(data.get('size')) |
139 | 139 | self._size_combo.props.icon_name = size + ' X ' + size |
diff --git a/model.py b/model.py
index 2567ed2..16239c4 100644
a
|
b
|
class Model(object): |
100 | 100 | information. |
101 | 101 | ''' |
102 | 102 | |
103 | | def __init__(self, game_path=None): |
| 103 | def __init__(self, game_path=None, activity_instance=None): |
104 | 104 | tmp_root = join(environ['SUGAR_ACTIVITY_ROOT'], 'instance') |
105 | 105 | self.temp_folder = tempfile.mkdtemp(dir=tmp_root) |
106 | 106 | chmod(self.temp_folder, 0777) |
| 107 | self._saved_game_loaded = False |
107 | 108 | |
| 109 | self._activity_instance = activity_instance |
108 | 110 | self.data = {} |
109 | 111 | |
110 | 112 | if game_path is None: |
… |
… |
class Model(object): |
366 | 368 | temp1.extend(temp2) |
367 | 369 | random.shuffle(temp1) |
368 | 370 | self.grid = temp1 |
| 371 | |
| 372 | if not self._saved_game_loaded: |
| 373 | if self._activity_instance is not None: |
| 374 | if 'saved_game_data_image' in self._activity_instance.metadata.keys(): |
| 375 | self.grid = eval(self._activity_instance.metadata['saved_game_data_image']) |
| 376 | self.data['size'] = int(self._activity_instance.metadata['size']) |
| 377 | self._saved_game_loaded = True |
| 378 | |
369 | 379 | _logger.debug('Defgrid: grid( size=%s ): %s' |
370 | 380 | % (self.data['size'], self.grid)) |
371 | 381 | _logger.debug('Defgrid: data: %s', self.data) |