Back to index

gcompris  8.2.2
Classes | Public Member Functions | Public Attributes
bargame.Gcompris_bargame Class Reference

List of all members.

Classes

class  answer_button
class  ball
class  hole
class  prof_button

Public Member Functions

def __init__
def start
def end
def set_level
def ok
def key_press
def repeat
def pause
def set_sublevel
def calculate_win_places
def cleanup
def newGame
def play
def machine_play
def gamelost

Public Attributes

 gcomprisBoard
 rootitem
 board_paused
 number_balls
 board_size
 scales
 holes
 balls
 list_win
 profbutton
 answer
 pixmap_blue_ball
 pixmap_green_ball
 pixmap_case
 pixmap_case_last
 pixmap_ombre
 pixmap_mask
 pixmap_mask_last
 rootitem_p
 last_played
 finished_sublevel
 game_won

Detailed Description

The Bar Game

Definition at line 44 of file bargame.py.


Constructor & Destructor Documentation

def bargame.Gcompris_bargame.__init__ (   self,
  gcomprisBoard 
)

Definition at line 47 of file bargame.py.

00047 
00048   def __init__(self, gcomprisBoard):
00049     random.seed()
00050     self.gcomprisBoard = gcomprisBoard
00051     self.rootitem = None
00052 
00053     # To display the bonus, we need to pause the board.
00054     self.board_paused  = 0
00055     self.number_balls = [[1,4],[2,6],[3,6]]
00056     self.board_size = [15,19,29]
00057     self.gcomprisBoard.level=1
00058     self.gcomprisBoard.maxlevel=4
00059     self.gcomprisBoard.sublevel=1
00060     self.gcomprisBoard.number_of_sublevel=3
00061 
00062     # global scale depending on the level
00063     self.scales = [0.208, 0.164, 0.107]
00064 
00065     self.holes = []
00066     self.balls = []
00067     self.list_win = []
00068     self.profbutton = []
00069     self.answer = []
00070 
00071     self.pixmap_blue_ball  = gcompris.utils.load_pixmap("bargame/blue_ball.png")
00072     self.pixmap_green_ball = gcompris.utils.load_pixmap("bargame/green_ball.png")
00073     self.pixmap_case       = gcompris.utils.load_pixmap("bargame/case.png")
00074     self.pixmap_case_last  = gcompris.utils.load_pixmap("bargame/case_last.png")
00075     self.pixmap_ombre      = gcompris.utils.load_pixmap("bargame/ombre.png")
00076     self.pixmap_mask       = gcompris.utils.load_pixmap("bargame/mask.png")
00077     self.pixmap_mask_last  = gcompris.utils.load_pixmap("bargame/mask_last.png")


Member Function Documentation

Definition at line 171 of file bargame.py.

00171 
00172   def calculate_win_places(self):
00173     winners = []
00174 
00175     min = self.number_balls[self.gcomprisBoard.sublevel-1][0]
00176     max = self.number_balls[self.gcomprisBoard.sublevel-1][1]
00177     period = (min + max)
00178 
00179     winners_list = [(self.board_size[self.gcomprisBoard.sublevel-1] -1 -x)% period for x in range(min)]
00180     for i in range(self.board_size[self.gcomprisBoard.sublevel-1]):
00181       if ((i+1) % period) in  winners_list:
00182         winners.append(i)
00183 
00184     level_win = (self.gcomprisBoard.level -1) * min
00185 
00186     if level_win == 0:
00187       winners = []
00188     else:
00189       winners = winners[-level_win:]
00190 
00191     return winners

Definition at line 193 of file bargame.py.

00193 
00194   def cleanup(self):
00195     if self.rootitem:
00196       self.rootitem.destroy()
00197 
00198     # Holes reinit
00199     for h in self.holes:
00200       del h
00201 
00202     del self.holes
00203     self.holes = []
00204 
00205     # Balls reinit
00206     for h in self.balls:
00207       del h
00208 
00209     del self.balls
00210     self.balls = []
00211 
00212 
00213     # Other variable cleanup
00214     del self.list_win
00215     self.list_win = []

Here is the caller graph for this function:

Definition at line 108 of file bargame.py.

00108 
00109   def end(self):
00110     self.cleanup()
00111 
00112     del self.profbutton
00113     self.profbutton = []
00114 
00115     del self.answer
00116     self.answer = []
00117 
00118     if self.rootitem_p:
00119       self.rootitem_p.destroy()
00120 

Here is the call graph for this function:

def bargame.Gcompris_bargame.gamelost (   self,
  human 
)

Definition at line 301 of file bargame.py.

00301 
00302   def gamelost(self,human):
00303     self.finished_sublevel = True
00304     if human:
00305       gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.GNU)
00306     else:
00307       self.game_won = True
00308       gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.GNU)
00309 

Here is the caller graph for this function:

def bargame.Gcompris_bargame.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 134 of file bargame.py.

00134 
00135   def key_press(self, keyval, commit_str, preedit_str):
00136     return False

Definition at line 281 of file bargame.py.

00281 
00282   def machine_play(self):
00283 
00284     def accessible(x):
00285       if ((x + self.last_played) in self.list_win):
00286         return True
00287       return False
00288 
00289     playable = filter(accessible,
00290                       range(self.number_balls[self.gcomprisBoard.sublevel-1][0],
00291                             self.number_balls[self.gcomprisBoard.sublevel-1][1]+1))
00292 
00293     if playable != []:
00294       self.play(random.choice(playable),False)
00295     else:
00296       self.play(random.choice(range(self.number_balls[self.gcomprisBoard.sublevel-1][0],
00297                                     self.number_balls[self.gcomprisBoard.sublevel-1][1]+1)),
00298                 False)
00299 
00300     self.answer.new_value(self.number_balls[self.gcomprisBoard.sublevel-1][0])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 216 of file bargame.py.

00216 
00217   def newGame(self):
00218     self.cleanup()
00219 
00220     width_ref = 256
00221 
00222     scale = self.scales[self.gcomprisBoard.sublevel-1]
00223 
00224     self.last_played = -1
00225     self.finished_sublevel = False
00226     self.game_won = False
00227     self.list_win = self.calculate_win_places()
00228 
00229 
00230     # Create root item canvas for the board
00231     self.rootitem = self.gcomprisBoard.canvas.root().add(
00232       gnomecanvas.CanvasGroup,
00233       x=0,
00234       y=0
00235       )
00236 
00237     # background
00238     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00239                             backgrounds[self.gcomprisBoard.level - 1])
00240 
00241     self.profbutton.set_prof(profs[self.gcomprisBoard.level - 1])
00242 
00243     for i in range(self.board_size[self.gcomprisBoard.sublevel-1]):
00244       self.holes.append(self.hole(self,
00245                                   self.rootitem,
00246                                   i * width_ref * scale,
00247                                   gcompris.BOARD_HEIGHT - 120, i,
00248                                   self.board_size[self.gcomprisBoard.sublevel-1],
00249                                   scale))
00250 
00251     for i in range(self.number_balls[self.gcomprisBoard.sublevel-1][1]):
00252       self.balls.append(self.ball(self.rootitem,
00253                                   i * width_ref * scale + 150,
00254                                   gcompris.BOARD_HEIGHT - 160,
00255                                   scale,
00256                                   self.pixmap_blue_ball))
00257       self.balls.append(self.ball(self.rootitem,
00258                                   i * width_ref * scale +150,
00259                                   gcompris.BOARD_HEIGHT-70,
00260                                   scale,
00261                                   self.pixmap_green_ball))
00262 
00263     self.answer.set_number_of_balls(self.number_balls[self.gcomprisBoard.sublevel-1])
00264 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 129 of file bargame.py.

00129 
00130   def ok(self):
00131     self.answer.has_focus()
00132     self.play(self.answer.value,True)
00133     pass

Here is the call graph for this function:

def bargame.Gcompris_bargame.pause (   self,
  pause 
)

Definition at line 140 of file bargame.py.

00140 
00141   def pause(self, pause):
00142     self.board_paused = pause
00143 
00144     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00145     # the game is won
00146     if ((pause == 0) and self.finished_sublevel):
00147       self.set_sublevel(self.gcomprisBoard.sublevel+1)
00148       return 0
00149 

