Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
gnumch.Gcompris_gnumch Class Reference

List of all members.

Public Member Functions

def __init__
def start
def show_trogwarning
def hide_trogwarning
def show_message
def hide_message
def set_level
def trog_spawn_time
def setNum
def key_press
def stopGame
def startGame
def winGame
def loseGame
def onBoard
def pause
def increment_level
def repeat
def timeout_add
def end

Public Attributes

 board
 scrw
 scrh
 width
 height
 sw
 sh
 left
 top
 munchanimation
 troganimation
 trogmoves
 onmove
 onstop
 goodies
 paused
 stopped
 levelset
 move_tick
 num_moveticks
 munch_time
 trog_wait
 trogwarn_time
 trogspawn_min
 trogspawn_max
 rootitem
 players
 muncher
 troggles
 squares
 title
 message_back
 message
 trogwarning
 trogwarning_num
 won_level

Detailed Description

Definition at line 631 of file gnumch.py.


Constructor & Destructor Documentation

def gnumch.Gcompris_gnumch.__init__ (   self,
  board 
)

Definition at line 632 of file gnumch.py.

00632 
00633     def __init__(self, board):
00634         global game
00635         game = self
00636 
00637         self.board = board
00638         self.board.disable_im_context = True
00639         self.scrw = gcompris.BOARD_WIDTH
00640         self.scrh = gcompris.BOARD_HEIGHT
00641         self.width = 6
00642         self.height = 6
00643 
00644         self.sw = self.scrw / (self.width + 1)
00645         self.sh = self.scrh / (self.width + 1)
00646         self.left = self.scrw - (self.sw * self.width)
00647         self.top = self.scrh - (self.sh * self.height)
00648 
00649         self.munchanimation = gcompris.anim.Animation("gnumch/muncher.txt")
00650         self.troganimation = []
00651         self.trogmoves = [Troggle.trogMove_straight, Troggle.trogMove_random,
00652                           Troggle.trogMove_run, Troggle.trogMove_random,
00653                           Troggle.trogMove_chase]
00654         self.onmove = [ None, Troggle.onMove_create, None, None, None ]
00655         self.onstop = [ None, None, None, Troggle.onStop_munch, None ]
00656         for file in [ "gnumch/reggie.txt",
00657                       "gnumch/diaper.txt",
00658                       "gnumch/fraidy.txt",
00659                       "gnumch/eater.txt",
00660                       "gnumch/smarty.txt" ]:
00661             self.troganimation.append( gcompris.anim.Animation(file) )
00662 
00663         self.goodies = 0
00664         self.paused = 0
00665         self.stopped = 0
00666         if board.mode == "primes":
00667             self.levelset = PrimeLevelset()
00668         elif board.mode == "factors":
00669             self.levelset = FactorLevelset()
00670         elif board.mode == "multiples":
00671             self.levelset = MultipleLevelset()
00672         elif board.mode == "equality":
00673             self.levelset = EqualityLevelset()
00674         elif board.mode == "inequality":
00675             self.levelset = InequalityLevelset()
00676         else:
00677             print "Warning: no levelset type specified, defaulting to primes"
00678             self.levelset = PrimeLevelset()
00679 
00680         print "Gcompris_gnumch __init__."
00681 
00682         # config options
00683         self.move_tick = 30
00684         self.num_moveticks = 10
00685         self.munch_time = 400
00686         self.trog_wait = 1000
00687         self.trogwarn_time = 1000
00688         self.trogspawn_min = 3000
00689         self.trogspawn_max = 10000


Member Function Documentation

Definition at line 920 of file gnumch.py.

00920 
00921     def end(self):
00922         for i in range(0, len(self.troggles)):
00923             self.troggles[i].anim.destroy()
00924         if self.muncher.anim:
00925             self.muncher.anim.destroy()
00926         self.stopGame()
00927         self.rootitem.destroy()

Here is the call graph for this function:

Definition at line 809 of file gnumch.py.

00809 
00810     def hide_message(self):
00811         self.message.hide()
00812         self.message_back.hide()

