comparison frontends/src/wix/quiz_game.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children beaf6bec2fcd
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
47 self.zindex = zindex 47 self.zindex = zindex
48 self.transparent = transparent 48 self.transparent = transparent
49 49
50 def __cmp__(self, other): 50 def __cmp__(self, other):
51 return self.zindex.__cmp__(other.zindex) 51 return self.zindex.__cmp__(other.zindex)
52 52
53 def draw(self, dc, x=None, y=None): 53 def draw(self, dc, x=None, y=None):
54 """Draw the card on the device context 54 """Draw the card on the device context
55 @param dc: device context 55 @param dc: device context
56 @param x: abscissa 56 @param x: abscissa
57 @param y: ordinate""" 57 @param y: ordinate"""
58 dc.DrawBitmap(self.bitmap, x or self.x, y or self.y, self.transparent) 58 dc.DrawBitmap(self.bitmap, x or self.x, y or self.y, self.transparent)
59 59
60 class BaseWindow(wx.Window): 60 class BaseWindow(wx.Window):
61 """This is the panel where the game is drawed, under the other widgets""" 61 """This is the panel where the game is drawed, under the other widgets"""
62 62
63 def __init__(self, parent): 63 def __init__(self, parent):
64 wx.Window.__init__(self, parent, pos=(0,0), size=(WIDTH, HEIGHT)) 64 wx.Window.__init__(self, parent, pos=(0,0), size=(WIDTH, HEIGHT))
65 self.parent = parent 65 self.parent = parent
66 self.SetMinSize(wx.Size(WIDTH, HEIGHT)) 66 self.SetMinSize(wx.Size(WIDTH, HEIGHT))
67 self.Bind(wx.EVT_PAINT, self.onPaint) 67 self.Bind(wx.EVT_PAINT, self.onPaint)
96 device_context.SetTextForeground(wx.BLACK) 96 device_context.SetTextForeground(wx.BLACK)
97 97
98 for i in range(4): 98 for i in range(4):
99 answer = self.parent.players_data[i]["answer"] 99 answer = self.parent.players_data[i]["answer"]
100 score = self.parent.players_data[i]["score"] 100 score = self.parent.players_data[i]["score"]
101 if answer == None: 101 if answer == None:
102 device_context.DrawText("%d" % score, 100 + i*184, 355) 102 device_context.DrawText("%d" % score, 100 + i*184, 355)
103 else: 103 else:
104 device_context.DrawBitmap(self.right_image if answer else self.wrong_image, 39+i*184, 348, True) 104 device_context.DrawBitmap(self.right_image if answer else self.wrong_image, 39+i*184, 348, True)
105 105
106 106
116 left = self.parent.time_left = max(0,limit - current) 116 left = self.parent.time_left = max(0,limit - current)
117 device_context.SetBrush(wx.RED_BRUSH if left/total < 1/4.0 else wx.WHITE_BRUSH) 117 device_context.SetBrush(wx.RED_BRUSH if left/total < 1/4.0 else wx.WHITE_BRUSH)
118 if left: 118 if left:
119 #we now draw the timer 119 #we now draw the timer
120 angle = ((-2*pi)*((total-left)/total) + (pi/2)) 120 angle = ((-2*pi)*((total-left)/total) + (pi/2))
121 x = center_x + radius * cos(angle) 121 x = center_x + radius * cos(angle)
122 y = center_y - radius * sin(angle) 122 y = center_y - radius * sin(angle)
123 device_context.DrawArc(center_x, center_y-radius, x, y, center_x, center_y) 123 device_context.DrawArc(center_x, center_y-radius, x, y, center_x, center_y)
124 124
125 def onPaint(self, event): 125 def onPaint(self, event):
126 dc = wx.PaintDC(self) 126 dc = wx.PaintDC(self)
127 self.fullPaint(dc) 127 self.fullPaint(dc)
128 128
129 129
130 130
131 class QuizPanel(wx.Panel): 131 class QuizPanel(wx.Panel):
132 """This class is used to display the quiz game""" 132 """This class is used to display the quiz game"""
133 133
154 self.players_data[i]['answer'] = None #True if the player gave a good answer 154 self.players_data[i]['answer'] = None #True if the player gave a good answer
155 self.players_data[i]['score'] = 0 155 self.players_data[i]['score'] = 0
156 self.answer.Bind(wx.EVT_TEXT_ENTER, self.answered) 156 self.answer.Bind(wx.EVT_TEXT_ENTER, self.answered)
157 self.parent.host.bridge.quizGameReady(player_nick, referee, profile_key = self.parent.host.profile) 157 self.parent.host.bridge.quizGameReady(player_nick, referee, profile_key = self.parent.host.profile)
158 self.state = None 158 self.state = None
159 159
160 def answered(self, event): 160 def answered(self, event):
161 """Called when the player gave an answer in the box""" 161 """Called when the player gave an answer in the box"""
162 self.last_answer = self.answer.GetValue() 162 self.last_answer = self.answer.GetValue()
163 self.answer.Clear() 163 self.answer.Clear()
164 if self.last_answer: 164 if self.last_answer:
182 self.time_left = timer 182 self.time_left = timer
183 self.time_origin = time() 183 self.time_origin = time()
184 self.time_limit = self.time_origin + timer 184 self.time_limit = self.time_origin + timer
185 self.time_pause = None 185 self.time_pause = None
186 self.__timer_refresh() 186 self.__timer_refresh()
187 187
188 def __timer_refresh(self): 188 def __timer_refresh(self):
189 self.Refresh() 189 self.Refresh()
190 if self.time_left: 190 if self.time_left:
191 wx.CallLater(1000, self.__timer_refresh) 191 wx.CallLater(1000, self.__timer_refresh)
192 192
201 @param question: question to ask""" 201 @param question: question to ask"""
202 self.question.ChangeValue(question) 202 self.question.ChangeValue(question)
203 self.startTimer(timer) 203 self.startTimer(timer)
204 self.last_answer = None 204 self.last_answer = None
205 self.answer.Clear() 205 self.answer.Clear()
206 206
207 def quizGamePlayerBuzzed(self, player, pause): 207 def quizGamePlayerBuzzed(self, player, pause):
208 """Called when the player pushed the buzzer 208 """Called when the player pushed the buzzer
209 @param player: player who pushed the buzzer 209 @param player: player who pushed the buzzer
210 @param pause: should we stop the timer ?""" 210 @param pause: should we stop the timer ?"""
211 if pause: 211 if pause:
212 self.time_pause = time() 212 self.time_pause = time()
213 213
214 def quizGamePlayerSays(self, player, text, delay): 214 def quizGamePlayerSays(self, player, text, delay):
215 """Called when the player says something 215 """Called when the player says something
216 @param player: who is talking 216 @param player: who is talking
217 @param text: what the player says""" 217 @param text: what the player says"""
218 if player != self.player_nick and self.last_answer: 218 if player != self.player_nick and self.last_answer: