Commit 0fa9a691 authored by Bruno Coudoin's avatar Bruno Coudoin

braille lotto: fixed a bunch of timer issues, reviewed the code to make it simpler.

parent c08ed162
...@@ -56,7 +56,6 @@ class Gcompris_braille_lotto: ...@@ -56,7 +56,6 @@ class Gcompris_braille_lotto:
#Boolean variable declaration #Boolean variable declaration
self.mapActive = False self.mapActive = False
self.ticketCheck = True
#CONSTANT Declarations #CONSTANT Declarations
self.board_paused = 0 self.board_paused = 0
...@@ -65,9 +64,6 @@ class Gcompris_braille_lotto: ...@@ -65,9 +64,6 @@ class Gcompris_braille_lotto:
self.gamewon = 0 self.gamewon = 0
self.score_player_a = 0 self.score_player_a = 0
self.score_player_b = 0 self.score_player_b = 0
self.status_timer = 70
self.delay_one = 100
self.delay_two = 100
self.tile_counter = 0 self.tile_counter = 0
self.rectangle_counter = 0 self.rectangle_counter = 0
...@@ -99,7 +95,8 @@ class Gcompris_braille_lotto: ...@@ -99,7 +95,8 @@ class Gcompris_braille_lotto:
while (index < 12): while (index < 12):
if(even % 2 == 0): if(even % 2 == 0):
gcompris.utils.item_focus_init(self.rect[even],None) gcompris.utils.item_focus_init(self.rect[even],None)
self.rect[even].connect("button_press_event",self.cross_number, index) self.rect[even].connect("button_press_event",
self.cross_number, index)
even += 2 even += 2
index += 1 index += 1
...@@ -287,7 +284,7 @@ class Gcompris_braille_lotto: ...@@ -287,7 +284,7 @@ class Gcompris_braille_lotto:
_("Hey, you have it. Its there in your {column} column").format(column = self.column) _("Hey, you have it. Its there in your {column} column").format(column = self.column)
else : else :
self.status_one.props.text = _("Oops,number isn't there in your ticket!") self.status_one.props.text = _("Oops,number isn't there in your ticket!")
self.timerAnim = gobject.timeout_add(200, self.hideCalloutLeft) self.timerAnim = gobject.timeout_add(1500, self.hideCalloutLeft)
def clue_right(self, event , target, item): def clue_right(self, event , target, item):
self.callout2 = goocanvas.Image(parent = self.root, self.callout2 = goocanvas.Image(parent = self.root,
...@@ -311,28 +308,16 @@ class Gcompris_braille_lotto: ...@@ -311,28 +308,16 @@ class Gcompris_braille_lotto:
_("Hey, you have it. Its there in your {column} column").format(column = self.column) _("Hey, you have it. Its there in your {column} column").format(column = self.column)
else : else :
self.status_two.props.text = _("Oops, number isn't there in your ticket!") self.status_two.props.text = _("Oops, number isn't there in your ticket!")
self.timerAnim = gobject.timeout_add(100, self.hideCalloutRight) self.timerAnim = gobject.timeout_add(1500, self.hideCalloutRight)
def hideCalloutLeft(self): def hideCalloutLeft(self):
self.delay_one -= 1 self.callout1.props.visibility = goocanvas.ITEM_INVISIBLE
if(self.delay_one == 0): self.status_one.props.text = ""
self.callout1.props.visibility = goocanvas.ITEM_INVISIBLE
self.status_one.props.text = ""
self.delay_one = 100
if self.delay_one < 100 :
self.timer_inc = gobject.timeout_add(self.delay_one,
self.hideCalloutLeft)
def hideCalloutRight(self): def hideCalloutRight(self):
self.delay_two -= 1 self.callout2.props.visibility = goocanvas.ITEM_INVISIBLE
if(self.delay_two == 0): self.status_two.props.text = ""
self.callout2.props.visibility = goocanvas.ITEM_INVISIBLE
self.status_two.props.text = ""
self.delay_two = 100
if self.delay_two < 100 :
self.timer_inc = gobject.timeout_add(self.delay_two,
self.hideCalloutRight)
def findColumn(self): def findColumn(self):
if self.check_random[self.counter] <= 25: if self.check_random[self.counter] <= 25:
...@@ -354,14 +339,12 @@ class Gcompris_braille_lotto: ...@@ -354,14 +339,12 @@ class Gcompris_braille_lotto:
def number_call(self): def number_call(self):
if(self.counter == 11): if(self.counter == 11):
self.displayGameStatus() self.displayGameStatus( _("Game Over") )
self.game_status.props.text = _(" Game Over") self.timer_inc = gobject.timeout_add(1000, self.game_over)
self.timer_inc = gobject.timeout_add(self.status_timer,
self.game_over)
elif (self.counter < 11): elif (self.counter < 11):
self.check_number = \ self.check_number = \
goocanvas.Text(parent = self.root, goocanvas.Text(parent = self.root,
text= self.check_random[self.counter], text = self.check_random[self.counter],
x=110, x=110,
y=420, y=420,
font = gcompris.skin.get_font("gcompris/board/title bold"), font = gcompris.skin.get_font("gcompris/board/title bold"),
...@@ -369,13 +352,7 @@ class Gcompris_braille_lotto: ...@@ -369,13 +352,7 @@ class Gcompris_braille_lotto:
) )
def game_over(self): def game_over(self):
self.status_timer -= 1
if self.status_timer == 0 :
self.pause(1) self.pause(1)
self.status_timer = 70
if self.status_timer < 70 :
self.timer_inc = gobject.timeout_add(self.status_timer,
self.game_over)
def displayTicketBox(self, x, y): def displayTicketBox(self, x, y):
goocanvas.Rect( goocanvas.Rect(
...@@ -409,23 +386,27 @@ class Gcompris_braille_lotto: ...@@ -409,23 +386,27 @@ class Gcompris_braille_lotto:
if (ticket < 10): if (ticket < 10):
obj = BrailleChar(self.root, x, y, 50 , ticket, COLOR_ON, COLOR_OFF , obj = BrailleChar(self.root, x, y, 50 , ticket, COLOR_ON, COLOR_OFF ,
CIRCLE_FILL, CIRCLE_FILL, False, False ,False, None) CIRCLE_FILL, CIRCLE_FILL, False, False ,False, None)
obj.ticket_focus(self.rect[self.rectangle_counter],self.cross_number, self.tile_counter) obj.ticket_focus(self.rect[self.rectangle_counter],
self.cross_number, self.tile_counter)
else : else :
tens_digit = ticket / 10 tens_digit = ticket / 10
ones_digit = ticket % 10 ones_digit = ticket % 10
obj1 = BrailleChar(self.root, x - 7, y, 50 ,tens_digit, COLOR_ON, COLOR_OFF , obj1 = BrailleChar(self.root, x - 7, y, 50 ,tens_digit, COLOR_ON, COLOR_OFF ,
CIRCLE_FILL, CIRCLE_FILL, False, False ,False, None) CIRCLE_FILL, CIRCLE_FILL, False, False ,False, None)
obj1.ticket_focus(self.rect[self.rectangle_counter], self.cross_number, self.tile_counter) obj1.ticket_focus(self.rect[self.rectangle_counter],
self.cross_number, self.tile_counter)
obj2 = BrailleChar(self.root, x + 25, y, 50 , ones_digit, COLOR_ON, COLOR_OFF , obj2 = BrailleChar(self.root, x + 25, y, 50 , ones_digit, COLOR_ON, COLOR_OFF ,
CIRCLE_FILL, CIRCLE_FILL, False, False ,False, None) CIRCLE_FILL, CIRCLE_FILL, False, False ,False, None)
obj2.ticket_focus(self.rect[self.rectangle_counter], self.cross_number, self.tile_counter) obj2.ticket_focus(self.rect[self.rectangle_counter],
self.cross_number, self.tile_counter)
self.rectangle_counter += 2 self.rectangle_counter += 2
self.tile_counter += 1 self.tile_counter += 1
def cross_number(self,item, event, target, index): def cross_number(self, item, event, target, index):
if( self.check_random[self.counter] == self.ticket_array[index]): if( self.check_random[self.counter] == self.ticket_array[index]):
# This is a win
if(index in (0, 1, 2, 3, 4, 5)): if(index in (0, 1, 2, 3, 4, 5)):
self.score_player_a +=1 self.score_player_a +=1
else: else:
...@@ -438,35 +419,28 @@ class Gcompris_braille_lotto: ...@@ -438,35 +419,28 @@ class Gcompris_braille_lotto:
y = self.rect_y[index * 2] + 5, y = self.rect_y[index * 2] + 5,
) )
else : else :
#This is to uncheck the cross button # This is a loss, indicate it with a cross mark
if (self.ticketCheck): item = \
#Cross Sign goocanvas.Image(parent = self.root,
self.cross_sign = goocanvas.Image(parent = self.root, pixbuf = gcompris.utils.load_pixmap("braille_lotto/cross_button.png"),
pixbuf = gcompris.utils.load_pixmap("braille_lotto/cross_button.png"), x = self.rect_x[index * 2] + 8,
x = self.rect_x[index * 2] + 8, y = self.rect_y[index * 2] + 5,
y = self.rect_y[index * 2] + 5, )
) gobject.timeout_add( 1000, lambda: item.remove() )
self.ticketCheck = False
gcompris.utils.item_focus_init(self.cross_sign , self.rect[index * 2]) winner = 0
self.cross_sign.connect("button_press_event", self.cross_number, index) if(self.score_player_a == 6):
else : winner = 1
self.cross_sign.props.visibility = goocanvas.ITEM_INVISIBLE elif(self.score_player_b == 6):
self.ticketCheck = True winner = 2
if winner:
if(self.score_player_a == 6 or self.score_player_b == 6): self.displayGameStatus( \
self.displayGameStatus() _("Congratulation player {player_id}, you won").format(player_id = str(winner) ) )
if(self.score_player_a == 6): self.timer_inc = gobject.timeout_add(1500, self.timer_loop)
self.game_status.props.text = _("PLAYER 1\n" "You WON")
elif(self.score_player_b == 6):
self.game_status.props.text = _("PLAYER 2 \n" "You WON") def displayGameStatus(self, message):
self.timer_inc = gobject.timeout_add(self.status_timer,
self.timer_loop)
#print self.score_player_a
#print self.score_player_b
def displayGameStatus(self):
self.game = goocanvas.Image(parent = self.root, self.game = goocanvas.Image(parent = self.root,
pixbuf = gcompris.utils.load_pixmap("braille_lotto/game.svg"), pixbuf = gcompris.utils.load_pixmap("braille_lotto/game.svg"),
x = 200 , x = 200 ,
...@@ -474,25 +448,22 @@ class Gcompris_braille_lotto: ...@@ -474,25 +448,22 @@ class Gcompris_braille_lotto:
) )
self.game_status = goocanvas.Text( self.game_status = goocanvas.Text(
parent = self.root, parent = self.root,
text= "", text = message,
x=365, x = 365,
y=200, y = 200,
font = "SANS 30", width = 100,
fill_color = "blue", font = gcompris.skin.get_font("gcompris/board/title bold"),
anchor=gtk.ANCHOR_CENTER, fill_color = "black",
) anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
)
def timer_loop(self): def timer_loop(self):
self.status_timer -= 1 # Hide the game status
if(self.status_timer == 0): self.game.props.visibility = goocanvas.ITEM_INVISIBLE
self.game.props.visibility = goocanvas.ITEM_INVISIBLE self.game_status.props.visibility = goocanvas.ITEM_INVISIBLE
self.game_status.props.visibility = goocanvas.ITEM_INVISIBLE self.gamewon = 1
self.status_timer = 70 gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)
self.gamewon = 1
gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)
if (self.status_timer < 70):
self.timer_inc = gobject.timeout_add(self.status_timer,
self.timer_loop)
def end(self): def end(self):
# Remove the root item removes all the others inside it # Remove the root item removes all the others inside it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment