[gcompris] braille fun: refarcored the code, tuned the difficulty.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] braille fun: refarcored the code, tuned the difficulty.
- Date: Sun, 4 Sep 2011 21:53:42 +0000 (UTC)
commit 449ee97a5cce681e00d2e2ee0818e79d8396a1ae
Author: Bruno Coudoin <bruno coudoin free fr>
Date: Sun Sep 4 23:52:26 2011 +0200
braille fun: refarcored the code, tuned the difficulty.
src/braille_alphabets-activity/BrailleChar.py | 4 +-
src/braille_fun-activity/braille_fun.py | 233 +++++++++++--------------
2 files changed, 102 insertions(+), 135 deletions(-)
---
diff --git a/src/braille_alphabets-activity/BrailleChar.py b/src/braille_alphabets-activity/BrailleChar.py
index 40fa41d..9a7037e 100644
--- a/src/braille_alphabets-activity/BrailleChar.py
+++ b/src/braille_alphabets-activity/BrailleChar.py
@@ -63,9 +63,7 @@ class BrailleChar:
height = width * 1.33
self.rootitem = goocanvas.Group(parent = rootitem)
- if(letter == '' or rectangle == False):
- """no rect"""
- else :
+ if(rectangle):
self.item = goocanvas.Rect(parent = self.rootitem,
x = x,
y = y,
diff --git a/src/braille_fun-activity/braille_fun.py b/src/braille_fun-activity/braille_fun.py
index 747bdc0..d7acecf 100644
--- a/src/braille_fun-activity/braille_fun.py
+++ b/src/braille_fun-activity/braille_fun.py
@@ -28,18 +28,11 @@ import gcompris.score
import goocanvas
import pango
import random
-import string
from BrailleChar import *
from BrailleMap import *
from gcompris import gcompris_gettext as _
-COLOR_ON = 0X00FFFF
-COLOR_OFF = 0X000000
-CIRCLE_FILL = "light green"
-CIRCLE_STROKE = "black"
-CELL_WIDTH = 30
-
class Gcompris_braille_fun:
"""Empty gcompris python class"""
@@ -50,12 +43,11 @@ class Gcompris_braille_fun:
self.gcomprisBoard = gcomprisBoard
self.gcomprisBoard.level=1
self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = 3
- self.gcomprisBoard.maxlevel = 5
+ self.gcomprisBoard.number_of_sublevel = 26
+ self.gcomprisBoard.maxlevel = 3
self.text_color = 0X0000FFFFL
self.counter = 0
self.timerAnim = 0
- self.delay = 40
#Boolean variable declaration
self.mapActive = False
@@ -63,7 +55,7 @@ class Gcompris_braille_fun:
# These are used to let us restart only after the bonus is displayed.
# When the bonus is displayed, it call us first with pause(1) and then with pause(0)
self.board_paused = 0
- self.gamewon = 0
+ self.gamewon = False
#Array declaration
self.letter_array = []
@@ -103,10 +95,9 @@ class Gcompris_braille_fun:
BrailleMap(self.map_rootitem, self.move_back)
self.map_rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
- #Display the sublevel
+ # Display the sublevel
gcompris.score.start(gcompris.score.STYLE_NOTE, 530, 460,
self.gcomprisBoard.number_of_sublevel)
- gcompris.score.set(self.gcomprisBoard.sublevel)
# Set a background image
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
@@ -119,142 +110,122 @@ class Gcompris_braille_fun:
self.mapActive = False
def display_game(self, level):
- #SVG Handle for TUX Plane
+
+ gcompris.score.set(self.gcomprisBoard.sublevel)
+
+ self.planeroot = goocanvas.Group( parent =
+ self.root )
+ # SVG Handle for TUX Plane
svghandle = gcompris.utils.load_svg("braille_fun/plane.svg")
self.tuxplane = goocanvas.Svg(
- parent = self.root,
+ parent = self.planeroot,
svg_handle = svghandle,
- svg_id = "#PLANE",
- tooltip = _("I am TUX PLANE")
+ svg_id = "#PLANE"
)
self.tuxplane.translate(50 * level, 40 )
- #Animated Tux plane.Move from left to right
- self.tuxplane.animate(900,
- 20 ,
- 1,
- 1,
- True,
- 25000 + level * 9000,
- 250,
- goocanvas.ANIMATE_FREEZE)
-
- for index in range (level) :
- #Select a random letter and append it to self.letter_array
+ # Animated Tux plane.Move from left to right
+ self.planeroot.animate(900,
+ 20 ,
+ 1,
+ 1,
+ True,
+ 25000 + level * 9000,
+ 250,
+ goocanvas.ANIMATE_FREEZE)
+
+ string = "abcdefghijklmnopqrstuvwxyz"
+ for index in range (level):
+ # Select a random letter and append it to self.letter_array
if (level == 1):
- #Letters from A to J
- letter = random.choice(string.letters[random.randint(0,9)])
+ letter = string[self.gcomprisBoard.sublevel - 1]
elif(level == 2):
- #Letters from K to T
- letter = random.choice(string.letters[random.randint(10,18)])
+ letter = random.choice(string[random.randint(0, 9)])
elif(level == 3):
- #Letters from U to Z
- letter = random.choice(string.letters[random.randint(19,25)])
+ letter = random.choice(string[random.randint(10,19)])
+ elif(level == 4):
+ letter = random.choice(string[random.randint(20, 25)])
else :
- letter = random.choice(string.letters[random.randint(0,25)])
-
- self.letter_array.append(letter.upper())
- self.animateString = "".join(self.letter_array)
-
- #Display rectangle for braille tile
- goocanvas.Rect(parent=self.root,
- x = 300 + 90 * index,
- y = 155,
- width = 80 ,
- height = 100,
- stroke_color = "black",
- fill_color = "#DfDfDf",
- line_width=2.0)
-
- #Naming Objects from Variable Class Names and appending
- #to array self.tile_array
- self.obj = "self.obj" + str(index)
- self.tile_array.append(self.obj)
-
- #Defining Object to BrailleChar Instance to produce braille_tile
- self.tile_array[index] = BrailleChar(self.root, 300 + 90 * index , 150, 80,
- '',COLOR_ON ,COLOR_OFF, "#DfDfDf","black",
- True, True ,True, callback = self.letter_change)
-
- #Display alphabets for TUX_PLANE horizontally and vertically
- lengthString = len(self.animateString)
- for index in range(lengthString):
- self.alphabet_horizontal = goocanvas.Text(
- parent = self.horizontalTextRoot,
- x = 50 * index ,
- y = 60.0 ,
- text = self.animateString[index],
- fill_color="black",
- anchor = gtk.ANCHOR_CENTER,
- alignment = pango.ALIGN_CENTER,
- font = 'SANS 50'
- )
+ letter = random.choice(string[random.randint(0,25)])
+
+ self.letter_array.append( letter.upper() )
+
+ # Defining Object to BrailleChar Instance to produce braille_tile
+ self.tile_array.append( \
+ BrailleChar(self.root,
+ 300 + 90 * index , 150, 80,
+ '', 0xFF0000FFL, 0xFFFFFFFFL,
+ "white", "black",
+ True, True, True, callback = self.letter_change) )
+
+ # Display alphabets for TUX_PLANE horizontally and vertically
+ animateString = "".join(self.letter_array)
+ for index in range( len(animateString) ):
+ goocanvas.Text(
+ parent = self.planeroot,
+ x = 50 * index ,
+ y = 60.0 ,
+ text = animateString[index],
+ fill_color="black",
+ anchor = gtk.ANCHOR_CENTER,
+ alignment = pango.ALIGN_CENTER,
+ font = 'SANS 50'
+ )
self.alphabet_vertical = goocanvas.Text(
parent = self.verticalTextRoot,
- x=50.0 + 50 * index ,
- y=130.0 ,
- text=self.animateString[index],
- fill_color="black",
+ x = 50.0 + 50 * index ,
+ y = 130.0 ,
+ text = animateString[index],
+ fill_color = "black",
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
font = 'SANS 50'
)
self.alphabet_array.append(self.alphabet_vertical)
- #Animate or move letters horizontally and vertically
- self.horizontalTextRoot.animate(900,
- 5,
- 1,
- 1,
- True,
- 20000 + level * 16000,
- 250,
- goocanvas.ANIMATE_FREEZE)
-
- self.verticalTextRoot.animate(5,
- 415,
- 1,
- 1,
- True,
- 30000 + level * 5000,
- 250,
- goocanvas.ANIMATE_FREEZE)
-
- #To call a function when animation finishes
+ # Animate or move letters vertically
+ self.verticalTextRoot.animate( 5,
+ 415,
+ 1,
+ 1,
+ True,
+ 30000 + level * 5000,
+ 250,
+ goocanvas.ANIMATE_FREEZE )
+
+ # To call a function when animation finishes
self.verticalTextRoot.connect("animation-finished", self.animationFinished)
def letter_change(self, letter):
self.letter = letter
for index in range(self.gcomprisBoard.level):
- #Change the text color of alphabet correctly identified in the braille tile
+ # Change the text color of alphabet correctly identified in the braille tile
if (self.tile_array[index].get_letter() == self.letter_array[index]):
- self.alphabet_array[index].set_property("fill_color_rgba",self.text_color)
+ self.alphabet_array[index].set_property("fill_color_rgba",
+ self.text_color)
- #If an alphabet's color changes to blue the counter is increased
- #and the index number of tile is appended to a self.tile_index_array
+ # If an alphabet's color changes to blue the counter is increased
+ # and the index number of tile is appended to a self.tile_index_array
if self.alphabet_array[index].get_property("fill_color_rgba") == self.text_color \
and index not in self.tile_index_array :
self.tile_index_array.append(index)
self.counter +=1
- #If counter equals level number then call a timer_loop
+ # If counter equals level number then call a timer_loop
if (self.counter == self.gcomprisBoard.level) :
- self.timerAnim = gobject.timeout_add(40, self.timer_loop)
+ self.timerAnim = gobject.timeout_add(1000, self.timer_loop)
- #This timer loop is to wait for milliseconds before calling a
- #Bonus API
+ # This timer loop is to wait for milliseconds before calling a Bonus API
def timer_loop(self):
- self.delay -= 1
- if(self.delay == 0):
- self.gamewon = 1
- gcompris.bonus.display(gcompris.bonus.WIN,gcompris.bonus.SMILEY)
- self.delay = 40
- if self.delay < 40 :
- gobject.timeout_add(self.delay,self.timer_loop)
+ print "timer_loop"
+ self.gamewon = True
+ gcompris.bonus.display(gcompris.bonus.WIN,gcompris.bonus.SMILEY)
def animationFinished(self, item, status):
+ print "animationFinished"
if (self.counter != self.gcomprisBoard.level) :
+ self.gamewon = False
gcompris.bonus.display(gcompris.bonus.LOOSE,gcompris.bonus.SMILEY)
def end(self):
@@ -265,7 +236,7 @@ class Gcompris_braille_fun:
self.verticalTextRoot.remove()
def ok(self):
- print("braille_fun ok.")
+ pass
def repeat(self):
if(self.mapActive):
@@ -277,32 +248,29 @@ class Gcompris_braille_fun:
def config(self):
- print("braille_fun config.")
+ pass
def key_press(self, keyval, commit_str, preedit_str):
- utf8char = gtk.gdk.keyval_to_unicode(keyval)
- strn = u'%c' % utf8char
-
- print("Gcompris_braille_fun key press keyval=%i %s" % (keyval, strn))
+ pass
def pause(self, pause):
self.board_paused = pause
- #This is to hide the Repeat board
+ # This is to hide the Repeat board
if self.mapActive == True:
- self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
- if(self.board_paused) and (self.gamewon == 1):
- self.gamewon = 0
- self.declare()
+ self.root.props.visibility = goocanvas.ITEM_INVISIBLE
+
+ if (self.board_paused):
+ return
+
+ if (not self.board_paused):
+ self.reset_level()
+ if self.gamewon:
self.increment_level()
+ self.gamewon = False
self.end()
self.start()
- if(self.board_paused) and (self.gamewon == 0):
- self.declare()
- self.end()
- self.start()
-
- def declare(self):
+ def reset_level(self):
self.letter_array = []
self.tile_array = []
self.alphabet_array = []
@@ -310,7 +278,8 @@ class Gcompris_braille_fun:
self.counter = 0
def increment_level(self):
- self.declare()
+ print "increment_level"
+ self.reset_level()
gcompris.sound.play_ogg("sounds/bleep.wav")
self.gcomprisBoard.sublevel += 1
if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
@@ -322,8 +291,8 @@ class Gcompris_braille_fun:
def set_level(self, level):
#This is to hide the Repeat board in case set_level button gets pressed
if self.mapActive == True:
- self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
- self.declare()
+ self.root.props.visibility = goocanvas.ITEM_INVISIBLE
+ self.reset_level()
gcompris.sound.play_ogg("sounds/receive.wav")
self.gcomprisBoard.level = level
self.gcomprisBoard.sublevel = 1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]