[gcompris/gcomprisbraille] Braille Lotto : Two player



commit f4a8dfb00152956c45e8a3fd179c0367556e1508
Author: Srishti Sethi <srishakatux gmail com>
Date:   Sat Jul 9 01:45:51 2011 +0530

    Braille Lotto : Two player

 src/braille_lotto-activity/braille_lotto.py        |  543 ++++++++------------
 .../resources/braille_lotto/sablier.gif            |  Bin 0 -> 25708 bytes
 .../resources/braille_lotto/sablier.txt            |    1 +
 3 files changed, 206 insertions(+), 338 deletions(-)
---
diff --git a/src/braille_lotto-activity/braille_lotto.py b/src/braille_lotto-activity/braille_lotto.py
index 7084565..dd9f9a4 100644
--- a/src/braille_lotto-activity/braille_lotto.py
+++ b/src/braille_lotto-activity/braille_lotto.py
@@ -19,41 +19,27 @@
 import gtk
 import gtk.gdk
 import gcompris
+import gobject
 import gcompris.utils
 import gcompris.skin
 import gcompris.bonus
 import gcompris.timer
+import gcompris.anim
 import goocanvas
 import random
 import pango
+
 from BrailleChar import *
 from braille_alphabets import *
 from gcompris import gcompris_gettext as _
 
-#CONSTANTS for generating TICKET A
-TICKET_A_a = random.randint(1,25)
-TICKET_A_b = random.randint(1,25)
-TICKET_A_c = random.randint(26,50)
-TICKET_A_d = random.randint(51,75)
-TICKET_A_e = random.randint(51,75)
-TICKET_A_f = random.randint(76,100)
-
-#CONSTANTS for generating TICKET B
-TICKET_B_a = random.randint(1,25)
-TICKET_B_b = random.randint(1,25)
-TICKET_B_c = random.randint(26,50)
-TICKET_B_d = random.randint(51,75)
-TICKET_B_e = random.randint(51,75)
-TICKET_B_f = random.randint(76,100)
-
-PLAYER_ONE = ['P','L','A','Y','E','R',1]
-PLAYER_TWO = ['P','L','A','Y','E','R',2]
-
 COLOR_ON = 0X00FFFFL
 COLOR_OFF = 0X00000000L
 CIRCLE_FILL = "light green"
 CELL_WIDTH = 30
 
+CHECK_RANDOM = []
+
 class Gcompris_braille_lotto:
   """Empty gcompris python class"""
 
@@ -67,6 +53,11 @@ class Gcompris_braille_lotto:
     # Needed to get key_press
     gcomprisBoard.disable_im_context = True
 
+    for index in range(1, 91):
+        CHECK_RANDOM.append(index)
+
+    random.shuffle(CHECK_RANDOM)
+
   def start(self):
     print "braille_lotto start"
 
@@ -81,6 +72,14 @@ class Gcompris_braille_lotto:
     #Boolean variable declaration
     self.mapActive = False
     self.board_paused = 0
+    self.timerAnim = 0
+    self.counter = 0
+    self.gamewon = 0
+    self.countAnim = 200
+    self.score_player_a = 0
+    self.score_player_b = 0
+    self.status_timer = 50
+
 
     #REPEAT ICON
     gcompris.bar_set(gcompris.BAR_REPEAT_ICON)
@@ -89,7 +88,7 @@ class Gcompris_braille_lotto:
     # Create our rootitem. We put each canvas item in it so at the end we
     # only have to kill it. The canvas deletes all the items it contains
     # automaticaly.