Definition at line 795 of file gnumch.py.

00795 
00796     def hide_trogwarning(self):
00797         self.trogwarning_num -= 1
00798         if self.trogwarning_num == 0:
00799             self.trogwarning.hide()

Here is the caller graph for this function:

Definition at line 902 of file gnumch.py.

00902 
00903     def increment_level(self):
00904         self.board.sublevel += 1
00905         if self.board.sublevel > self.board.number_of_sublevel:
00906             self.set_level( self.board.level % self.board.maxlevel + 1)
00907         else:
00908             self.startGame();
00909 

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Gcompris_gnumch.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 841 of file gnumch.py.

00841 
00842     def key_press(self, keyval, commit_str, preedit_str):
00843         self.muncher.push_key(keyval)
00844         return True

Definition at line 885 of file gnumch.py.

00885 
00886     def loseGame(self):
00887         self.stopGame()
00888         gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.TUX)

Here is the call graph for this function:

def gnumch.Gcompris_gnumch.onBoard (   self,
  x,
  y 
)

Definition at line 889 of file gnumch.py.

00889 
00890     def onBoard(self, x, y):
00891         return x >= 0 and x < self.width and y >= 0 and y < self.height

def gnumch.Gcompris_gnumch.pause (   self,
  p 
)

Definition at line 892 of file gnumch.py.

00892 
00893     def pause(self, p):
00894         self.paused = p
00895 
00896         if p == 0:
00897             if self.won_level:
00898                 # if we are paused, then unpaused it means that they beat the sublevel
00899                 self.increment_level()
00900             else:
00901                 self.set_level(self.board.level)

Here is the call graph for this function:

Definition at line 910 of file gnumch.py.

00910 
00911     def repeat(self):
00912         self.stopGame()
00913         self.startGame()

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Gcompris_gnumch.set_level (   self,
  level 
)

Definition at line 813 of file gnumch.py.

00813 
00814     def set_level(self, level):
00815         self.board.level = level;
00816         self.board.sublevel = 1;
00817         gcompris.bar_set_level(self.board);
00818         self.trog_wait = 2000 - self.board.level*100
00819         self.stopGame()
00820         self.startGame()

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Gcompris_gnumch.setNum (   self,
  x,
  y,
  new 
)

Definition at line 824 of file gnumch.py.

00824 
00825     def setNum(self, x, y, new):
00826         change = 0
00827         if new == None or not new.good:
00828             change -= 1
00829         else:
00830             change += 1
00831         if self.squares[x][y].num == None or not self.squares[x][y].num.good:
00832             change += 1
00833         else:
00834             change -= 1
00835 
00836         change /= 2
00837         self.goodies += change
00838         if self.goodies == 0:
00839             self.winGame()
00840         self.squares[x][y].setNum(new)

Here is the call graph for this function:

def gnumch.Gcompris_gnumch.show_message (   self,
  text 
)

Definition at line 800 of file gnumch.py.

00800 
00801     def show_message(self, text):
00802         self.message.set( text = text )
00803         w = self.message.get_property("text-width")
00804         h = self.message.get_property("text-height")
00805         self.message_back.set( x1 = (self.scrw - w)/2, y1 = (self.scrh - h)/2,
00806                                x2 = (self.scrw + w)/2, y2 = (self.scrh + h)/2 )
00807         self.message_back.show()
00808         self.message.show()

Definition at line 790 of file gnumch.py.

00790 
00791     def show_trogwarning(self):
00792         self.trogwarning_num += 1
00793         if self.trogwarning_num == 1:
00794             self.trogwarning.show()

Definition at line 690 of file gnumch.py.

