Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/game/Area1Game4.py
blob: c2a57630f5a7c44d1a4d0c11965dec653e2e62c9 (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# -*- coding: utf-8 -*-

import pygame
import random
import api.Image as Image
from api.Game import CGame
from api.GameState import CGameState
from api.Button import CButton
from api.Globe import Globe
from api.Sprite2 import CSprite
from api.MultiLabel import CMultiLabel
from api.Points import CPoints
import HallState
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 area1game4_data.ITEMS.keys():
            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((255, 125, 0))
            button.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 26)
            #button.set_center((110, 650))
            button.set_size((230, 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(316, 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.mBsetted = False
        self.mNsetted = True
                
        self.mBackImageN = Image.loadImage('assets/images/back.png')
        self.mBackImageB = Image.loadImage('assets/images/back_big.png')
        
        self.mButtonBack = CSprite()
        self.mButtonBack.setRegistrationPointOffset(22, 22)
        self.mButtonBack.setXY(1170, 30)
        self.mButtonBack.setImage(self.mBackImageN)
        CGame().addChild(self.mButtonBack)
        
        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()
        self.mLabelQuestion.bgColor = (252, 175, 23)
        self.mLabelQuestion.set_font(fontSize=28)
        self.mLabelQuestion.set_center((600, 250))
        self.mLabelQuestion.set_size((380, 150))
        self.mLabelQuestion.set_text(self.mQuestions[self.mQuestionsL[self.mCurrentQuestion]][0])
        CGame().addChild(self.mLabelQuestion)
        
        t = unicode(_('Ăšltima pregunta'), 'UTF-8')
        self.mLabelEnd = Globe((400, 100), pico='None', text=t)
        self.mLabelEnd.set_center((600, 400))
        
    def update(self):

        CGameState.update(self)
        
        if self.mButtonBack.mouseOver():
            if not(self.mBsetted):
                self.mBsetted = True
                self.mNsetted = False
                self.mButtonBack.setRegistrationPointOffset(27, 27)
                self.mButtonBack.setImage(self.mBackImageB)
        else:
            if not(self.mNsetted):
                self.mBsetted = False
                self.mNSetted = True
                self.mButtonBack.setRegistrationPointOffset(22, 22)
                self.mButtonBack.setImage(self.mBackImageN)
        
        if self.mButtonBack.clicked():
            hs = HallState.CHallState()
            CGame().setState(hs)
            hs.setCurrentGame(3)
            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
                    
                #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
                self.mCurrentQuestion = self.mCurrentQuestion + 1
                #print 'estado de preguntas', self.mCurrentQuestion
                if not(self.mCurrentQuestion == 6):
                    self.mLabelQuestion.set_text(self.mQuestions[self.mQuestionsL[self.mCurrentQuestion]][0])
                else:
                    CGame().addChild(self.mLabelEnd)
                    CGame().removeChild(self.mBook)
                    CGame().removeChild(self.mLabelQuestion)
                    #print 'ultima'
        
        
    def destroy(self):
        CGameState.destroy(self)

        CGame().removeChild(self.mButtonBack)
        CGame().removeChild(self.mLabelQuestion)
        CGame().removeChild(self.mPoints)
        CGame().removeChild(self.mBook)
        CGame().removeChild(self.mGoodSprite)
        CGame().removeChild(self.mBadSprite)
        CGame().removeChild(self.mLabelEnd)
        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