Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
algorithm.Gcompris_algorithm Class Reference

List of all members.

Public Member Functions

def paint_image
def __init__
def start
def end
def ok
def pause
def cleanup
def display_current_level
def paint_qm
def key_press
def set_level
def increment_level
def apple_click

Public Attributes

 gcomprisBoard
 anzahl
 algos
 rootitem
 distance
 leftx
 board_paused
 gamewon
 symbollist
 pixlist
 algo
 random_index
 selector
 place
 qm

Detailed Description

The algorithm activity

Definition at line 40 of file algorithm.py.


Constructor & Destructor Documentation

def algorithm.Gcompris_algorithm.__init__ (   self,
  gcomprisBoard 
)

Definition at line 53 of file algorithm.py.

00053 
00054   def __init__(self, gcomprisBoard):
00055     self.gcomprisBoard = gcomprisBoard
00056     self.anzahl = 8
00057     print("Gcompris_algorithm __init__.")
00058     self.algos = [algo, algo1, algo2, algo3]
00059     self.rootitem = None
00060     self.distance = 80
00061     self.leftx = 90
00062 
00063     # These are used to let us restart only after the bonus is displayed.
00064     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00065     self.board_paused  = 0;
00066     self.gamewon       = 0;


Member Function Documentation

def algorithm.Gcompris_algorithm.apple_click (   self,
  widget,
  event = None,
  index = 0 
)

Definition at line 204 of file algorithm.py.

00204 
00205   def apple_click (self, widget, event=None, index=0):
00206     if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
00207      if index == self.random_index[self.algo(self.place)]:
00208       self.qm.destroy()
00209       self.paint_image(index, self.place, 147)
00210       self.place +=1
00211       if self.place == self.anzahl:
00212         gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.TUX)
00213         return
00214       self.paint_qm ()
00215 
00216 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file algorithm.py.

00113 
00114   def cleanup(self):
00115 
00116     # Remove the root item removes all the others inside it
00117     if self.rootitem != None:
00118      self.rootitem.destroy()
00119      self.rootitem = None
00120      gcompris.score.end()

Here is the caller graph for this function:

Definition at line 121 of file algorithm.py.

00121 
00122   def display_current_level(self):
00123     self.cleanup()
00124     gcompris.score.start(gcompris.score.STYLE_NOTE, 570, 305,
00125      self.gcomprisBoard.number_of_sublevel)
00126     gcompris.bar_set_level(self.gcomprisBoard)
00127     gcompris.score.set(self.gcomprisBoard.sublevel)
00128 
00129     # Create our rootitem. We put each canvas item in it so at the end we
00130     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00131     self.rootitem = self.gcomprisBoard.canvas.root().add(
00132       gnomecanvas.CanvasGroup,
00133       x=0.0,
00134       y=0.0
00135       )
00136 
00137     # Display our list of items
00138     for i in range(len(self.symbollist)):
00139      s = self.paint_image(i ,i ,390)
00140      s.connect ("event", self.apple_click, i)
00141 
00142     # Display the algorithm
00143     self.algo = random.choice(self.algos)
00144 
00145     # Create a uniq list of index in random order
00146     self.random_index = []
00147     self.selector  = range(self.anzahl)
00148     for i in range(self.anzahl):
00149       j=random.randrange(len(self.selector))
00150       self.random_index.append(self.selector[j])
00151       self.selector.pop(j)
00152 
00153     # Display what to search
00154     for i in range(len(self.symbollist)):
00155      self.paint_image(self.random_index[self.algo(i)], i, 45)
00156 
00157     # Display the uncomplete user area
00158     self.random_index = []
00159 
00160     for i in range(self.anzahl):
00161      self.random_index.append(random.randrange(len(self.symbollist)))
00162 
00163     for i in range(5):
00164      self.paint_image(self.random_index[self.algo(i)], i, 147)
00165 
00166     self.place = 5
00167     self.paint_qm ()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file algorithm.py.

00088 
00089   def end(self):
00090     self.cleanup()
00091     print("Gcompris_algorithm end.")

Here is the call graph for this function:

Definition at line 188 of file algorithm.py.