00690 
00691     def start(self):
00692         self.board.level = 1
00693         self.board.maxlevel = self.levelset.numlevels
00694         self.board.sublevel = 1
00695         self.board.number_of_sublevel = self.levelset.num_sublevels
00696         self.trog_wait = 1900
00697 
00698         gcompris.bar_set(0)
00699         gcompris.set_background(self.board.canvas.root(), gcompris.skin.image_to_skin("gcompris-bg.jpg"))
00700         gcompris.bar_set_level(self.board)
00701 
00702         pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
00703         if(pixmap):
00704             gcompris.bar_set_repeat_icon(pixmap)
00705             gcompris.bar_set(gcompris.BAR_LEVEL | gcompris.BAR_REPEAT_ICON)
00706         else:
00707             gcompris.bar_set(gcompris.BAR_LEVEL | gcompris.BAR_REPEAT)
00708 
00709         # create our rootitem. We put each canvas item here so at the end we only
00710         # need to destroy the rootitem
00711         self.rootitem = self.board.canvas.root().add(gnomecanvas.CanvasGroup,
00712                                                      x=0.0,
00713                                                      y=0.0)
00714 
00715         # draw the board on top of the background
00716         for i in range(0,self.width+1):
00717             self.rootitem.add(gnomecanvas.CanvasLine,
00718                               points = (i*self.sw + self.left, self.top,
00719                                         i*self.sw + self.left, self.scrh),
00720                               fill_color_rgba = 0x000000FFL,
00721                               width_units = 3.0)
00722         for i in range(0,self.height+1):
00723             self.rootitem.add(gnomecanvas.CanvasLine,
00724                               points = (self.left, self.top + i*self.sh,
00725                                         self.scrw, self.top + i*self.sh),
00726                               fill_color_rgba = 0x000000FFL,
00727                               width_units = 3.0)
00728 
00729         # munchers and troggles
00730         self.players = []
00731         self.muncher = Muncher()
00732         self.troggles = [Troggle(), Troggle(), Troggle()]
00733 
00734         self.players[:] = self.troggles
00735         self.players.append(self.muncher)
00736 
00737         # create the squares
00738         self.squares = []
00739         for i in range(0, self.width):
00740             tmp = []
00741             for j in range(0, self.height):
00742                 s = Square(self.left + self.sw*i + self.sw/2, self.top + self.sh*j + self.sh/2)
00743                 s.pic.raise_to_top()
00744                 tmp.append( s )
00745             self.squares.append(tmp)
00746 
00747         # so that the troggles get clipped to the board area
00748         self.rootitem.add(gnomecanvas.CanvasRect,
00749                           x1=0, y1=0,
00750                           x2=self.scrw, y2=self.top,
00751                           fill_color_rgba = 0xFFFFFFFFL)
00752         self.rootitem.add(gnomecanvas.CanvasRect,
00753                           x1=0, y1=0,
00754                           x2=self.left, y2=self.scrh,
00755                           fill_color_rgba = 0xFFFFFFFFL)
00756 
00757         # the board title
00758         self.title = self.rootitem.add(gnomecanvas.CanvasText,
00759                                        text = "",
00760                                        font = gcompris.skin.get_font("gcompris/board/huge bold"),
00761                                        x = self.scrw/2,
00762                                        y = self.top/2)
00763 
00764         # the message
00765         self.message_back = self.rootitem.add(gnomecanvas.CanvasRect,
00766                                         x1=0, y1=0, x2=1, y2=1,
00767                                         fill_color_rgba = 0x60F06060L)
00768         self.message = self.rootitem.add(gnomecanvas.CanvasText,
00769                                         text = "",
00770                                         justification = gtk.JUSTIFY_CENTER,
00771                                         font = gcompris.skin.get_font("gcompris/board/huge bold"),
00772                                         x = self.scrw/2,
00773                                         y = self.scrh/2)
00774         self.message.hide()
00775 
00776         # the trogwarning
00777         self.trogwarning = self.rootitem.add(gnomecanvas.CanvasText,
00778                                         text = _("T\nR\nO\nG\nG\nL\nE"),
00779                                         justification = gtk.JUSTIFY_CENTER,
00780                                         font = gcompris.skin.get_font("gcompris/board/huge bold"),
00781                                         x = self.left/2,
00782                                         y = self.scrh/2)
00783         self.trogwarning.hide()
00784         self.trogwarning_num = 0
00785 
00786         # the spare life
00787         self.muncher.spare.gnomecanvas.raise_to_top()
00788 
00789         self.startGame()

