diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-12-16 17:12:30 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-12-16 17:12:30 (GMT) |
commit | 3ba707764efec300137d26a1fad26926321fc423 (patch) | |
tree | ac7269631533f5e672ffec0281665333c3cfbc3b | |
parent | 60a692f9cf431dd14d562441e4aae7da92b13343 (diff) |
reorg of toolbar
-rw-r--r-- | TurtlePondActivity.py | 20 | ||||
-rw-r--r-- | game.py | 60 | ||||
-rw-r--r-- | icons/pippy-openoff.svg | 56 | ||||
-rw-r--r-- | icons/pippy-reload.svg | 115 |
4 files changed, 67 insertions, 184 deletions
diff --git a/TurtlePondActivity.py b/TurtlePondActivity.py index f9ebfbc..8028b2a 100644 --- a/TurtlePondActivity.py +++ b/TurtlePondActivity.py @@ -52,7 +52,8 @@ BEGINNER = 0 INTERMEDIATE = 1 EXPERT = 2 CUSTOM = 3 -LEVEL_LABELS = [_('beginner'), _('intermediate'), _('expert'), _('custom')] +LEVEL_LABELS = [_('Beginner'), _('Intermediate'), _('Expert'), + _('My strategy')] class TurtlePondActivity(activity.Activity): @@ -155,11 +156,6 @@ class TurtlePondActivity(activity.Activity): self._do_load_python_cb, tooltip=_('Load strategy from Journal')) - self.reload_strategy = button_factory( - 'pippy-reload', self.toolbar, - self._do_reset_strategy_cb, - tooltip=_('Load default strategy')) - if _have_toolbox: stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>q' @@ -167,6 +163,9 @@ class TurtlePondActivity(activity.Activity): stop_button.show() def _level_cb(self, button, level): + if level == CUSTOM and self._game.strategies[CUSTOM] is None: + level = EXPERT + self.expert_button.set_active(True) self._game.level = level self._game.new_game() @@ -182,16 +181,12 @@ class TurtlePondActivity(activity.Activity): """ Restore the game state from metadata """ return - def _do_reset_strategy_cb(self, button): - ''' Reset the strategy to default ''' - self._game.reset_strategy() - self._game.new_game() - def _do_load_python_cb(self, button): ''' Load Python code from the Journal. ''' self._chooser('org.laptop.Pippy', self._load_python_code_from_journal) - self.custom_button.set_active(True) + if self._game.strategies[CUSTOM] is not None: + self.custom_button.set_active(True) self._game.level = CUSTOM self._game.new_game() @@ -206,7 +201,6 @@ class TurtlePondActivity(activity.Activity): except IOError: _logger.debug("couldn't open %s" % dsobject.file_path) self._game.strategies[CUSTOM] = python_code - self._game.msgs[CUSTOM] = _('customized strategy') def _chooser(self, filter, action): ''' Choose an object from the datastore and take some action ''' @@ -40,9 +40,7 @@ CIRCLE = [[(0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0), (-1, -1)], [(1, -1), (1, 0), (1, 1), (0, 1), (-1, 0), (0, -1)]] ''' Simple strategy: head to daylight or randomly check for an open dot turtle is the (col, row) of the current turtle position ''' -BEGINNER_MSG = _('random') BEGINNER_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ - self._set_label(self.strategy_msg)\n\ dots = self._surrounding_dots(turtle)\n\ n = int(uniform(0, 6))\n\ for i in range(6):\n\ @@ -51,7 +49,6 @@ BEGINNER_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ return self._dot_to_grid(dots[(i + n) % 6])\n\ self._orientation = (i + n) % 6\n\ return turtle\n' -INTERMEDIATE_MSG = _('looking for an open path') INTERMEDIATE_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ dots = self._surrounding_dots(turtle)\n\ for i in range(6): # search for an edge\n\ @@ -66,9 +63,7 @@ INTERMEDIATE_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ self._orientation = (i + n) % 6\n\ return self._dot_to_grid(dots[(i + n) % 6])\n\ return turtle\n' -EXPERT_MSG = _('using a weight function') EXPERT_STRATEGY = 'def _turtle_strategy(self, turtle):\n\ - self._set_label(self.strategy_msg)\n\ dots = self._surrounding_dots(turtle)\n\ for i in range(6):\n\ if self._dots[dots[i]].type is None:\n\ @@ -110,13 +105,11 @@ class Game(): self._space = int(self._dot_size / 5.) self._orientation = 0 self.level = 0 - self.custom_strategy = EXPERT_STRATEGY + self.custom_strategy = None self.strategies = [BEGINNER_STRATEGY, INTERMEDIATE_STRATEGY, EXPERT_STRATEGY, self.custom_strategy] - self.msgs = [BEGINNER_MSG, INTERMEDIATE_MSG, - EXPERT_MSG, _('strategy from Journal')] self.strategy = self.strategies[self.level] - self.strategy_msg = self.msgs[self.level] + self._timeout_id = None # Generate the sprites we'll need... self._sprites = Sprites(self._canvas) @@ -141,17 +134,22 @@ class Game(): self._new_dot(self._colors[FILL]))) self._dots[-1].type = False # not set - # Put a turtle at the center of the screen + # Put a turtle at the center of the screen... self._turtle_images = [] self._rotate_turtle(self._new_turtle()) - pos = self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy() - self._turtle = Sprite(self._sprites, pos[0], pos[1], + self._turtle = Sprite(self._sprites, 0, 0, self._turtle_images[0]) - self._turtle.move_relative((-self._turtle_offset, -self._turtle_offset)) + self._move_turtle(self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy()) - # and initialize a few variables we'll need. + # ...and initialize. self._all_clear() + def _move_turtle(self, pos): + ''' Move turtle and add its offset ''' + self._turtle.move(pos) + self._turtle.move_relative( + (-self._turtle_offset, -self._turtle_offset)) + def _all_clear(self): ''' Things to reinitialize when starting up a new game. ''' # Clear dots @@ -162,24 +160,11 @@ class Game(): dot.set_label('') # Recenter the turtle - pos = self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy() - self._turtle.move(pos) - self._turtle.move_relative((-self._turtle_offset, -self._turtle_offset)) + self._move_turtle(self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy()) self._turtle.set_shape(self._turtle_images[0]) self._set_label('') - ''' - self._set_label( - _('Click on the dots to keep the turtle from escaping.')) - ''' - - def _initiating(self): - return self._activity.initiating - - def reset_strategy(self): - ''' Reload default strategy ''' - self.custom_strategy = EXPERT_STRATEGY - self.custom_msg = _('strategy from Journal') - self.level = 3 + if self._timeout_id is not None: + gobject.source_remove(self._timeout_id) def new_game(self, saved_state=None): ''' Start a new game. ''' @@ -195,7 +180,6 @@ class Game(): # Calculate the distances to the edge self._initialize_weights() self.strategy = self.strategies[self.level] - self.strategy_msg = self.msgs[self.level] def _set_label(self, string): ''' Set the label in the toolbar or the window frame. ''' @@ -241,10 +225,7 @@ class Game(): new_dot = self._grid_to_dot( self._my_strategy_import(self.strategy, self._dot_to_grid(self._turtle_dot))) - pos = self._dots[new_dot].get_xy() - self._turtle.move(pos) - # Turtle is offset - self._turtle.move_relative((-self._turtle_offset, -self._turtle_offset)) + self._move_turtle(self._dots[new_dot].get_xy()) # And set the orientation self._turtle.set_shape(self._turtle_images[self._orientation]) @@ -255,7 +236,7 @@ class Game(): if new_dot is None: return if self._dots[new_dot].type is None: - # self._set_label(_('turtle wins')) + # Game-over feedback self._once_around = False self._happy_turtle_dance() return True @@ -272,7 +253,7 @@ class Game(): new_dot + CIRCLE[c][4][0] + THIRTEEN * CIRCLE[c][4][1]].type and \ self._dots[ new_dot + CIRCLE[c][5][0] + THIRTEEN * CIRCLE[c][5][1]].type: - # self._set_label(_('you win')) + # Game-over feedback for dot in self._dots: dot.set_label(':)') return True @@ -306,12 +287,11 @@ class Game(): x -= 1 i = self._grid_to_dot((x, y)) self._dots[i].set_label(':)') - self._turtle.move(self._dots[i].get_xy()) - self._turtle.move_relative((-self._turtle_offset, -self._turtle_offset)) + self._move_turtle(self._dots[i].get_xy()) self._orientation += 1 self._orientation %= 6 self._turtle.set_shape(self._turtle_images[self._orientation]) - gobject.timeout_add(250, self._happy_turtle_dance) + self._timeout_id = gobject.timeout_add(250, self._happy_turtle_dance) def _ordered_weights(self, pos): ''' Returns the list of surrounding points sorted by their diff --git a/icons/pippy-openoff.svg b/icons/pippy-openoff.svg index 605e62a..e22e042 100644 --- a/icons/pippy-openoff.svg +++ b/icons/pippy-openoff.svg @@ -99,21 +99,6 @@ <g - transform="matrix(1.1181651,0,0,1.1181651,61.470731,-23.367585)" - id="g3348" - style="fill:none"><path - d="m -19.754174,46.744351 c 3.555069,0 8.83424,-1.56838 8.83424,-6.181226 0,-5.131219 -4.597011,-5.60538 -6.503378,-6.124857 -2.107038,-0.441556 -3.510542,-1.057744 -3.594847,-1.909356 -0.144269,-1.460061 0.687503,-2.028723 2.342736,-2.028723 0,0 3.937412,2.024856 7.282311,0.40895 0.942794,-0.454819 2.631273,-2.579702 2.631273,-4.04529 0,-1.466142 -5.450749,-3.160522 -7.104794,-3.160522 -1.655233,0 -3.062894,2.125988 -3.062894,2.125988 -3.309277,0 -6.619149,2.932283 -6.619149,5.864566 0,2.93173 3.166197,5.225166 6.950433,5.864565 1.759131,0.259187 3.230316,1.226851 2.896064,3.005231 -0.27132,1.444036 -1.778128,2.932283 -4.963917,2.932283 -2.524407,0 -7.896195,-0.121026 -8.75409,-2.254199 -0.551547,-1.373851 0.09974,-2.876467 0.927358,-2.876467 l -0.01603,-0.08842 c -0.843052,-0.08732 -3.293841,0.08842 -3.293841,3.020151 -5.94e-4,3.759026 5.428782,5.447327 12.048526,5.447327 z" - id="path2474" - style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path - d="m -11.393706,30.909692 c -1.557272,-0.158607 -3.924943,-1.105272 -4.43315,-2.775335" - id="path2476" - style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><circle - cx="35.805" - cy="10.96" - r="1.676" - transform="matrix(0.59369893,0,0,0.5526353,-36.672813,19.93767)" - id="circle2478" - style="fill:none;stroke-width:3.42034841;stroke-miterlimit:4;stroke-dasharray:none" /></g><g transform="translate(-2.2743816,2.513511)" id="g3036" style="overflow:visible"><path @@ -130,4 +115,43 @@ transform="matrix(-0.469241,0.469241,-0.469241,-0.469241,66.2906,1019.03)" /><path d="m 39.363241,1033.1291 -0.05636,9.9115 -8.750608,0.067" id="path4776-5" - style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g></g></svg>
\ No newline at end of file + style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g></g><g + transform="matrix(0.50000001,0,0,0.50000001,23.753499,3.7645)" + id="g3862"> + <polygon + points="26.891,12.363 17.238,16.369 14.659,4.975 20.555,2.531 " + id="polygon3864" + style="fill:#ffffff" /> + <polygon + points="42.646,26.88 38.649,17.228 50.04,14.654 52.477,20.55 " + id="polygon3866" + style="fill:#ffffff" /> + <polygon + points="28.117,42.645 37.775,38.645 40.349,50.029 34.453,52.471 " + id="polygon3868" + style="fill:#ffffff" /> + <polygon + points="37.824,16.315 28.171,12.309 34.394,2.439 40.295,4.882 " + id="polygon3870" + style="fill:#ffffff" /> + <polygon + points="38.628,37.791 42.623,28.139 52.493,34.365 50.055,40.258 " + id="polygon3872" + style="fill:#ffffff" /> + <polygon + points="16.385,37.76 12.391,28.105 2.515,34.34 4.953,40.234 " + id="polygon3874" + style="fill:#ffffff" /> + <polygon + points="12.319,26.875 16.32,17.216 4.936,14.643 2.493,20.539 " + id="polygon3876" + style="fill:#ffffff" /> + <polygon + points="26.939,42.623 17.287,38.629 14.719,50.018 20.609,52.461 " + id="polygon3878" + style="fill:#ffffff" /> + <path + d="m 39.925,22.352 c 2.845,6.863 -0.412,14.728 -7.274,17.574 -6.867,2.85 -14.734,-0.418 -17.578,-7.281 -2.84,-6.862 0.418,-14.733 7.279,-17.572 6.862,-2.845 14.734,0.417 17.573,7.279 z" + id="path3880" + style="fill:none;stroke:#ffffff;stroke-width:11.69439983" /> +</g></svg>
\ No newline at end of file diff --git a/icons/pippy-reload.svg b/icons/pippy-reload.svg deleted file mode 100644 index 340dec1..0000000 --- a/icons/pippy-reload.svg +++ /dev/null @@ -1,115 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Created with Inkscape (http://www.inkscape.org/) --> - -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - version="1.1" - width="55.125" - height="55" - viewBox="0 0 55.125 55" - id="svg2" - xml:space="preserve"><metadata - id="metadata11"><rdf:RDF><cc:Work - rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs - id="defs9"> - - - - - -<linearGradient - x1="0.94254935" - y1="-31.669659" - x2="104.37702" - y2="20.434471" - id="linearGradient3172" - xlink:href="#linearGradient3166" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(0.7083638,0,0,1.0012565,0.1338084,32.632067)" /><linearGradient - id="linearGradient3166"><stop - id="stop3168" - style="stop-color:#ffffff;stop-opacity:1" - offset="0" /><stop - id="stop3170" - style="stop-color:#ffff00;stop-opacity:1" - offset="1" /></linearGradient><linearGradient - x1="0" - y1="22" - x2="74" - y2="22" - id="linearGradient3172-9" - xlink:href="#linearGradient3166-6" - gradientUnits="userSpaceOnUse" /><linearGradient - id="linearGradient3166-6"><stop - id="stop3168-5" - style="stop-color:#ffffff;stop-opacity:1" - offset="0" /><stop - id="stop3170-6" - style="stop-color:#ff0000;stop-opacity:1" - offset="1" /></linearGradient> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</defs><path - d="m 27.564022,52.678344 c -5.524281,0 -9.998541,-4.477177 -10.001458,-9.998542 0.0022,-4.154149 2.533178,-7.720577 6.147003,-9.226338 0.69564,-0.292402 1.496281,0.035 1.785766,0.732828 0.293132,0.69564 -0.03719,1.495552 -0.732098,1.788683 -2.624326,1.097419 -4.466968,3.686014 -4.464781,6.704827 0.0073,4.010501 3.250693,7.25536 7.265568,7.262652 4.009771,-0.0073 7.25536,-3.252151 7.261922,-7.262652 0.0015,-2.440571 -1.219921,-4.58072 -3.066938,-5.897623 l 0.850955,2.124107 c 0.280735,0.702932 -0.06052,1.498469 -0.762724,1.778475 -0.166983,0.06563 -0.337612,0.09771 -0.505323,0.09771 -0.542512,0 -1.056585,-0.325944 -1.270235,-0.860434 L 27.99351,34.72297 c -0.01312,-0.03208 -0.0058,-0.06781 -0.01604,-0.100627 -0.035,-0.109377 -0.04885,-0.219484 -0.05469,-0.336882 -0.0036,-0.07656 -0.0095,-0.149482 -0.0015,-0.226047 0.0051,-0.03719 -0.0073,-0.07219 0,-0.109377 0.01677,-0.08094 0.06344,-0.145107 0.09188,-0.220213 0.01969,-0.05104 0.0175,-0.107189 0.04375,-0.156045 0.01094,-0.01969 0.03136,-0.03063 0.04302,-0.04958 0.06708,-0.110836 0.152399,-0.200525 0.245734,-0.287298 0.04448,-0.04083 0.07729,-0.08969 0.126149,-0.12469 0.14219,-0.102085 0.301152,-0.174274 0.473239,-0.215838 0.0124,-0.0029 0.01969,-0.0124 0.03208,-0.01531 l 0.0058,-7.3e-4 c 0.0029,-7.29e-4 0.0051,-7.29e-4 0.0087,-0.0015 l 5.459385,-1.168149 c 0.737932,-0.159691 1.463468,0.310631 1.620971,1.050022 0.158233,0.737932 -0.313548,1.462738 -1.050022,1.623158 l -1.45253,0.311361 c 2.423801,1.823684 3.991542,4.718536 3.993,7.986 -0.0015,5.519906 -4.478635,9.997083 -9.998542,9.997083 z" - id="path5" - style="fill:#ffffff;fill-opacity:1;stroke:none;display:inline" /><g - transform="matrix(1.038303,0,0,1.038303,48.621641,-19.573104)" - id="g3348" - style="fill:none"><path - d="m -19.754174,46.744351 c 3.555069,0 8.83424,-1.56838 8.83424,-6.181226 0,-5.131219 -4.597011,-5.60538 -6.503378,-6.124857 -2.107038,-0.441556 -3.510542,-1.057744 -3.594847,-1.909356 -0.144269,-1.460061 0.687503,-2.028723 2.342736,-2.028723 0,0 3.937412,2.024856 7.282311,0.40895 0.942794,-0.454819 2.631273,-2.579702 2.631273,-4.04529 0,-1.466142 -5.450749,-3.160522 -7.104794,-3.160522 -1.655233,0 -3.062894,2.125988 -3.062894,2.125988 -3.309277,0 -6.619149,2.932283 -6.619149,5.864566 0,2.93173 3.166197,5.225166 6.950433,5.864565 1.759131,0.259187 3.230316,1.226851 2.896064,3.005231 -0.27132,1.444036 -1.778128,2.932283 -4.963917,2.932283 -2.524407,0 -7.896195,-0.121026 -8.75409,-2.254199 -0.551547,-1.373851 0.09974,-2.876467 0.927358,-2.876467 l -0.01603,-0.08842 c -0.843052,-0.08732 -3.293841,0.08842 -3.293841,3.020151 -5.94e-4,3.759026 5.428782,5.447327 12.048526,5.447327 z" - id="path2474" - style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path - d="m -11.393706,30.909692 c -1.557272,-0.158607 -3.924943,-1.105272 -4.43315,-2.775335" - id="path2476" - style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><circle - cx="35.805" - cy="10.96" - r="1.676" - transform="matrix(0.59369893,0,0,0.5526353,-36.672813,19.93767)" - id="circle2478" - style="fill:none;stroke-width:3.42034841;stroke-miterlimit:4;stroke-dasharray:none" /></g></svg>
\ No newline at end of file |