-    self.rootitem = goocanvas.Group(parent =
+    self.root = goocanvas.Group(parent =
                                     self.gcomprisBoard.canvas.get_root_item())
 
     self.lotto_board()
@@ -97,7 +96,7 @@ class Gcompris_braille_lotto:
   def lotto_board(self):
     #Lotto Board
     board = goocanvas.Rect(
-      parent = self.rootitem,
+      parent = self.root,
       x = 40,
       y = 20,
       width = 420,
@@ -109,203 +108,69 @@ class Gcompris_braille_lotto:
     #Horizontal polylines for lotto board
     for index in range(8):
         p_points = goocanvas.Points([(40.0, 30 * index + 50),(460.0, 30 * index + 50)])
-        polyline = goocanvas.Polyline(parent = self.rootitem, points=p_points, stroke_color="blue")
+        polyline = goocanvas.Polyline(parent = self.root, points=p_points, stroke_color="blue")
 
     #Vertical polylines for lotto board
     for index in range(9):
         p_points = goocanvas.Points([(42 * index + 80, 20.0),(42 * index + 80, 290.0)])
-        polyline = goocanvas.Polyline(parent = self.rootitem, points=p_points, stroke_color="blue")
-
-
-    #Displaying ticket for player one
-    ticket_one = goocanvas.Rect(
-      parent = self.rootitem,
-      x = 40,
-      y = 310,
-      width = 280,
-      height = 180,
-      stroke_color = "dark green",
-      fill_color = "light green" ,
-      line_width=10)
-
-    self.rectangle_one = []
-    self.rectangle_one_x = []
-    self.rectangle_one_y = []
-    for i in range(4):
-        for j in range(3):
-              rect = goocanvas.Rect(
-                             parent = self.rootitem,
-                             x = 45 + 68 * i,
-                             y = 315 + 57 * j,
-                             width = 65,
-                             height = 54,
-                             stroke_color = "dark green",
-                             fill_color = "light green" ,
-                             line_width=2)
-              self.rectangle_one.append(rect)
-              self.rectangle_one_x.append(45 + 68 * i)
-              self.rectangle_one_y.append(315 + 57 * j)
-    for index in range(12):
-        gcompris.utils.item_focus_init(self.rectangle_one[index],None)
-        self.rectangle_one[index].connect("button_press_event",self.test, index)
-
-
-    #Displaying ticket for player two
-    ticket_two = goocanvas.Rect(
-      parent = self.rootitem,
-      x = 500,
-      y = 310,
-      width = 280,
-      height = 180,
-      stroke_color = "dark green",
-      fill_color = "light green" ,
-      line_width=10)
-
-    self.rectangle_two = []
-    self.rectangle_two_x = []
-    self.rectangle_two_y = []
-    for i in range(4):
-        for j in range(3):
-              rect = goocanvas.Rect(
-                             parent = self.rootitem,
-                             x = 505 + 68 * i,
-                             y = 315 + 57 * j,
-                             width = 65,
-                             height = 54,
-                             stroke_color = "dark green",
-                             fill_color = "light green" ,
-                             line_width=2)
-              self.rectangle_two.append(rect)
-              self.rectangle_two_x.append(505 + 68 * i)
-              self.rectangle_two_y.append(315 + 57 * j)
-    for index in range(12):
-        gcompris.utils.item_focus_init(self.rectangle_two[index],None)
-        self.rectangle_two[index].connect("button_press_event",self.test)
+        polyline = goocanvas.Polyline(parent = self.root, points=p_points, stroke_color="blue")
+
+    #Display Rectangle Ticket Boxes
+    self.rect = []
+    self.rect_x = []
+    self.rect_y = []
+    self.displayTicketBox(40 , 310)
+    self.displayTicketBox(500, 310)
+
+    #Rectangle box with ticket number is made clickable
+    index = 0
+    even = 0
+    while (index < 12):
+        if(even % 2 == 0):
+            gcompris.utils.item_focus_init(self.rect[even],None)
+            self.rect[even].connect("button_press_event",self.cross_number, index)
+        even += 2
+        index += 1
 
     #Displaying player_one and player_two
-
-    for index in range(7):
-        #PLAYER 1
-        goocanvas.Text(
-                parent = self.rootitem,
-                x=340.0,
-                y=330 + 20 * index,
-                text=str(PLAYER_ONE[index]),
+    #PLAYER 1
+    goocanvas.Text(
+                parent = self.root,
+                x=170.0,
+                y=500.0,
+                text=_("PLAYER 1"),
                 fill_color="black",
                 anchor = gtk.ANCHOR_CENTER,
                 alignment = pango.ALIGN_CENTER,
                 )
-        #PLAYER TWO
-        goocanvas.Text(
-                parent = self.rootitem,
-                x=480.0,
-                y=330 + 20 * index,
-                text=str(PLAYER_TWO[index]),
+    #PLAYER TWO
+    goocanvas.Text(
+                parent = self.root,
+                x=640.0,
+                y=500.0,
+                text=_("PLAYER 2"),
                 fill_color="black",
                 anchor = gtk.ANCHOR_CENTER,
                 alignment = pango.ALIGN_CENTER,
                 )
-    # The Lotto Room Area
-    # ---------------
-    self.lotto_room_sw = gtk.ScrolledWindow()
-    self.lotto_room_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
-    self.lotto_room_sw.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
-
-    w = 100.0
-    h = gcompris.BOARD_HEIGHT - 380.0
-    y = 20.0 # The upper limit of the text boxes
-    x = gcompris.BOARD_WIDTH - w - 20.0
-
-    self.lotto_room_tb = gtk.TextBuffer()
-    self.lotto_room_tv = gtk.TextView(self.lotto_room_tb)
-    self.lotto_room_tv.set_editable(False)
-    self.lotto_room_sw.add(self.lotto_room_tv)
-    # save name and selected color in a map
-    self.lotto_room_map = {}
-
-    self.lotto_room_tb.set_text("")
-
-    self.lotto_room_tv.set_wrap_mode(gtk.WRAP_CHAR)
-
-    goocanvas.Widget(
-      parent = self.rootitem,
-      widget=self.lotto_room_sw,
-      x=x,
-      y=y,
-      width=w,
-      height= h,
-      anchor=gtk.ANCHOR_NW)
-    self.lotto_room_tv.show()
-    self.lotto_room_sw.show()
-
-    # A label for the room area
-    goocanvas.Text(
-      parent = self.rootitem,
-      text=_("Lotto Room"),
-      font = gcompris.skin.get_font("gcompris/board/medium"),
-      x=x+(w/2),
-      y=y+h+15,
-      anchor=gtk.ANCHOR_CENTER,
-      )
-
-    # The channel area
-    # ---------------
-    self.channel = gtk.Entry()
-
-    goocanvas.Widget(
-      parent = self.rootitem,
-      widget=self.channel,
-      x=500,
-      y=60,
-      width=160,
-      height= 10,
-      anchor=gtk.ANCHOR_NW)
-
-    self.channel.show()
-    self.channel.set_text("Type your channel name in order to start playing")
-
-
-    # A label for the channel area
-    goocanvas.Text(
-      parent = self.rootitem,
-      text=_("Your Channel"),
-      font = gcompris.skin.get_font("gcompris/board/medium"),
-      x=560,
-      y=30,
-      anchor=gtk.ANCHOR_CENTER,
-      )
 
     #Button to display the number to be checked in the ticket
-    goocanvas.Image(parent = self.rootitem,
+    goocanvas.Image(parent = self.root,
                     pixbuf = gcompris.utils.load_pixmap("braille_lotto/button.jpg"),
                     x = 530,
-                    y = 200,
+                    y = 35,
                     )
 
     #Check number
     goocanvas.Text(
-      parent = self.rootitem,
-      text=_("Check Number"),
+      parent = self.root,
+      text= _("Check Number"),
       font = gcompris.skin.get_font("gcompris/board/medium"),
       x=630,
-      y=220,
+      y=55,
       anchor=gtk.ANCHOR_CENTER,
       )
 
-    goocanvas.Text(
-      parent = self.rootitem,
-      text= "23",
-      x=635,
-      y=250,
-      font = "SANS 20",
-      anchor=gtk.ANCHOR_CENTER,
-      )
-
-    #Setting Timer
-    gcompris.timer.display(560,100,gcompris.timer.CLOCK,10,self.say)
-    gcompris.timer.pause(9)
-    gcompris.timer.add(10)
-
     #Displaying Numbers in Lotto Board
     k = 0
     i = 0
@@ -317,7 +182,7 @@ class Gcompris_braille_lotto:
         spacing = 0
         for index in range(i,j):
             goocanvas.Text(
-                    parent = self.rootitem,
+                    parent = self.root,
                     text = (index + 1),
                     font = gcompris.skin.get_font("gcompris/board/medium"),
                     x = spacing * 43 + 55,
@@ -333,160 +198,176 @@ class Gcompris_braille_lotto:
         j += 10
         k += 1
 
-    #Place the checked button on number which is being called
-    number = 23
-    if number == 23:
-        goocanvas.Image(parent = self.rootitem,
+    #Adding a timer
+    self.displayTimer()
+
+    #Calling the random number and checking it on lotto board
+    self.number_call()
+
+    #An array to store the ticket numbers
+    self.ticket_array = []
+
+    #Displaying the Braille Code for TICKETS A & B
+    #TICKET A
+    self.displayTicket(1, 25, 55, 320)
+    self.displayTicket(1, 25, 55, 432)
+    self.displayTicket(26, 50, 122, 377)
+    self.displayTicket(51, 75, 191, 320)
+    self.displayTicket(51, 75, 191, 432)
+    self.displayTicket(76, 90, 259, 377)
+
+    #TICKET B
+    self.displayTicket(1, 25, 515, 320)
+    self.displayTicket(1, 25, 515, 432)
+    self.displayTicket(26, 50, 582, 377)
+    self.displayTicket(51, 75, 650, 320)
+    self.displayTicket(51, 75, 650, 432)
+    self.displayTicket(76, 90, 718, 377)
+
+
+  def animTimer(self):
+        self.countAnim -= 1
+        if self.countAnim > 0:
+            self.timerAnim = gobject.timeout_add(200, self.animTimer)
+        else:
+            self.check_number.set_property("text","")
+            self.countAnim = 200
+            self.counter += 1
+            self.number_call()
+
+
+  def displayTimer(self):
+      self.timericon = gcompris.anim.CanvasItem( gcompris.anim.Animation("braille_lotto/sablier.txt"),
+            self.root)
+      self.timericon.goocanvas.translate(580, 150)
+      self.timerAnim = gobject.timeout_add(200, self.animTimer)
+      self.timericon.goocanvas.props.visibility = goocanvas.ITEM_VISIBLE
+
+  def number_call(self):
+      if(self.counter == 90):
+          gcompris.utils.dialog(_("Game Over"),None)
+          self.pause(1)
+      self.timerAnim = gobject.timeout_add(200, self.animTimer)
+      self.check_number = goocanvas.Text(
+                            parent = self.root,
+                            text= CHECK_RANDOM[self.counter],
+                            x=630,
+                            y=100,
+                            font = "SANS 20",
+                            anchor=gtk.ANCHOR_CENTER,
+                            )
+      #Place the checked button on number which is being called
+      goocanvas.Image(parent = self.root,
                     pixbuf = gcompris.utils.load_pixmap("braille_lotto/button_checked.png"),
-                    x = self.board_array_x[number- 1] - 10 ,
-                    y = self.board_array_y[number- 1]- 10,
+                    x = self.board_array_x[CHECK_RANDOM[self.counter] - 1] - 10 ,
+                    y = self.board_array_y[CHECK_RANDOM[self.counter] - 1]- 10,
                     )
 
-    #Displaying the Braille Code for randomly generated numbers for TICKET_A
-    #TICKET_A_a
-    #TICKET_A_b
-    if (TICKET_A_a < 10) :
-        BrailleChar(self.rootitem, 55, 320, 35 , TICKET_A_a, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    if(TICKET_A_b < 10):
-        BrailleChar(self.rootitem, 55, 432, 35 , TICKET_A_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    if(TICKET_A_a >= 10):
-        tens_digit_a = TICKET_A_a / 10
-        ones_digit_a = TICKET_A_a % 10
-        BrailleChar(self.rootitem, 47, 320, 33 , tens_digit_a, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-        BrailleChar(self.rootitem, 74, 320, 33 , ones_digit_a, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
 
-    if(TICKET_A_b >= 10):
-        tens_digit_b = TICKET_A_b / 10
-        ones_digit_b = TICKET_A_b % 10
-        BrailleChar(self.rootitem, 47, 432, 33 , tens_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-        BrailleChar(self.rootitem, 72, 432, 33 , ones_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_A_c
-    tens_digit_b = TICKET_A_c / 10
-    ones_digit_b = TICKET_A_c % 10
-    BrailleChar(self.rootitem, 115, 377, 33 , tens_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 142, 377, 33 , ones_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_A_d
-    tens_digit_d = TICKET_A_d / 10
-    ones_digit_d = TICKET_A_d % 10
-    BrailleChar(self.rootitem, 184, 320, 33 , tens_digit_d, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 211, 320, 33 , ones_digit_d, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_A_e
-    tens_digit_e = TICKET_A_e / 10
-    ones_digit_e = TICKET_A_e % 10
-    BrailleChar(self.rootitem, 184, 432, 33 , tens_digit_e, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 211, 432, 33 , ones_digit_e, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_A_f
-    tens_digit_f = TICKET_A_f / 10
-    ones_digit_f = TICKET_A_f % 10
-    BrailleChar(self.rootitem, 252, 377, 33 , tens_digit_f, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 279, 377, 33 , ones_digit_f, COLOR_ON, COLOR_OFF ,
-                    CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #Displaying the Braille Code for randomly generated numbers for TICKET_B
-    #TICKET_B_a
-    #TICKET_B_b
-    if (TICKET_B_a < 10) :
-        BrailleChar(self.rootitem, 515, 320, 35 , TICKET_B_a, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    if(TICKET_B_b < 10):
-        BrailleChar(self.rootitem, 515, 432, 35 , TICKET_B_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    if(TICKET_B_a >= 10):
-        tens_digit_a = TICKET_B_a / 10
-        ones_digit_a = TICKET_B_a % 10
-        BrailleChar(self.rootitem, 508, 320, 33 , tens_digit_a, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-        BrailleChar(self.rootitem, 535, 320, 33 , ones_digit_a, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    if(TICKET_B_b >= 10):
-        tens_digit_b = TICKET_B_b / 10
-        ones_digit_b = TICKET_B_b % 10
-        BrailleChar(self.rootitem, 508, 432, 33 , tens_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-        BrailleChar(self.rootitem, 535, 432, 33 , ones_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_B_c
-    tens_digit_b = TICKET_B_c / 10
-    ones_digit_b = TICKET_B_c % 10
-    BrailleChar(self.rootitem, 575, 377, 33 , tens_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 602, 377, 33 , ones_digit_b, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_B_d
-    tens_digit_d = TICKET_B_d / 10
-    ones_digit_d = TICKET_B_d % 10
-    BrailleChar(self.rootitem, 643, 320, 33 , tens_digit_d, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 670, 320, 33 , ones_digit_d, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
+  def displayTicketBox(self, x, y):
+      goocanvas.Rect(
+      parent = self.root,
+      x = x + 5,
+      y = y + 5,
+      width = 268,
+      height = 168,
+      stroke_color = "dark green",
+      fill_color = "light green" ,
+      line_width=7)
 
-    #TICKET_B_e
-    tens_digit_e = TICKET_B_e / 10
-    ones_digit_e = TICKET_B_e % 10
-    BrailleChar(self.rootitem, 643, 432, 33 , tens_digit_e, COLOR_ON, COLOR_OFF ,
-                  CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 670, 432, 33 , ones_digit_e, COLOR_ON, COLOR_OFF ,
+      for i in range(4):
+        for j in range(3):
+              box = goocanvas.Rect(
+                             parent = self.root,
+                             x = x + 5 + 68 * i,
+                             y = y + 5 + 57 * j,
+                             width = 65,
+                             height = 54,
+                             stroke_color = "dark green",
+                             fill_color = "light green" ,
+                             line_width=2)
+              self.rect.append(box)
+              self.rect_x.append(x + 5 + 68 * i)
+              self.rect_y.append(y + 5 + 57 * j)
+
+  def displayTicket(self, a, b, x, y):
+      ticket = random.randint(a, b)
+      self.ticket_array.append(ticket)
+      if (ticket < 10):
+          BrailleChar(self.root, x, y, 35 , ticket, COLOR_ON, COLOR_OFF ,
                   CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-
-    #TICKET_B_f
-    tens_digit_f = TICKET_B_f / 10
-    ones_digit_f = TICKET_B_f % 10
-    BrailleChar(self.rootitem, 711, 377, 33 , tens_digit_f, COLOR_ON, COLOR_OFF ,
+      else :
+          tens_digit = ticket / 10
+          ones_digit = ticket % 10
+          BrailleChar(self.root, x - 7, y, 33 ,tens_digit, COLOR_ON, COLOR_OFF ,
                   CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
-    BrailleChar(self.rootitem, 738, 377, 33 , ones_digit_f, COLOR_ON, COLOR_OFF ,
+          BrailleChar(self.root, x + 20, y, 33 , ones_digit, COLOR_ON, COLOR_OFF ,
                   CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
 
-
-
-  def say(self):
-      print "hello"
-
-  def test(self,item, event, target, index):
+  def cross_number(self,item, event, target, index):
     #Cross Sign
-    goocanvas.Image(parent = self.rootitem,
+    goocanvas.Image(parent = self.root,
                     pixbuf = gcompris.utils.load_pixmap("braille_lotto/cross_button.png"),
-                    x = self.rectangle_one_x[index]+8 ,
-                    y = self.rectangle_one_y[index]+5,
+                    x = self.rect_x[index * 2]+8 ,
+                    y = self.rect_y[index * 2]+5,
                     )
 
+    if( CHECK_RANDOM[self.counter] == self.ticket_array[index]):
+        if(index in (0, 1, 2, 3, 4, 5)):
+            self.score_player_a +=1
+        else:
+            self.score_player_b +=1
+
+    if(self.score_player_a == 6 or self.score_player_b == 6):
+        if(self.score_player_a == 6):
+            text = "PLAYER 1 \n" "You WON"
+            color = "blue"
+        elif(self.score_player_b == 6):
+            text = "PLAYER 2 \n" "You WON"
+            color = "dark green"
+        status = goocanvas.Text(
+                    parent = self.root,
+                    text= text,
+                    x=410,
+                    y=370,
+                    font = "SANS 20",
+                    fill_color = color,
+                    anchor=gtk.ANCHOR_CENTER,
+                   )
+        self.timer_inc  = gobject.timeout_add(self.status_timer,
+                                            self.timer_loop)
+  def timer_loop(self):
+      self.status_timer -= 1
+      if(self.status_timer == 0):
+          self.gamewon = 1
+          gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)
+      self.timer_inc  = gobject.timeout_add(self.status_timer,
+                                            self.timer_loop)
+
   def end(self):
     print "braille_lotto end"
-    # Remove the root item removes all the others inside it
-    self.rootitem.remove()
+    if self.timer_inc:
+      gobject.source_remove(self.timer_inc)
+    if self.timerAnim:
+      gobject.source_remove(self.timerAnim)
+    del self.timerAnim
+    del self.timer_inc
 
+    # Remove the root item removes all the others inside it
+    self.root.remove()
+    gcompris.end_board()
 
   def ok(self):
     print("braille_lotto ok.")
 
-
   def repeat(self):
       if(self.mapActive):
-          self.end()
-          self.start()
+          self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
+          self.root.props.visibility = goocanvas.ITEM_VISIBLE
           self.mapActive = False
           self.pause(0)
       else :
-          self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
+          self.root.props.visibility = goocanvas.ITEM_INVISIBLE
           self.rootitem = goocanvas.Group(parent=
                                    self.gcomprisBoard.canvas.get_root_item())
           gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
@@ -495,32 +376,18 @@ class Gcompris_braille_lotto:
           self.mapActive = True
           self.pause(1)
 
-
   def config(self):
     print("braille_lotto config.")
 
-
   def key_press(self, keyval, commit_str, preedit_str):
     utf8char = gtk.gdk.keyval_to_unicode(keyval)
     strn = u'%c' % utf8char
 
-    print("Gcompris_braille_lotto key press keyval=%i %s" % (keyval, strn))
-
   def pause(self, pause):
       self.board_paused = pause
-      # There is a problem with GTK widgets, they are not covered by the help
-      # We hide/show them here
-      if(self.board_paused):
-          self.channel.hide()
-          self.lotto_room_tv.hide()
-          self.lotto_room_sw.hide()
-          gcompris.timer.end()
-      else :
-          self.channel.show()
-          self.lotto_room_tv.show()
-          self.lotto_room_sw.show()
-          gcompris.timer.pause(9)
-
+      if(self.board_paused == 1 and (self.counter == 90 or self.gamewon == 1)):
+          self.end()
+          self.start()
 
   def set_level(self, level):
     print("braille_lotto set level. %i" % level)
\ No newline at end of file
diff --git a/src/braille_lotto-activity/resources/braille_lotto/sablier.gif b/src/braille_lotto-activity/resources/braille_lotto/sablier.gif
new file mode 100644
index 0000000..61fe7ca
Binary files /dev/null and b/src/braille_lotto-activity/resources/braille_lotto/sablier.gif differ
diff --git a/src/braille_lotto-activity/resources/braille_lotto/sablier.txt b/src/braille_lotto-activity/resources/braille_lotto/sablier.txt
new file mode 100644
index 0000000..f864df6
--- /dev/null
+++ b/src/braille_lotto-activity/resources/braille_lotto/sablier.txt
@@ -0,0 +1 @@
+braille_lotto/sablier.gif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]