Definition at line 857 of file gnumch.py.

00857 
00858     def startGame(self):
00859         self.stopped = 0
00860         self.levelset.setLevel(self.board.level, self.board.sublevel)
00861         self.title.set(text = self.levelset.getTitle())
00862         self.trogwarning_num = 1
00863         self.hide_trogwarning()
00864         self.goodies = 0
00865         self.won_level = 0
00866         for col in self.squares:
00867             for s in col:
00868                 s.setNum( self.levelset.getNumber() )
00869                 if s.num.good:
00870                     self.goodies += 1
00871 
00872         self.muncher.lives = 1
00873         for i in range(0, len(self.troggles)):
00874             if i < self.board.sublevel-1:
00875                 self.troggles[i].die()
00876             else: # don't move them into the spawning queue
00877                 self.troggles[i].exists = 0
00878                 self.troggles[i].anim.gnomecanvas.hide()
00879         self.muncher.spawn()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 845 of file gnumch.py.

00845 
00846     def stopGame(self):
00847         self.stopped = 1
00848         if self.muncher.munch_timer != 0:
00849             gtk.timeout_remove(self.muncher.munch_timer)
00850         if self.muncher.movestep_timer != 0:
00851             gtk.timeout_remove(self.muncher.movestep_timer)
00852 
00853         for t in self.troggles:
00854             for timer in [t.munch_timer, t.movestep_timer, t.nextmove_timer, t.nextspawn_timer, t.warn_timer]:
00855                 if timer != 0:
00856                     gtk.timeout_remove(timer)

Here is the caller graph for this function:

def gnumch.Gcompris_gnumch.timeout_add (   self,
  t,
  fn 
)

Definition at line 914 of file gnumch.py.

00914 
00915     def timeout_add(self, t, fn):
00916         if not self.paused and not self.stopped:
00917             return gtk.timeout_add(t, fn)
00918         else:
00919             return 0

Definition at line 821 of file gnumch.py.

00821 
00822     def trog_spawn_time(self):
00823         return random.randint(self.trogspawn_min, self.trogspawn_max)

Definition at line 880 of file gnumch.py.

00880 
00881     def winGame(self):
00882         self.stopGame()
00883         self.won_level = 1
00884         gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.TUX)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 636 of file gnumch.py.

Definition at line 662 of file gnumch.py.

Definition at line 641 of file gnumch.py.

Definition at line 645 of file gnumch.py.

Definition at line 666 of file gnumch.py.

Definition at line 767 of file gnumch.py.

Definition at line 764 of file gnumch.py.

Definition at line 682 of file gnumch.py.

Definition at line 684 of file gnumch.py.

Definition at line 648 of file gnumch.py.

Definition at line 730 of file gnumch.py.

Definition at line 683 of file gnumch.py.

Definition at line 653 of file gnumch.py.

Definition at line 654 of file gnumch.py.

Definition at line 663 of file gnumch.py.

Definition at line 729 of file gnumch.py.

Definition at line 710 of file gnumch.py.

Definition at line 639 of file gnumch.py.

Definition at line 638 of file gnumch.py.

Definition at line 644 of file gnumch.py.

Definition at line 737 of file gnumch.py.

Definition at line 664 of file gnumch.py.

Definition at line 643 of file gnumch.py.

Definition at line 757 of file gnumch.py.

Definition at line 646 of file gnumch.py.

Definition at line 685 of file gnumch.py.

Definition at line 649 of file gnumch.py.

Definition at line 731 of file gnumch.py.

Definition at line 650 of file gnumch.py.

Definition at line 688 of file gnumch.py.

Definition at line 687 of file gnumch.py.

Definition at line 686 of file gnumch.py.

Definition at line 776 of file gnumch.py.

Definition at line 783 of file gnumch.py.

Definition at line 640 of file gnumch.py.

Definition at line 864 of file gnumch.py.


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