diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-12-15 16:50:56 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-12-15 16:50:56 (GMT) |
commit | 544a3b37dc38c6643dee1f31b6c34420e5fe020e (patch) | |
tree | 877890e6148485f2c3161b1df8410d84fd24ca75 | |
parent | c266a27a80d92c8cdf75706a869fa8d3e4ac1b5a (diff) |
added robot play
-rw-r--r-- | ReflectionActivity.py | 19 | ||||
-rw-r--r-- | game.py | 51 | ||||
-rw-r--r-- | icons/robot-off.svg | 60 | ||||
-rw-r--r-- | icons/robot-on.svg | 80 |
4 files changed, 209 insertions, 1 deletions
diff --git a/ReflectionActivity.py b/ReflectionActivity.py index 43194c7..4a25ea7 100644 --- a/ReflectionActivity.py +++ b/ReflectionActivity.py @@ -128,6 +128,13 @@ class ReflectionActivity(activity.Activity): self.status = label_factory(self.toolbar, '') if _have_toolbox: + separator_factory(toolbox.toolbar, False, True) + + self.robot_button = button_factory( + 'robot-off', self.toolbar, self._robot_cb, + tooltip= _('Play with the robot.')) + + if _have_toolbox: separator_factory(toolbox.toolbar, True, False) if _have_toolbox: @@ -140,6 +147,18 @@ class ReflectionActivity(activity.Activity): ''' Start a new game. ''' self._game.new_game(orientation) + def _robot_cb(self, button=None): + ''' Play with the computer (or not). ''' + if not self._game.playing_with_robot: + self.set_robot_status(True, 'robot-on') + else: + self.set_robot_status(False, 'robot-off') + + def set_robot_status(self, status, icon): + ''' Reset robot icon and status ''' + self._game.playing_with_robot = status + self.robot_button.set_icon(icon) + def write_file(self, file_path): """ Write the grid status to the Journal """ [dot_list, orientation] = self._game.save_game() @@ -61,6 +61,7 @@ class Game(): self._space = int(self._dot_size / 5.) self._orientation = 'horizontal' self.we_are_sharing = False + self.playing_with_robot = False # Generate the sprites we'll need... self._sprites = Sprites(self._canvas) @@ -179,6 +180,10 @@ class Game(): spr.type += 1 spr.type %= 4 spr.set_shape(self._new_dot(self._colors[spr.type])) + + if self.playing_with_robot: + self._robot_play(spr) + self._test_game_over() if self.we_are_sharing: @@ -187,6 +192,50 @@ class Game(): spr.type) return True + def _robot_play(self, dot): + ''' Robot reflects dot clicked. ''' + x, y = self._dot_to_grid(self._dots.index(dot)) + if self._orientation == 'horizontal': + _logger.debug('%d: %d, %d' % (self._dots.index(dot), x, y)) + x = TEN - x - 1 + i = self._grid_to_dot((x, y)) + _logger.debug('%d: %d, %d' % (i, x, y)) + self._dots[i].type = dot.type + self._dots[i].set_shape(self._new_dot(self._colors[dot.type])) + if self.we_are_sharing: + _logger.debug('sending a robot click to the share') + self._parent.send_dot_click(i, dot.type) + elif self._orientation == 'vertical': + y = SIX - y - 1 + i = self._grid_to_dot((x, y)) + self._dots[i].type = dot.type + self._dots[i].set_shape(self._new_dot(self._colors[dot.type])) + if self.we_are_sharing: + _logger.debug('sending a robot click to the share') + self._parent.send_dot_click(i, dot.type) + else: + x = TEN - x - 1 + i = self._grid_to_dot((x, y)) + self._dots[i].type = dot.type + self._dots[i].set_shape(self._new_dot(self._colors[dot.type])) + if self.we_are_sharing: + _logger.debug('sending a robot click to the share') + self._parent.send_dot_click(i, dot.type) + y = SIX - y - 1 + i = self._grid_to_dot((x, y)) + self._dots[i].type = dot.type + self._dots[i].set_shape(self._new_dot(self._colors[dot.type])) + if self.we_are_sharing: + _logger.debug('sending a robot click to the share') + self._parent.send_dot_click(i, dot.type) + x = TEN - x - 1 + i = self._grid_to_dot((x, y)) + self._dots[i].type = dot.type + self._dots[i].set_shape(self._new_dot(self._colors[dot.type])) + if self.we_are_sharing: + _logger.debug('sending a robot click to the share') + self._parent.send_dot_click(i, dot.type) + def remote_button_press(self, dot, color): ''' Receive a button press from a sharer ''' self._dots[dot].type = color @@ -243,7 +292,7 @@ class Game(): def _dot_to_grid(self, dot): ''' calculate the grid column and row for a dot ''' - return [dot % TEN, int(dot / SIX)] + return [dot % TEN, int(dot / TEN)] def game_over(self, msg=_('Game over')): ''' Nothing left to do except show the results. ''' diff --git a/icons/robot-off.svg b/icons/robot-off.svg new file mode 100644 index 0000000..549e5c7 --- /dev/null +++ b/icons/robot-off.svg @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="55" + height="55" + id="svg2"> + <defs + id="defs4" /> + <rect + width="3.6656132" + height="9.5444069" + x="-42.845825" + y="-15.126163" + transform="matrix(-0.89091996,-0.45416035,-0.40870649,0.91266588,0,0)" + id="rect3687" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.72821403;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <rect + width="3.6656165" + height="9.5444155" + x="7.0011344" + y="9.6786585" + transform="matrix(0.89091996,-0.45416035,0.40870649,0.91266588,0,0)" + id="rect3685" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.72821581;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <rect + width="37.611328" + height="40.772209" + x="8.6943359" + y="9.8687277" + id="rect1919" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:2.46731305;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 25.841115,21.968429 a 6.4093275,6.355592 0 0 1 -12.818655,0 6.4093275,6.355592 0 1 1 12.818655,0 z" + id="path2794" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.48038781;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 42.429962,22.053175 a 6.4093275,6.355592 0 0 1 -12.818655,0 6.4093275,6.355592 0 1 1 12.818655,0 z" + id="path3669" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.48038781;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <rect + width="27.791536" + height="6.8113303" + ry="0" + x="14.056654" + y="39.380295" + id="rect3679" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.45960462;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 12.817797,23 c 13.050847,0.23305 13.050847,0 13.050847,0" + id="path2822" + style="fill:none;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + d="m 29.597458,23 c 13.050847,0.23305 13.050847,0 13.050847,0" + id="path2822-4" + style="fill:none;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> +</svg> diff --git a/icons/robot-on.svg b/icons/robot-on.svg new file mode 100644 index 0000000..85b9b19 --- /dev/null +++ b/icons/robot-on.svg @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="55" + height="55" + id="svg2"> + <defs + id="defs4" /> + <rect + width="3.6656132" + height="9.5444069" + x="-42.845825" + y="-15.126163" + transform="matrix(-0.89091996,-0.45416035,-0.40870649,0.91266588,0,0)" + id="rect3687" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.72821403;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <rect + width="3.6656165" + height="9.5444155" + x="7.0011344" + y="9.6786585" + transform="matrix(0.89091996,-0.45416035,0.40870649,0.91266588,0,0)" + id="rect3685" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.72821581;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <rect + width="37.611328" + height="40.772209" + x="8.6943359" + y="9.8687277" + id="rect1919" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:2.46731305;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 25.841115,21.968429 a 6.4093275,6.355592 0 0 1 -12.818655,0 6.4093275,6.355592 0 1 1 12.818655,0 z" + id="path2794" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.48038781;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 42.429962,22.053175 a 6.4093275,6.355592 0 0 1 -12.818655,0 6.4093275,6.355592 0 1 1 12.818655,0 z" + id="path3669" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.48038781;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <rect + width="27.334038" + height="11.947053" + ry="0" + x="14.285403" + y="34.015823" + id="rect3679" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.91710222;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 20.86446,21.646627 a 1.2818655,1.3676591 0 0 1 -2.563731,0 1.2818655,1.3676591 0 1 1 2.563731,0 z" + id="path3681" + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.48038781;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 37.754923,21.646627 a 1.2818655,1.3676591 0 0 1 -2.563731,0 1.2818655,1.3676591 0 1 1 2.563731,0 z" + id="path3683" + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.48038781;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /> + <path + d="m 14.228922,39.98935 26.843769,0" + id="path3689" + style="fill:#000000;fill-opacity:1;stroke:#ffffff;stroke-width:1.91710222;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 29.912923,33.955559 0,11.263071" + id="path3691" + style="fill:#000000;fill-opacity:1;stroke:#ffffff;stroke-width:1.91710222;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 24.483846,33.955559 0,11.263071" + id="path3693" + style="fill:#000000;fill-opacity:1;stroke:#ffffff;stroke-width:1.91710222;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 35.342002,33.955559 0,11.263071" + id="path3695" + style="fill:#000000;fill-opacity:1;stroke:#ffffff;stroke-width:1.91710222;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> + <path + d="m 19.205576,33.955559 0,11.263071" + id="path3697" + style="fill:#000000;fill-opacity:1;stroke:#ffffff;stroke-width:1.91710222;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> +</svg> |