diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-07-11 00:40:52 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-07-11 00:40:52 (GMT) |
commit | 18fa6026db0a84c2d9aaa293cb7746cc470ed377 (patch) | |
tree | 3cebdf5736dd8c3ddeb0191cf8bd542660a10aa0 | |
parent | f3d6d180825d03582446004b1c895ca745888501 (diff) |
Level choose added
-rw-r--r-- | activity.py | 46 | ||||
-rw-r--r-- | game.py | 10 | ||||
-rw-r--r-- | icons/2-glasses.svg | 94 | ||||
-rw-r--r-- | icons/3-glasses.svg | 94 | ||||
-rw-r--r-- | icons/4-glasses.svg | 94 |
5 files changed, 334 insertions, 4 deletions
diff --git a/activity.py b/activity.py index d9140fd..c7f9e98 100644 --- a/activity.py +++ b/activity.py @@ -18,7 +18,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import time import random +import simplejson from gi.repository import Gtk from gettext import gettext as _ @@ -37,6 +39,8 @@ class Guess(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle, True) + self._scores = {} + # Toolbars toolbarbox = ToolbarBox() @@ -46,6 +50,18 @@ class Guess(activity.Activity): separator = Gtk.SeparatorToolItem() toolbarbox.toolbar.insert(separator, -1) + two_glasses = ToolButton('2-glasses') + toolbarbox.toolbar.insert(two_glasses, -1) + + three_glasses = ToolButton('3-glasses') + toolbarbox.toolbar.insert(three_glasses, -1) + + four_glasses = ToolButton('4-glasses') + toolbarbox.toolbar.insert(four_glasses, -1) + + separator = Gtk.SeparatorToolItem() + toolbarbox.toolbar.insert(separator, -1) + self._reload_btn = ToolButton('gtk-refresh') self._reload_btn.set_sensitive(False) self._reload_btn.set_tooltip(_('Restart')) @@ -61,6 +77,7 @@ class Guess(activity.Activity): self.set_toolbar_box(toolbarbox) + # Canvas self._eventbox = Gtk.EventBox() self._game = Game() self._game.connect('won', self._win_or_lose_cb) @@ -68,10 +85,37 @@ class Guess(activity.Activity): self._eventbox.add(self._game) self.set_canvas(self._eventbox) + # Callbacks self._reload_btn.connect('clicked', self._game.reload) + two_glasses.connect('clicked', self._game.reload, 2) + three_glasses.connect('clicked', self._game.reload, 3) + four_glasses.connect('clicked', self._game.reload, 4) self.show_all() - self._game.add_glasses(3, random.randrange(1, 4)) + self._game.add_glasses(2, random.randrange(1, 3)) + self._game._glasses = 2 def _win_or_lose_cb(self, widget): self._reload_btn.set_sensitive(True) + + def read_file(self, file_path): + scores_file = open(file_path) + self._scores = simplejson.load(scores_file) + scores_file.close() + + def write_file(self, file_path): + score = self._game.score + + num = 1 + date = time.strftime("%d/%m/%y - " + str(num)) + + for i in self._scores.keys(): + if date in self._scores: + num += 1 + date = time.strftime("%d/%m/%y - " + str(num)) + + self._scores[date] = score + + scores_file = open(file_path, 'w') + simplejson.dump(self._scores, scores_file) + scores_file.close() @@ -50,6 +50,7 @@ class Game(Gtk.Fixed): self.put(self._score_label, 5, 5) self.score = 0 + self.glasses = 2 self._glasses_box = Gtk.Box() self._glasses_box.set_spacing(30) @@ -66,8 +67,11 @@ class Game(Gtk.Fixed): self.connect('draw', self._draw_event_cb) - def reload(self, widget): - widget.set_sensitive(False) + def reload(self, widget, glasses=None): + if widget.props.icon_name == 'gtk-refresh': + widget.set_sensitive(False) + if glasses: + self._glasses = glasses pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('icons/neutral.svg', SMILY_SIZE, SMILY_SIZE) self._smily.set_from_pixbuf(pixbuf) @@ -77,7 +81,7 @@ class Game(Gtk.Fixed): self.queue_draw() random.seed() - self.add_glasses(3, random.randrange(1, 4)) + self.add_glasses(self._glasses, random.randrange(1, self._glasses + 1)) def lose(self): if not self.score <= 0: diff --git a/icons/2-glasses.svg b/icons/2-glasses.svg new file mode 100644 index 0000000..55425c1 --- /dev/null +++ b/icons/2-glasses.svg @@ -0,0 +1,94 @@ +<?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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="55" + height="55" + id="svg2" + version="1.1" + inkscape:version="0.48.2 r9819" + sodipodi:docname="2-glasses.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="5.9900718" + inkscape:cx="-14.67991" + inkscape:cy="21.795019" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:window-width="1280" + inkscape:window-height="741" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" /> + <metadata + id="metadata7"> + <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 /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-25.461093,-978.89671)"> + <text + xml:space="preserve" + style="font-size:32.33923721000000029px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans" + x="53.815216" + y="1084.2871" + id="text3137" + sodipodi:linespacing="125%" + transform="scale(1.0602075,0.94321159)"><tspan + sodipodi:role="line" + id="tspan3139" + x="53.815216" + y="1084.2871" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Khmer OS;-inkscape-font-specification:Khmer OS;fill:#ffffff">2</tspan></text> + <path + style="fill:none;stroke:#ffffff;stroke-width:1.55600000000000005;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + d="m 35.892073,1016.9062 23.896912,0 -4.636714,-29.47338 -14.980154,0 z" + id="path2985" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccc" /> + <path + style="fill:none;stroke:#ffffff;stroke-width:1.55600000000000005;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + d="m 39.82961,990.48176 16.050165,0 z" + id="path2987" + inkscape:connector-curvature="0" /> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" + x="38.084335" + y="32.204994" + id="text3133" + sodipodi:linespacing="125%" + transform="translate(25.461093,978.89671)"><tspan + sodipodi:role="line" + id="tspan3135" /></text> + </g> +</svg> diff --git a/icons/3-glasses.svg b/icons/3-glasses.svg new file mode 100644 index 0000000..0e0da3f --- /dev/null +++ b/icons/3-glasses.svg @@ -0,0 +1,94 @@ +<?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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="55" + height="55" + id="svg2" + version="1.1" + inkscape:version="0.48.2 r9819" + sodipodi:docname="3-glasses.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="3.9315137" + inkscape:cx="-36.145485" + inkscape:cy="24.093801" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:window-width="1280" + inkscape:window-height="741" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" /> + <metadata + id="metadata7"> + <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 /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-25.461093,-978.89671)"> + <text + xml:space="preserve" + style="font-size:34.93960571px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans" + x="57.952641" + y="1007.7318" + id="text3137" + sodipodi:linespacing="125%" + transform="scale(0.98130188,1.0190544)"><tspan + sodipodi:role="line" + id="tspan3139" + x="57.952641" + y="1007.7318" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;fill-opacity:1;font-family:Khmer OS;-inkscape-font-specification:Khmer OS">3</tspan></text> + <path + style="fill:none;stroke:#ffffff;stroke-width:1.55600000000000005;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + d="m 35.892073,1016.9062 23.896912,0 -4.636714,-29.47338 -14.980154,0 z" + id="path2985" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccc" /> + <path + style="fill:none;stroke:#ffffff;stroke-width:1.55600000000000005;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + d="m 39.82961,990.48176 16.050165,0 z" + id="path2987" + inkscape:connector-curvature="0" /> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" + x="38.084335" + y="32.204994" + id="text3133" + sodipodi:linespacing="125%" + transform="translate(25.461093,978.89671)"><tspan + sodipodi:role="line" + id="tspan3135" /></text> + </g> +</svg> diff --git a/icons/4-glasses.svg b/icons/4-glasses.svg new file mode 100644 index 0000000..1793193 --- /dev/null +++ b/icons/4-glasses.svg @@ -0,0 +1,94 @@ +<?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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="55" + height="55" + id="svg2" + version="1.1" + inkscape:version="0.48.2 r9819" + sodipodi:docname="4-glasses.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="14.754467" + inkscape:cx="3.2692845" + inkscape:cy="33.550462" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:window-width="1280" + inkscape:window-height="741" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" /> + <metadata + id="metadata7"> + <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 /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-25.461093,-978.89671)"> + <text + xml:space="preserve" + style="font-size:32.33923721000000029px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans" + x="54.732922" + y="1086.8667" + id="text3137" + sodipodi:linespacing="125%" + transform="scale(1.0602075,0.94321159)"><tspan + sodipodi:role="line" + id="tspan3139" + x="54.732922" + y="1086.8667" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Khmer OS;-inkscape-font-specification:Khmer OS;fill:#ffffff">4</tspan></text> + <path + style="fill:none;stroke:#ffffff;stroke-width:1.556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + d="m 35.892073,1016.9062 23.896912,0 -4.636714,-29.47338 -14.980154,0 z" + id="path2985" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccc" /> + <path + style="fill:none;stroke:#ffffff;stroke-width:1.556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + d="m 39.82961,990.48176 16.050165,0 z" + id="path2987" + inkscape:connector-curvature="0" /> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans" + x="38.084335" + y="32.204994" + id="text3133" + sodipodi:linespacing="125%" + transform="translate(25.461093,978.89671)"><tspan + sodipodi:role="line" + id="tspan3135" /></text> + </g> +</svg> |