Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
hexagon.Gcompris_hexagon Class Reference

List of all members.

Public Member Functions

def __init__
def start
def end
def ok
def key_press
def pause
def cleanup
def paint_hex
def paint_skin
def coloring
def finished
def on_click
def paint_cat
def distance_cat

Public Attributes

 gcomprisBoard
 rootitem
 board_paused
 gamewon
 random_catx
 random_caty
 pts
 r
 cx
 cy
 sqrt3

Detailed Description

The minouche activity

Definition at line 31 of file hexagon.py.


Constructor & Destructor Documentation

def hexagon.Gcompris_hexagon.__init__ (   self,
  gcomprisBoard 
)

Definition at line 34 of file hexagon.py.

00034 
00035   def __init__(self, gcomprisBoard):
00036     self.gcomprisBoard = gcomprisBoard
00037     self.rootitem = None
00038 
00039     # These are used to let us restart only after the bonus is displayed.
00040     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00041     self.board_paused  = 0;
00042     self.gamewon       = False;
00043 


Member Function Documentation

Definition at line 87 of file hexagon.py.

00087 
00088   def cleanup(self):
00089 
00090     self.gamewon       = False;
00091     # Remove the root item removes all the others inside it
00092     if self.rootitem != None:
00093      self.rootitem.destroy()
00094      self.rootitem = None

Here is the caller graph for this function:

def hexagon.Gcompris_hexagon.coloring (   self,
  dist 
)

Definition at line 125 of file hexagon.py.

00125 
00126   def coloring(self,dist):
00127     r=b=g=0
00128     if dist <0.25:
00129      r = 0xFF
00130      g = long(4*0xFF*dist)
00131     elif dist <0.5:
00132      g = 0xFF
00133      r = 0xFF-long(4*(dist-0.25)*0xFF)
00134     elif dist <0.75:
00135      g = 0xFF-long(4*(dist-0.5)*0xFF)
00136      b = long(0xFF*4*(dist-0.5))
00137     elif dist <=1:
00138      b = 0xFF
00139      r = long(0xFF*4*(dist-0.75))
00140     else :
00141      pass
00142     color = r*0x1000000+g*0x10000+b*0x100+0xFF
00143     return color

Here is the caller graph for this function:

def hexagon.Gcompris_hexagon.distance_cat (   self,
  x,
  y 
)

Definition at line 176 of file hexagon.py.

00176 
00177   def distance_cat (self,x,y):
00178     dx = self.random_catx-x-int(self.random_caty/2)
00179     dy = self.random_caty-y
00180 
00181     if dx*dy >=0:
00182      return abs(dx)+abs(dy)
00183     if dx*dy<0:
00184      return max(abs(dx),abs(dy))

Here is the caller graph for this function:

Definition at line 58 of file hexagon.py.

00058 
00059   def end(self):
00060     self.cleanup()

Here is the call graph for this function:

Definition at line 144 of file hexagon.py.

00144 
00145   def finished(self):
00146     gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)

Here is the caller graph for this function:

def hexagon.Gcompris_hexagon.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 64 of file hexagon.py.

00064 
00065   def key_press(self, keyval, commit_str, preedit_str):
00066     #print("got key %i" % keyval)
00067     return False

Definition at line 61 of file hexagon.py.

00061 
00062   def ok(self):
00063     print("Gcompris_minouche ok.")

def hexagon.Gcompris_hexagon.on_click (   self,
  widget,
  event = None,
  x = 0,
  y = 0 
)

Definition at line 147 of file hexagon.py.

00147 
00148   def on_click (self, widget, event=None, x=0, y=0):
00149     if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1 :
00150 
00151      catdistance = self.distance_cat(x,y)
00152      #print self.random_catx, self.random_caty,x,y,catdistance
00153 
00154      if catdistance<0.1:
00155       self.paint_cat()
00156       self.gamewon       = True;
00157       gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.GNU)
00158      else:
00159        color = self.coloring (catdistance/30.0)
00160        widget.set(fill_color_rgba=color);
00161 