00188 
00189   def increment_level(self):
00190     self.gcomprisBoard.sublevel += 1
00191 
00192     if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
00193       # Try the next level
00194       self.gcomprisBoard.sublevel=1
00195       self.gcomprisBoard.level += 1
00196       if(self.gcomprisBoard.level>self.gcomprisBoard.maxlevel):
00197         # the current board is finished : bail out
00198         gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00199         return 0
00200 
00201     self.display_current_level()
00202     return 1
00203 

Here is the call graph for this function:

Here is the caller graph for this function:

def algorithm.Gcompris_algorithm.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 174 of file algorithm.py.

00174 
00175   def key_press(self, keyval, commit_str, preedit_str):
00176     print("got key %i" % keyval)
00177     return False

Definition at line 92 of file algorithm.py.

00092 
00093   def ok(self):
00094     print("Gcompris_algorithm ok.")

def algorithm.Gcompris_algorithm.paint_image (   self,
  i,
  x2,
  y2 
)

Definition at line 43 of file algorithm.py.

00043 
00044   def paint_image (self, i, x2, y2):
00045 
00046 
00047     return self.rootitem.add(
00048         gnomecanvas.CanvasPixbuf,
00049         pixbuf = self.pixlist[i],
00050         x=self.leftx+x2*self.distance,
00051         y=y2
00052         )

Here is the caller graph for this function:

Definition at line 168 of file algorithm.py.

00168 
00169   def paint_qm (self):
00170     self.qm = self.rootitem.add(gnomecanvas.CanvasText, text = "?",
00171      x = self.place*self.distance+30+self.leftx,
00172      y = 185, fill_color_rgba = 0x000000ffL,
00173      font = gcompris.skin.get_font("gcompris/board/huge bold"))

Here is the caller graph for this function:

def algorithm.Gcompris_algorithm.pause (   self,
  pause 
)

Definition at line 96 of file algorithm.py.

00096 
00097   def pause(self, pause):
00098 
00099     self.board_paused = pause
00100 
00101     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00102     # the game is won
00103     if(pause == 0):
00104       self.increment_level()
00105       self.gamewon = 0
00106 
00107     return

Here is the call graph for this function:

def algorithm.Gcompris_algorithm.set_level (   self,
  level 
)

Definition at line 178 of file algorithm.py.

00178 
00179   def set_level(self, level):
00180     print("Gcompris_algorithm set level. %i" % level)
00181     self.gcomprisBoard.level=level;
00182     self.gcomprisBoard.sublevel=1;
00183     self.cleanup()
00184     self.display_current_level()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 67 of file algorithm.py.

00067 
00068   def start(self):
00069     gcompris.bar_set (0)
00070     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00071                             "images/scenery5_background.png")
00072     self.gcomprisBoard.level=1
00073     self.gcomprisBoard.sublevel=1
00074     self.gcomprisBoard.number_of_sublevel=5
00075     self.gcomprisBoard.maxlevel = 1
00076 
00077     self.symbollist = ["gcompris/misc/apple.png","gcompris/misc/strawberry.png","gcompris/misc/peer.png","gcompris/misc/football.png","gcompris/misc/cerise.png","gcompris/misc/egg.png","gcompris/misc/glass.png","gcompris/misc/eggpot.png"]
00078     self.pixlist = []
00079     for i in range (len(self.symbollist)):
00080      pixbuf2 = gcompris.utils.load_pixmap(self.symbollist [i])
00081      h2 = 60
00082      w2 = pixbuf2.get_width()*h2/pixbuf2.get_height()
00083      self.pixlist.append (pixbuf2.scale_simple(w2, h2, gtk.gdk.
00084       INTERP_BILINEAR))
00085      del pixbuf2
00086     self.display_current_level()
00087     print("Gcompris_algorithm start.")


Member Data Documentation

Definition at line 142 of file algorithm.py.

Definition at line 57 of file algorithm.py.

Definition at line 55 of file algorithm.py.

Definition at line 64 of file algorithm.py.

Definition at line 59 of file algorithm.py.

Definition at line 65 of file algorithm.py.

Definition at line 54 of file algorithm.py.

Definition at line 60 of file algorithm.py.

Definition at line 77 of file algorithm.py.

Definition at line 165 of file algorithm.py.

Definition at line 169 of file algorithm.py.

Definition at line 145 of file algorithm.py.

Definition at line 58 of file algorithm.py.

Definition at line 146 of file algorithm.py.

Definition at line 76 of file algorithm.py.


The documentation for this class was generated from the following file: