1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# -*- coding: utf-8 -*-
import pygame
import random
import MenuState
import api.Image as Image
from api.Game import CGame
from api.GameState import CGameState
from api.Button import CButton
from api.Sprite import CSprite
from api.Label import CLabel
from api.MultiLabel import CMultiLabel
from api.Points import CPoints
from gettext import gettext as _
from assets.data import area1game4_data
STATE_ANSWER = 1
STATE_ANIM = 2
TIME_ANIM = 60
class CArea1Game4(CGameState):
def __init__(self):
CGameState.__init__(self)
self.mLocalState = STATE_ANSWER
self.mAnimCounter = 0
self.mBackground = None
self.mButtonBackA1G4 = None
self.mCurrentQuestion = 0
self.mQuestions = []
self.mButtonList = []
self.mBad = 0
self.mGood = 0
self.mPoints = CPoints()
self.mPoints.setXY(250, 10)
CGame().addChild(self.mPoints)
for i in range(6):
t = area1game4_data.ITEMS[i]
q = (unicode(t[0], 'UTF-8'), unicode(t[1], 'UTF-8'))
self.mQuestions.append(q)
button = CButton()
button.set_bgColor((0x99, 0x99, 0x66))
button.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 22)
#button.set_center((110, 650))
button.set_size((200, 40))
button.set_text(q[1])
self.mButtonList.append(button)
CGame().addChild(button)
self.mBackground = Image.loadImage('assets/images/a1g4/a1game4.png', False)
CGame().setBackground(self.mBackground)
self.mBook = CSprite()
self.mBook.setXY(300, 100)
self.mBook.loadImage('assets/images/a1g4/A1G4-libro.png')
CGame().addChild(self.mBook)
self.mGoodSprite = CSprite()
self.mGoodSprite.setXY(300, 100)
self.mGoodSprite.loadImage('assets/images/a1g4/good.png')
self.mBadSprite = CSprite()
self.mBadSprite.setXY(300, 100)
self.mBadSprite.loadImage('assets/images/a1g4/bad.png')
self.mButtonBackA1G4 = CButton()
self.mButtonBackA1G4.set_bgColor((0x99, 0x99, 0x66))
self.mButtonBackA1G4.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 20)
self.mButtonBackA1G4.set_center((110, 650))
self.mButtonBackA1G4.set_size((200, 40))
self.mButtonBackA1G4.set_text(_('Volver'))
CGame().addChild(self.mButtonBackA1G4)
self.mButtonList[0].set_center((350, 550))
self.mButtonList[1].set_center((600, 550))
self.mButtonList[2].set_center((850, 550))
self.mButtonList[3].set_center((350, 600))
self.mButtonList[4].set_center((600, 600))
self.mButtonList[5].set_center((850, 600))
self.mQuestionsL = range(6)
random.shuffle(self.mQuestionsL)
self.mLabelQuestion = CMultiLabel(transparent=True)
self.mLabelQuestion.set_center((600, 250))
self.mLabelQuestion.set_size((400, 100))
self.mLabelQuestion.set_text(self.mQuestions[self.mQuestionsL[self.mCurrentQuestion]][0])
CGame().addChild(self.mLabelQuestion)
def update(self):
CGameState.update(self)
if self.mButtonBackA1G4.clicked():
ms = MenuState.CMenuState()
CGame().setState(ms)
return
if self.mLocalState == STATE_ANSWER:
answer = -1
for i in range(6):
b = self.mButtonList[i]
if b.clicked():
answer = i
break
if not(answer == -1):
n = -1
if self.mCurrentQuestion < 6:
n = self.mQuestionsL[self.mCurrentQuestion]
if (answer == n):
b = self.mButtonList[answer]
b.mclicked = False
CGame().removeChild(b)
self.mGood = self.mGood + 1
self.mPoints.set_goods(self.mGood)
CGame().addChild(self.mGoodSprite)
else:
self.mBad = self.mBad + 1
self.mPoints.set_bads(self.mBad)
CGame().addChild(self.mBadSprite)
self.mLocalState = STATE_ANIM
self.mCurrentQuestion = self.mCurrentQuestion + 1
if not(self.mCurrentQuestion == 6):
self.mLabelQuestion.set_text(self.mQuestions[self.mQuestionsL[self.mCurrentQuestion]][0])
else:
CGame().removeChild(self.mLabelQuestion)
print 'ultima'
else:
print 'fin preguntas'
else:
self.mAnimCounter = self.mAnimCounter + 1
if self.mAnimCounter > TIME_ANIM:
self.mAnimCounter = 0
CGame().removeChild(self.mGoodSprite)
CGame().removeChild(self.mBadSprite)
self.mLocalState = STATE_ANSWER
def destroy(self):
CGameState.destroy(self)
CGame().removeChild(self.mButtonBackA1G4)
CGame().removeChild(self.mLabelQuestion)
CGame().removeChild(self.mPoints)
CGame().removeChild(self.mBook)
self.mButtonBackA1G4 = None
self.mBackground = None
self.mLabelDefinition = None
self.mBook = None
for i in range(6):
b = self.mButtonList[i]
CGame().removeChild(b)
b = None
print "CArea1Game4 destroy"
|