Here is the call graph for this function:

def bargame.Gcompris_bargame.play (   self,
  value,
  human 
)

Definition at line 265 of file bargame.py.

00265 
00266   def play(self, value, human):
00267     for i in range(1,value+1):
00268       self.last_played += 1
00269       if human:
00270         self.holes[self.last_played].isGreen()
00271       else:
00272         self.holes[self.last_played].isBlue()
00273 
00274       if self.last_played == self.board_size[self.gcomprisBoard.sublevel-1] - 1 :
00275         self.gamelost(human)
00276         return
00277 
00278     if human:
00279       self.machine_play()
00280 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 137 of file bargame.py.

00137 
00138   def repeat(self):
00139     self.newGame()

Here is the call graph for this function:

Here is the caller graph for this function:

def bargame.Gcompris_bargame.set_level (   self,
  level 
)

Definition at line 121 of file bargame.py.

00121 
00122   def set_level(self,level):
00123     self.gcomprisBoard.level = level
00124     self.gcomprisBoard.sublevel = 1
00125     gcompris.bar_set_level(self.gcomprisBoard)
00126 
00127     self.newGame()
00128     pass

Here is the call graph for this function:

Here is the caller graph for this function:

def bargame.Gcompris_bargame.set_sublevel (   self,
  sublevel 
)

Definition at line 154 of file bargame.py.

00154 
00155   def set_sublevel(self, sublevel):
00156     #sublevel change only in game_won
00157     if sublevel > self.gcomprisBoard.number_of_sublevel:
00158       if self.game_won:
00159         if self.gcomprisBoard.level == self.gcomprisBoard.maxlevel:
00160           gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00161           return 0
00162         else:
00163           self.set_level(self.gcomprisBoard.level+1)
00164       else:
00165         self.gcomprisBoard.sublevel = 1
00166         self.newGame()
00167     else:
00168       self.gcomprisBoard.sublevel = sublevel
00169       self.newGame()
00170 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file bargame.py.

00078 
00079   def start(self):
00080     # load pixmaps for the ui.
00081     #
00082     pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
00083     if(pixmap):
00084       gcompris.bar_set_repeat_icon(pixmap)
00085       gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT_ICON)
00086     else:
00087       gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT)
00088     gcompris.bar_set_level(self.gcomprisBoard)
00089 
00090     # Create persistent over levels root item canvas for the board
00091     self.rootitem_p = self.gcomprisBoard.canvas.root().add(
00092       gnomecanvas.CanvasGroup,
00093       x=0,
00094       y=0
00095       )
00096 
00097     self.profbutton = self.prof_button(self,
00098                                        self.rootitem_p,
00099                                        profs[self.gcomprisBoard.level - 1])
00100 
00101     self.answer = self.answer_button(self.rootitem_p,
00102                                      self.scales[self.gcomprisBoard.sublevel-1],
00103                                      self.pixmap_green_ball,
00104                                      self.number_balls[self.gcomprisBoard.sublevel-1])
00105 
00106     #
00107     self.newGame()


Member Data Documentation

Definition at line 68 of file bargame.py.

Definition at line 65 of file bargame.py.

Definition at line 53 of file bargame.py.

Definition at line 55 of file bargame.py.

Definition at line 224 of file bargame.py.

Definition at line 225 of file bargame.py.

Definition at line 49 of file bargame.py.

Definition at line 64 of file bargame.py.

Definition at line 223 of file bargame.py.

Definition at line 66 of file bargame.py.

Definition at line 54 of file bargame.py.

Definition at line 70 of file bargame.py.

Definition at line 72 of file bargame.py.

Definition at line 73 of file bargame.py.

Definition at line 71 of file bargame.py.

Definition at line 75 of file bargame.py.

Definition at line 76 of file bargame.py.

Definition at line 74 of file bargame.py.

Definition at line 67 of file bargame.py.

Definition at line 50 of file bargame.py.

Definition at line 90 of file bargame.py.

Definition at line 62 of file bargame.py.


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