Author: simplet
Date: 2008-12-13 16:42:10 +0100 (Sat, 13 Dec 2008)
New Revision: 3084

Added:
   software_suite_v2/software/scripts/loto/
   software_suite_v2/software/scripts/loto/loto.py
Log:
* First version of the loto script. There is a bug in the events that are not 
triggered corrcetly (see source).


Added: software_suite_v2/software/scripts/loto/loto.py
===================================================================
--- software_suite_v2/software/scripts/loto/loto.py                             
(rev 0)
+++ software_suite_v2/software/scripts/loto/loto.py     2008-12-13 15:42:10 UTC 
(rev 3084)
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+# -*- coding: latin1 -*-
+
+"""
+======================================================================
+
+  Loto Game  :)    (with loto sheet generator inside)
+
+  Simplet <simplet _at_ ptigeek _dot_ net>
+
+
+  Use this script to generate loto sheet, and let the tux be the
+  host of a loto game !
+  
+  
+  ############
+  gros bug
+  
+  - (impossible d'appeller une fonction dans un callback oO ??)
+  exemple: si j'appuie sur la tete, ca execute "ResetGame" mais
+  il s'arr�te � la prononcitation de la phrase et n'appelle pas "ReadNumber"...
+  
+======================================================================
+"""
+
+__author__  = 'Simplet <simplet _at_ ptigeek _dot_ net>'
+__appname__ = 'Loto script'
+__version__ = '0.0.1'
+__date__    = '2008/12/09'
+__license__ = 'GPL'
+
+
+import sys, random, time, threading
+from tuxisalive.api import *
+
+
+def ReadNumber(*args):
+    global THEnumber
+    my_text = "Le num�ro [" + THEnumber + "]."
+    t = threading.Thread(target = tux_speak, args = [my_text,])
+    t.start()
+
+def NewNumber(*args):
+    global THEnumber
+    THEnumber = random.randint(1, 50)
+    my_text = "Hop Hop ! Un nouveau num�ro. Le [" + THEnumber + "]."
+    t = threading.Thread(target = tux_speak, args = [my_text,])
+    t.start()
+
+def ResetGame(*args):
+    my_text = "Remise � z�ro de la partie."
+    t = threading.Thread(target = tux_speak, args = [my_text,])
+    t.start()
+    NewNumber()
+
+def Quitter(*args):
+    global iEtat
+    my_text = "Partie termin�e ! A bientot !"
+    t = threading.Thread(target = tux_speak, args = [my_text,])
+    t.start()
+    iEtat = 0
+    
+def tux_speak(text):
+    tux.mouth.open()
+    tux.tts.speak(text, "Julie", 100)
+    tux.mouth.close()
+
+def GenererGrilles(NbGrilles):
+   """ Generate a loto sheet """
+
+   nombres = range(1, 50)
+   
+   for i in range(NbGrilles):
+      print "Grille #" + str(i+1) + "\n"
+
+      chaine = ""
+ 
+      for L in range(3):
+         ligne = random.sample(nombres, 9)
+         
+         cpt = 4
+         while cpt > 0:
+            for j in range(9):
+               if random.randint(0, 10) == 1 and ligne[j] != 0 and cpt > 0:
+                  ligne[j] = 0
+                  cpt -= 1
+         
+         for j in range(9):
+            if ligne[j] == 0:
+               chaine += "-\t"
+            else:
+               chaine += str(ligne[j]) + "\t"
+         chaine += "\n"
+
+      print chaine + "\n"
+
+
+# Generate loto sheets ?
+if len(sys.argv) == 2:
+   GenererGrilles(sys.argv[1])
+   exit()
+
+# Start game
+tux = TuxAPI('192.168.1.5', 270)
+tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'Loto', 'NONE')
+tux.server.waitConnected(10.0)
+tux.dongle.waitConnected(10.0)
+tux.radio.waitConnected(10.0)
+if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+
+  # Register game events
+  tux.button.left.registerEventOnPressed(ReadNumber)
+  tux.button.right.registerEventOnPressed(NewNumber)
+  tux.button.head.registerEventOnPressed(ResetGame)
+  tux.button.remote.registerEventOnPressed(Quitter, K_STANDBY)
+
+  #tux_speak("Bievenue au Tux Loto !. La partie de loto peut maintenant 
commencer !. Bonne chance a tous !.")
+  
+  iEtat = 1
+  while iEtat == 1:
+     time.sleep(1)
+
+tux.access.release() 
+tux.server.disconnect()
+tux.destroy()


Property changes on: software_suite_v2/software/scripts/loto/loto.py
___________________________________________________________________
Name: svn:executable
   + *


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to