1
# gcompris - clickanddraw
4
# Copyright (C) 2007, 2008 Olivier Ponchaut
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, see <http://www.gnu.org/licenses/>.
29
from drawnumber import Gcompris_drawnumber
31
class Gcompris_clickanddraw(Gcompris_drawnumber):
33
def set_sublevel(self, sublevel=1):
34
"""Start of the game at sublevel number sublevel of level n"""
39
#Creation of canvas group use by the activity
42
parent = self.gcomprisBoard.canvas.get_root_item(),
45
#Setting of the first background image of the level
46
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
47
self.data[sublevel][0][1])
49
#Initialisation of sub-elements in list
53
#Display actual sublevel and number of sublevel of this level
54
self.gcomprisBoard.sublevel=sublevel
55
self.gcomprisBoard.number_of_sublevel=len(self.data)
57
gcompris.score.start(gcompris.score.STYLE_NOTE, 10, 485,self.gcomprisBoard.number_of_sublevel)
58
gcompris.score.set(self.gcomprisBoard.sublevel)
60
#Set point number 0 from which the draw start. This point is equal to first one.
61
self.MAX=self.data[sublevel][0][0]
62
self.POINT[0]=self.point(0,self.data[sublevel][self.MAX][0],self.data[sublevel][self.MAX][1],30)
63
self.POINT[0].props.visibility = goocanvas.ITEM_INVISIBLE
65
#Data loading from global data and display of points and numbers
69
if self.gcomprisBoard.level==1 :
70
self.POINT.append(self.point(idpt=(self.MAX-i+1),
71
x=self.data[sublevel][i][0],
72
y=self.data[sublevel][i][1],d=45))
73
elif self.gcomprisBoard.level==2 :
74
self.POINT.append(self.point(idpt=(self.MAX-i+1),
75
x=self.data[sublevel][i][0],
76
y=self.data[sublevel][i][1],d=30))
78
self.POINT.append(self.point(idpt=(self.MAX-i+1),
79
x=self.data[sublevel][i][0],
80
y=self.data[sublevel][i][1],d=20))
82
self.POINT[(self.MAX-i+1)].connect('button_press_event',
83
self.action,(self.MAX-i+1))
85
#Setting of display level to prevent covering a point with another
86
#point which cause an impossibility to select it.
88
self.POINT[(self.MAX-i+1)].lower(prev_point)
89
prev_point = self.POINT[(self.MAX-i+1)]
92
#Setting color of the first point to blue instead of green
93
self.POINT[1].set_properties(fill_color_rgba = 0x003DF5D0)
95
def action(self, objet, target, truc, idpt):
96
"""Action to do at each step during normal execution of the game"""
97
if truc.type == gtk.gdk.BUTTON_PRESS :
98
if idpt == (self.actu+1): #Action to execute if the selected point is the following of previous one
99
xd,yd,xa,ya = self.POINT[(idpt-1)].x, self.POINT[(idpt-1)].y, self.POINT[idpt].x, self.POINT[idpt].y
102
points = goocanvas.Points([(xd,yd), (xa,ya)]),
103
fill_color = 'black',
104
line_cap = cairo.LINE_CAP_ROUND,
107
if idpt == 2: # Always raise the first point
108
self.POINT[self.MAX].raise_(None)
110
objet.props.visibility = goocanvas.ITEM_INVISIBLE
111
if idpt==self.MAX : #Action to exectute if all points have been selected in good way
112
gcompris.set_background(self.ROOT,
113
self.data[self.gcomprisBoard.sublevel][0][2])
115
gcompris.bar_hide(True)
116
self.timeout = gobject.timeout_add(1500, self.lauch_bonus) # The level is complete -> Bonus display
118
else : # Action to execute if the selected point isn''t the last one of this level
119
# Set color in blue to next point. Too easy ???
120
self.POINT[(idpt+1)].set_properties(fill_color_rgba=0x003DF5D0)
121
self.actu = self.actu+1 #self.actu update to set it at actual value of selected point