Here is the call graph for this function:

Definition at line 162 of file hexagon.py.

00162 
00163   def paint_cat(self):
00164     position =19+self.sqrt3*self.r*self.random_catx
00165     if self.random_caty%2:
00166      position +=self.sqrt3/2*self.r
00167     pixbuf2 = gcompris.utils.load_pixmap \
00168     ("gcompris/misc/strawberry.png")
00169     h2 = 30
00170     w2 = pixbuf2.get_width()*h2/pixbuf2.get_height()
00171     self.rootitem.add(gnomecanvas.CanvasPixbuf,
00172                       pixbuf=pixbuf2.scale_simple(w2, h2,
00173                                                   gtk.gdk.INTERP_BILINEAR),
00174                       x=position,
00175                       y=14+1.5*self.random_caty*self.r)

Here is the caller graph for this function:

def hexagon.Gcompris_hexagon.paint_hex (   self,
  x,
  y,
  color = 0x0099FFCCL 
)

Definition at line 95 of file hexagon.py.

00095 
00096   def paint_hex(self, x, y, color=0x0099FFCCL):
00097     ax = 30+self.sqrt3*self.r*x
00098     ay = 30+1.5*self.r*y
00099 
00100     if y&1 :
00101      ax+=self.sqrt3/2*self.r
00102     self.pts = []
00103     for i in range (len(self.cx)):
00104      self.pts.append (ax+self.cx [i])
00105      self.pts.append (ay+self.cy [i])
00106 
00107     s = self.rootitem.add(gnomecanvas.CanvasPolygon, points = self.pts,
00108          fill_color_rgba = color, outline_color = "black", width_units =
00109          2.5)
00110     return s

Definition at line 111 of file hexagon.py.

00111 
00112   def paint_skin(self):
00113     self.r = 20
00114     self.cx = []
00115     self.cy = []
00116     self.sqrt3 = math.sqrt(3)
00117     for i in range (6):
00118      self.cx.append(int(self.r*math.cos(math.pi/6+i*math.pi/3)))
00119      self.cy.append(int(self.r*math.sin(math.pi/6+i*math.pi/3)))
00120     for x in range (22):
00121      for y in range (16):
00122       s = self.paint_hex(x, y)
00123 
00124       s.connect ("event", self.on_click, x-int(y/2), y)

Here is the caller graph for this function:

def hexagon.Gcompris_hexagon.pause (   self,
  pause 
)

Definition at line 69 of file hexagon.py.

00069 
00070   def pause(self, pause):
00071 
00072     self.board_paused = pause
00073 
00074     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00075     # the game is won
00076     if(pause == 0 and self.gamewon):
00077       self.finished()
00078       self.gamewon = 0
00079 
00080     return
00081 

Here is the call graph for this function:

Definition at line 44 of file hexagon.py.

00044 
00045   def start(self):
00046     gcompris.bar_set (0)
00047     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00048                             gcompris.skin.image_to_skin("gcompris-bg.jpg"))
00049     self.rootitem = self.gcomprisBoard.canvas.root().add(
00050      gnomecanvas.CanvasGroup,
00051      x=0.0,
00052      y=0.0
00053      )
00054     self.paint_skin()
00055     self.random_catx = random.randrange(21)
00056     self.random_caty = random.randrange(15)
00057 

Here is the call graph for this function:


Member Data Documentation

Definition at line 40 of file hexagon.py.

Definition at line 113 of file hexagon.py.

Definition at line 114 of file hexagon.py.

Definition at line 41 of file hexagon.py.

Definition at line 35 of file hexagon.py.

Definition at line 101 of file hexagon.py.

Definition at line 112 of file hexagon.py.

Definition at line 54 of file hexagon.py.

Definition at line 55 of file hexagon.py.

Definition at line 36 of file hexagon.py.

Definition at line 115 of file hexagon.py.


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