-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconozco.py
More file actions
executable file
·1978 lines (1873 loc) · 88.1 KB
/
Copy pathconozco.py
File metadata and controls
executable file
·1978 lines (1873 loc) · 88.1 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Conozco
# Copyright (C) 2008, 2012 Gabriel Eirea
# Copyright (C) 2011, 2012 Alan Aguiar
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Gabriel Eirea geirea@gmail.com
# Alan Aguiar alanjas@hotmail.com
import os.path
import random
import pygame
import time
import imp
import gettext
import configparser
from gettext import gettext as _
gtk_present = True
try:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
except:
gtk_present = False
# constantes
RADIO = 10
RADIO2 = RADIO**2
XMAPAMAX = 786
DXPANEL = 414
XCENTROPANEL = 1002
YGLOBITO = 100
DXBICHO = 255
DYBICHO = 412
XBICHO = 1200-DXBICHO
YBICHO = 900-DYBICHO-80
XPUERTA = 786
YPUERTA = 279
XBARRA_P = 840
YBARRA_P = 790
ABARRA_P = 40
YTEXTO = 370
XBARRA_A = XMAPAMAX+20
YBARRA_A = 900 - ABARRA_P - 20
ABARRA_A = DXPANEL-40
# control
TOTALAVANCE = 7
EVENTORESPUESTA = pygame.USEREVENT+1
TIEMPORESPUESTA = 2300
EVENTODESPEGUE = EVENTORESPUESTA+1
EVENTOREFRESCO = EVENTODESPEGUE+1
TIEMPOREFRESCO = 250
ESTADONORMAL = 1
ESTADOPESTANAS = 2
ESTADOFRENTE = 3
ESTADODESPEGUE = 4
# paths
CAMINORECURSOS = "recursos"
CAMINOCOMUN = "comun"
CAMINOFUENTES = "fuentes"
CAMINODATOS = "datos"
CAMINOIMAGENES = "imagenes"
CAMINOSONIDOS = "sonidos"
ARCHIVONIVELES = "levels"
ARCHIVOEXPLORACIONES = "explorations"
# colors
COLORNOMBREDEPTO = (10, 10, 10)
COLORNOMBRECAPITAL = (10, 10, 10)
COLORNOMBRERIO = (10, 10, 10)
COLORNOMBRERUTA = (10, 10, 10)
COLORNOMBREELEVACION = (10, 10, 10)
COLORESTADISTICAS1 = (10, 10, 150)
COLORESTADISTICAS2 = (10, 10, 10)
COLORPREGUNTAS = (80, 80, 155)
COLORPANEL = (156, 158, 172)
COLORBARRA_P = (255, 0, 0)
COLORBARRA_A = (0, 0, 255)
COLORBARRA_C = (0, 0, 0)
COLOR_FONDO = (0, 0, 0)
COLOR_ACT_NAME = (255, 255, 255)
COLOR_OPTION_B = (20, 20, 20)
COLOR_OPTION_T = (200, 100, 100)
COLOR_BUTTON_B = (20, 20, 20)
COLOR_BUTTON_T = (100, 200, 100)
COLOR_NEXT = (100, 100, 200)
COLOR_STAT_N = (100, 100, 200)
COLOR_SKIP = (255, 155, 155)
COLOR_CREDITS = (155, 155, 255)
COLOR_SHOW_ALL = (100, 20, 20)
# variables globales para adaptar la pantalla a distintas resoluciones
scale = 1
shift_x = 0
shift_y = 0
xo_resolution = True
clock = pygame.time.Clock()
class Punto():
"""Clase para objetos geograficos que se pueden definir como un punto.
La posicion esta dada por un par de coordenadas (x,y) medida en pixels
dentro del mapa.
"""
def __init__(self, nombre, tipo, simbolo, posicion, postexto):
self.nombre = nombre
self.tipo = int(tipo)
self.posicion = (int(int(posicion[0])*scale+shift_x),
int(int(posicion[1])*scale+shift_y))
self.postexto = (int(int(postexto[0])*scale)+self.posicion[0],
int(int(postexto[1])*scale)+self.posicion[1])
self.simbolo = simbolo
def estaAca(self, pos):
"""Devuelve un booleano indicando si esta en la coordenada pos,
la precision viene dada por la constante global RADIO"""
if (pos[0]-self.posicion[0])**2 + \
(pos[1]-self.posicion[1])**2 < RADIO2:
return True
else:
return False
def dibujar(self, pantalla, flipAhora):
"""Dibuja un punto en su posicion"""
pantalla.blit(self.simbolo, (self.posicion[0]-8, self.posicion[1]-8))
if flipAhora:
pygame.display.flip()
def mostrarNombre(self, pantalla, fuente, color, flipAhora):
"""Escribe el nombre del punto en su posicion"""
text = fuente.render(self.nombre, 1, color)
textrect = text.get_rect()
textrect.center = (self.postexto[0], self.postexto[1])
pantalla.blit(text, textrect)
if flipAhora:
pygame.display.flip()
class Zona():
"""Clase para objetos geograficos que se pueden definir como una zona.
La posicion esta dada por una imagen bitmap pintada con un color
especifico, dado por la clave (valor 0 a 255 del componente rojo).
"""
def __init__(self, mapa, nombre, claveColor, tipo, posicion, rotacion):
self.mapa = mapa # esto hace una copia en memoria o no????
self.nombre = nombre
self.claveColor = int(claveColor)
self.tipo = int(tipo)
self.posicion = (int(int(posicion[0])*scale+shift_x),
int(int(posicion[1])*scale+shift_y))
self.rotacion = int(rotacion)
def estaAca(self, pos):
"""Devuelve True si la coordenada pos esta en la zona"""
if pos[0] < XMAPAMAX*scale+shift_x:
try:
colorAca = self.mapa.get_at((int(pos[0]-shift_x),
int(pos[1]-shift_y)))
except: # probablemente click fuera de la imagen
return False
if colorAca[0] == self.claveColor:
return True
else:
return False
else:
return False
def mostrarNombre(self, pantalla, fuente, color, flipAhora):
"""Escribe el nombre de la zona en su posicion"""
text = fuente.render(self.nombre, 1, color)
textrot = pygame.transform.rotate(text, self.rotacion)
textrect = textrot.get_rect()
textrect.center = (self.posicion[0], self.posicion[1])
pantalla.blit(textrot, textrect)
if flipAhora:
pygame.display.flip()
class Nivel():
"""Clase para definir los niveles del juego.
Cada nivel tiene un dibujo inicial, los elementos pueden estar
etiquetados con el nombre o no, y un conjunto de preguntas.
"""
def __init__(self, nombre):
self.nombre = nombre
self.dibujoInicial = list()
self.nombreInicial = list()
self.preguntas = list()
self.indicePreguntaActual = 0
self.elementosActivos = list()
def prepararPreguntas(self):
"""Este metodo sirve para preparar la lista de preguntas al azar."""
random.shuffle(self.preguntas)
def siguientePregunta(self, listaSufijos, listaPrefijos):
"""Prepara el texto de la pregunta siguiente"""
self.preguntaActual = self.preguntas[self.indicePreguntaActual]
self.sufijoActual = random.randint(1, len(listaSufijos))-1
self.prefijoActual = random.randint(1, len(listaPrefijos))-1
lineas = listaPrefijos[self.prefijoActual].split("\n")
lineas.extend(self.preguntaActual[0].split("\n"))
lineas.extend(listaSufijos[self.sufijoActual].split("\n"))
self.indicePreguntaActual = self.indicePreguntaActual+1
if self.indicePreguntaActual == len(self.preguntas):
self.indicePreguntaActual = 0
return lineas
def devolverAyuda(self):
"""Devuelve la linea de ayuda"""
self.preguntaActual = self.preguntas[self.indicePreguntaActual-1]
return self.preguntaActual[3].split("\n")
class Conozco():
"""Clase principal del juego.
"""
def mostrarTexto(self, texto, fuente, posicion, color):
"""Muestra texto en una determinada posicion"""
text = fuente.render(texto, 1, color)
textrect = text.get_rect()
textrect.center = posicion
self.pantalla.blit(text, textrect)
def loadInfo(self):
"""Carga las imagenes y los datos de cada pais"""
r_path = os.path.join(self.camino_datos, self.directorio + '.py')
a_path = os.path.abspath(r_path)
f = None
try:
f = imp.load_source(self.directorio, a_path)
except:
print(_('Cannot open %s') % self.directorio)
if f:
lugares = []
if hasattr(f, 'CAPITALS'):
lugares = lugares + f.CAPITALS
if hasattr(f, 'CITIES'):
lugares = lugares + f.CITIES
if hasattr(f, 'HILLS'):
lugares = lugares + f.HILLS
self.listaLugares = list()
for c in lugares:
nombreLugar = c[0]
posx = c[1]
posy = c[2]
tipo = c[3]
incx = c[4]
incy = c[5]
if tipo == 0:
simbolo = self.simboloCapitalN
elif tipo == 1:
simbolo = self.simboloCapitalD
elif tipo == 2:
simbolo = self.simboloCiudad
elif tipo == 5:
simbolo = self.simboloCerro
else:
simbolo = self.simboloCiudad
nuevoLugar = Punto(nombreLugar, tipo, simbolo,
(posx, posy), (incx, incy))
self.listaLugares.append(nuevoLugar)
if hasattr(f, 'STATES'):
self.deptos = self.cargarImagen("deptos.png")
self.deptosLineas = self.cargarImagen("deptosLineas.png")
self.listaDeptos = list()
for d in f.STATES:
nombreDepto = d[0]
claveColor = d[1]
posx = d[2]
posy = d[3]
rotacion = d[4]
nuevoDepto = Zona(self.deptos, nombreDepto,
claveColor, 1, (posx, posy), rotacion)
self.listaDeptos.append(nuevoDepto)
if hasattr(f, 'CUCHILLAS'):
self.cuchillas = self.cargarImagen("cuchillas.png")
self.cuchillasDetectar = self.cargarImagen(
"cuchillasDetectar.png")
self.listaCuchillas = list()
for c in f.CUCHILLAS:
nombreCuchilla = c[0]
claveColor = c[1]
posx = c[2]
posy = c[3]
rotacion = c[4]
nuevaCuchilla = Zona(self.cuchillasDetectar, nombreCuchilla,
claveColor, 4, (posx, posy), rotacion)
self.listaCuchillas.append(nuevaCuchilla)
if hasattr(f, 'RIVERS'):
self.rios = self.cargarImagen("rios.png")
self.riosDetectar = self.cargarImagen("riosDetectar.png")
self.listaRios = list()
for r in f.RIVERS:
nombreRio = r[0]
claveColor = r[1]
posx = r[2]
posy = r[3]
rotacion = r[4]
nuevoRio = Zona(self.riosDetectar, nombreRio,
claveColor, 3, (posx, posy), rotacion)
self.listaRios.append(nuevoRio)
if hasattr(f, 'ROUTES'):
self.rutas = self.cargarImagen("rutas.png")
self.rutasDetectar = self.cargarImagen("rutasDetectar.png")
self.listaRutas = list()
for r in f.ROUTES:
nombreRuta = r[0]
claveColor = r[1]
posx = r[2]
posy = r[3]
rotacion = r[4]
nuevaRuta = Zona(self.rutasDetectar, nombreRuta,
claveColor, 6, (posx, posy), rotacion)
self.listaRutas.append(nuevaRuta)
self.lista_estadisticas = list()
if hasattr(f, 'STATS'):
for e in f.STATS:
p1 = e[0]
p2 = e[1]
self.lista_estadisticas.append((p1, p2))
def cargarListaDirectorios(self):
"""Carga la lista de directorios con los distintos mapas"""
self.listaDirectorios = list()
self.listaNombreDirectorios = list()
listaTemp = os.listdir(CAMINORECURSOS)
listaTemp.sort()
for d in listaTemp:
if not (d == 'comun'):
r_path = os.path.join(CAMINORECURSOS, d, 'datos', d + '.py')
a_path = os.path.abspath(r_path)
f = None
try:
f = imp.load_source(d, a_path)
except:
print(_('Cannot open %s') % d)
if hasattr(f, 'NAME'):
name = f.NAME
self.listaNombreDirectorios.append(name)
self.listaDirectorios.append(d)
def loadCommons(self):
self.listaPrefijos = list()
self.listaSufijos = list()
self.listaCorrecto = list()
self.listaMal = list()
self.listaDespedidasB = list()
self.listaDespedidasM = list()
self.listaPresentacion = list()
self.listaCreditos = list()
r_path = os.path.join(CAMINORECURSOS, CAMINOCOMUN,
'datos', 'commons.py')
a_path = os.path.abspath(r_path)
f = None
try:
f = imp.load_source('commons', a_path)
except:
print(_('Cannot open %s') % 'commons')
if f:
if hasattr(f, 'ACTIVITY_NAME'):
e = f.ACTIVITY_NAME
self.activity_name = e
if hasattr(f, 'PREFIX'):
for e in f.PREFIX:
e1 = e
self.listaPrefijos.append(e1)
if hasattr(f, 'SUFIX'):
for e in f.SUFIX:
e1 = e
self.listaSufijos.append(e1)
if hasattr(f, 'CORRECT'):
for e in f.CORRECT:
e1 = e
self.listaCorrecto.append(e1)
if hasattr(f, 'WRONG'):
for e in f.WRONG:
e1 = e
self.listaMal.append(e1)
if hasattr(f, 'BYE_C'):
for e in f.BYE_C:
e1 = e
self.listaDespedidasB.append(e1)
if hasattr(f, 'BYE_W'):
for e in f.BYE_W:
e1 = e
self.listaDespedidasM.append(e1)
if hasattr(f, 'PRESENTATION'):
for e in f.PRESENTATION:
e1 = e
self.listaPresentacion.append(e1)
if hasattr(f, 'CREDITS'):
for e in f.CREDITS:
e1 = e
self.listaCreditos.append(e1)
self.numeroSufijos = len(self.listaSufijos)
self.numeroPrefijos = len(self.listaPrefijos)
self.numeroCorrecto = len(self.listaCorrecto)
self.numeroMal = len(self.listaMal)
self.numeroDespedidasB = len(self.listaDespedidasB)
self.numeroDespedidasM = len(self.listaDespedidasM)
def cargarNiveles(self):
"""Carga los niveles del archivo de configuracion"""
self.listaNiveles = list()
r_path = os.path.join(self.camino_datos, ARCHIVONIVELES + '.py')
a_path = os.path.abspath(r_path)
f = None
try:
f = imp.load_source(ARCHIVONIVELES, a_path)
except:
print(_('Cannot open %s') % ARCHIVONIVELES)
if hasattr(f, 'LEVELS'):
for ln in f.LEVELS:
index = ln[0]
nombreNivel = str(ln[1])
nuevoNivel = Nivel(nombreNivel)
listaDibujos = ln[2]
for i in listaDibujos:
nuevoNivel.dibujoInicial.append(i.strip())
listaNombres = ln[3]
for i in listaNombres:
nuevoNivel.nombreInicial.append(i.strip())
listpreguntas = ln[4]
if (index == 1):
for i in listpreguntas:
texto = i[0]
tipo = i[1]
respuesta = i[2]
ayuda = i[3]
respuesta = str(i[2])
ayuda = str(i[3])
nuevoNivel.preguntas.append(
(texto, tipo, respuesta, ayuda))
else:
for i in listpreguntas:
respuesta = i[0]
ayuda = i[1]
if (index == 2):
tipo = 2
texto = _('the city of\n%s') % respuesta
elif (index == 7):
tipo = 1
texto = _('the department of\n%s') % respuesta
elif (index == 8):
tipo = 1
texto = _('the province of\n%s') % respuesta
elif (index == 9):
tipo = 1
texto = _('the district of\n%s') % respuesta
elif (index == 10):
tipo = 1
texto = _('the state of\n%s') % respuesta
elif (index == 11):
tipo = 1
texto = _('the region of\n%s') % respuesta
elif (index == 12):
tipo = 1
texto = _('the parish of\n%s') % respuesta
elif (index == 14):
tipo = 1
texto = _('the taluka of\n%s') % respuesta
elif (index == 6):
tipo = 1
texto = _('the municipality of\n%s') % respuesta
elif (index == 4):
tipo = 3
texto = _('the %s') % respuesta
elif (index == 5):
tipo = 6
texto = _('the %(route)s') % {'route': respuesta}
nuevoNivel.preguntas.append(
(texto, tipo, respuesta, ayuda))
self.listaNiveles.append(nuevoNivel)
self.indiceNivelActual = 0
self.numeroNiveles = len(self.listaNiveles)
def cargarExploraciones(self):
"""Carga los niveles de exploracion del archivo de configuracion"""
self.listaExploraciones = list()
r_path = os.path.join(self.camino_datos, ARCHIVOEXPLORACIONES + '.py')
a_path = os.path.abspath(r_path)
f = None
try:
f = imp.load_source(ARCHIVOEXPLORACIONES, a_path)
except:
print(_('Cannot open %s') % ARCHIVOEXPLORACIONES)
if hasattr(f, 'EXPLORATIONS'):
for e in f.EXPLORATIONS:
nombreNivel = e[0]
nuevoNivel = Nivel(nombreNivel)
listaDibujos = e[1]
for i in listaDibujos:
nuevoNivel.dibujoInicial.append(i.strip())
listaNombres = e[2]
for i in listaNombres:
nuevoNivel.nombreInicial.append(i.strip())
listaNombres = e[3]
for i in listaNombres:
nuevoNivel.elementosActivos.append(i.strip())
self.listaExploraciones.append(nuevoNivel)
self.numeroExploraciones = len(self.listaExploraciones)
def pantallaAcercaDe(self):
"""Pantalla con los datos del juego, creditos, etc"""
self.pantallaTemp = pygame.Surface(
(self.anchoPantalla, self.altoPantalla))
self.pantallaTemp.blit(self.pantalla, (0, 0))
self.pantalla.fill(COLOR_FONDO)
self.pantalla.blit(self.terron,
(int(20*scale+shift_x),
int(20*scale+shift_y)))
self.pantalla.blit(self.jp1,
(int(925*scale+shift_x),
int(468*scale+shift_y)))
self.mostrarTexto(_("About %s") % self.activity_name,
self.fuente40,
(int(600*scale+shift_x),
int(100*scale+shift_y)),
COLOR_ACT_NAME)
yLinea = int(200*scale+shift_y)
for linea in self.listaCreditos:
self.mostrarTexto(linea.strip(),
self.fuente32,
(int(600*scale+shift_x), yLinea),
COLOR_CREDITS)
yLinea = yLinea + int(40*scale)
self.mostrarTexto(_("Press any key to return"),
self.fuente32,
(int(600*scale+shift_x),
int(800*scale+shift_y)),
COLOR_SKIP)
pygame.display.flip()
while 1:
clock.tick(20)
if gtk_present:
while Gtk.events_pending():
Gtk.main_iteration()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN or \
event.type == pygame.MOUSEBUTTONDOWN:
if self.sound:
self.click.play()
self.pantalla.blit(self.pantallaTemp, (0, 0))
pygame.display.flip()
return
elif event.type == pygame.QUIT:
if self.sound:
self.click.play()
self.save_stats()
return 1
elif event.type == EVENTOREFRESCO:
pygame.display.flip()
def pantallaStats(self):
"""Pantalla con los datos del juego, creditos, etc"""
self.pantallaTemp = pygame.Surface(
(self.anchoPantalla, self.altoPantalla))
self.pantallaTemp.blit(self.pantalla, (0, 0))
self.pantalla.fill(COLOR_FONDO)
self.pantalla.blit(self.jp1,
(int(925*scale+shift_x),
int(468*scale+shift_y)))
msg = _("Stats of %s") % self.activity_name
self.mostrarTexto(msg,
self.fuente40,
(int(600*scale+shift_x),
int(100*scale+shift_y)),
COLOR_ACT_NAME)
msg = _('Total score: %s') % self._score
self.mostrarTexto(msg,
self.fuente32,
(int(400*scale+shift_x),
int(300*scale+shift_y)),
COLOR_STAT_N)
msg = _('Game average score: %s') % self._average
self.mostrarTexto(msg,
self.fuente32,
(int(400*scale+shift_x),
int(350*scale+shift_y)),
COLOR_STAT_N)
msg = _('Times using Explore Mode: %s') % self._explore_times
self.mostrarTexto(msg,
self.fuente32,
(int(400*scale+shift_x),
int(400*scale+shift_y)),
COLOR_STAT_N)
msg = _('Places Explored: %s') % self._explore_places
self.mostrarTexto(msg,
self.fuente32,
(int(400*scale+shift_x),
int(450*scale+shift_y)),
COLOR_STAT_N)
msg = _('Times using Game Mode: %s') % self._game_times
self.mostrarTexto(msg,
self.fuente32,
(int(400*scale+shift_x),
int(500*scale+shift_y)),
COLOR_STAT_N)
t = int(time.time() - self._init_time) / 60
t = t + self._time
msg = _('Total time: %s minutes') % t
self.mostrarTexto(msg,
self.fuente32,
(int(400*scale+shift_x),
int(550*scale+shift_y)),
COLOR_STAT_N)
self.mostrarTexto(_("Press any key to return"),
self.fuente32,
(int(600*scale+shift_x),
int(800*scale+shift_y)),
COLOR_SKIP)
pygame.display.flip()
while 1:
clock.tick(20)
if gtk_present:
while Gtk.events_pending():
Gtk.main_iteration()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN or \
event.type == pygame.MOUSEBUTTONDOWN:
if self.sound:
self.click.play()
self.pantalla.blit(self.pantallaTemp, (0, 0))
pygame.display.flip()
return
elif event.type == pygame.QUIT:
if self.sound:
self.click.play()
self.save_stats()
return 1
elif event.type == EVENTOREFRESCO:
pygame.display.flip()
def pantallaInicial(self):
"""Pantalla con el menu principal del juego"""
self.pantalla.fill(COLOR_FONDO)
self.mostrarTexto(self.activity_name,
self.fuente60,
(int(600*scale+shift_x),
int(80*scale+shift_y)),
COLOR_ACT_NAME)
self.mostrarTexto(_("You have chosen the map ") +
self.listaNombreDirectorios
[self.indiceDirectorioActual],
self.fuente40,
(int(600*scale+shift_x), int(140*scale+shift_y)),
COLOR_OPTION_T)
self.mostrarTexto(_("Play"),
self.fuente60,
(int(300*scale+shift_x), int(220*scale+shift_y)),
COLOR_OPTION_T)
yLista = int(300*scale+shift_y)
for n in self.listaNiveles:
self.pantalla.fill(COLOR_OPTION_B,
(int(10*scale+shift_x),
yLista-int(24*scale),
int(590*scale),
int(48*scale)))
self.mostrarTexto(n.nombre,
self.fuente40,
(int(300*scale+shift_x), yLista),
COLOR_OPTION_T)
yLista += int(50*scale)
self.mostrarTexto(_("Explore"),
self.fuente60,
(int(900*scale+shift_x), int(220*scale+shift_y)),
COLOR_NEXT)
yLista = int(300*scale+shift_y)
for n in self.listaExploraciones:
self.pantalla.fill(COLOR_OPTION_B,
(int(610*scale+shift_x),
yLista-int(24*scale),
int(590*scale),
int(48*scale)))
self.mostrarTexto(n.nombre,
self.fuente40,
(int(900*scale+shift_x), yLista),
COLOR_NEXT)
yLista += int(50*scale)
# about button
self.pantalla.fill(COLOR_BUTTON_B,
(int(20*scale+shift_x), int(801*scale+shift_y),
int(370*scale), int(48*scale)))
self.mostrarTexto(_("About this game"),
self.fuente40,
(int(205*scale+shift_x), int(825*scale+shift_y)),
COLOR_BUTTON_T)
# stats button
self.pantalla.fill(COLOR_BUTTON_B,
(int(420*scale+shift_x), int(801*scale+shift_y),
int(370*scale), int(48*scale)))
self.mostrarTexto(_("Stats"),
self.fuente40,
(int(605*scale+shift_x), int(825*scale+shift_y)),
COLOR_BUTTON_T)
# return button
self.pantalla.fill(COLOR_BUTTON_B,
(int(820*scale+shift_x), int(801*scale+shift_y),
int(370*scale), int(48*scale)))
self.mostrarTexto(_("Return"),
self.fuente40,
(int(1005*scale+shift_x), int(825*scale+shift_y)),
COLOR_BUTTON_T)
pygame.display.flip()
while 1:
clock.tick(20)
if gtk_present:
while Gtk.events_pending():
Gtk.main_iteration()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == 27: # escape: volver
if self.sound:
self.click.play()
self.elegir_directorio = True
return
elif event.type == pygame.QUIT:
if self.sound:
self.click.play()
self.save_stats()
return 1
elif event.type == pygame.MOUSEBUTTONDOWN:
if self.sound:
self.click.play()
pos = event.pos
# zona de opciones
if pos[1] < 800*scale+shift_y:
if pos[1] > 275*scale + shift_y:
if pos[0] < 600*scale + shift_x: # primera columna
if pos[1] < 275*scale + shift_y + \
len(self.listaNiveles)*50*scale: # nivel
self.indiceNivelActual = \
int((pos[1]-int(275*scale+shift_y)) //
int(50*scale))
self.jugar = True
return
else: # segunda columna
if pos[1] < 275*scale + shift_y +\
len(self.listaExploraciones)*50*scale:
# nivel de exploracion
self.indiceNivelActual = \
int((pos[1]-int(275*scale+shift_y)) //
int(50*scale))
self.jugar = False
return
# buttons zone
else:
if pos[1] < 850*scale + shift_y:
if pos[0] > 20*scale+shift_x and \
pos[0] < 390*scale+shift_x:
if self.pantallaAcercaDe() == 1:
return # acerca
elif pos[0] > 420*scale+shift_x and \
pos[0] < 790*scale+shift_x:
if self.pantallaStats() == 1:
return # stats
elif pos[0] > 820*scale+shift_x and \
pos[0] < 1190*scale+shift_x:
self.elegir_directorio = True
return
elif event.type == EVENTOREFRESCO:
pygame.display.flip()
def pantallaDirectorios(self):
"""Pantalla con el menu de directorios"""
self.pantalla.fill(COLOR_FONDO)
self.mostrarTexto(self.activity_name,
self.fuente60,
(int(600*scale+shift_x), int(80*scale+shift_y)),
COLOR_ACT_NAME)
self.mostrarTexto(_("Choose the map to use"),
self.fuente40,
(int(600*scale+shift_x), int(140*scale+shift_y)),
COLOR_OPTION_T)
nDirectorios = len(self.listaNombreDirectorios)
paginaDirectorios = self.paginaDir
while 1:
if gtk_present:
while Gtk.events_pending():
Gtk.main_iteration()
yLista = int(200*scale+shift_y)
self.pantalla.fill(COLOR_FONDO,
(int(shift_x), yLista-int(24*scale),
int(1200*scale), int(600*scale)))
if paginaDirectorios == 0:
paginaAnteriorActiva = False
else:
paginaAnteriorActiva = True
paginaSiguienteActiva = False
if paginaAnteriorActiva:
self.pantalla.fill(COLOR_OPTION_B,
(int(10*scale+shift_x), yLista-int(24*scale),
int(590*scale), int(48*scale)))
self.mostrarTexto("<<< " + _("Previous page"),
self.fuente40,
(int(300*scale+shift_x), yLista),
COLOR_NEXT)
yLista += int(50*scale)
indiceDir = paginaDirectorios * 20
terminar = False
while not terminar:
self.pantalla.fill(COLOR_OPTION_B,
(int(10*scale+shift_x), yLista-int(24*scale),
int(590*scale), int(48*scale)))
self.mostrarTexto(self.listaNombreDirectorios[indiceDir],
self.fuente40,
(int(300*scale+shift_x), yLista),
COLOR_OPTION_T)
yLista += int(50*scale)
indiceDir = indiceDir + 1
if indiceDir == nDirectorios or \
indiceDir == paginaDirectorios * 20 + 10:
terminar = True
if indiceDir == paginaDirectorios * 20 + 10 and \
not indiceDir == nDirectorios:
nDirectoriosCol1 = 10
yLista = int(250*scale+shift_y)
terminar = False
while not terminar:
self.pantalla.fill(COLOR_OPTION_B,
(int(610*scale+shift_x),
yLista-int(24*scale),
int(590*scale), int(48*scale)))
self.mostrarTexto(self.listaNombreDirectorios[indiceDir],
self.fuente40,
(int(900*scale+shift_x), yLista),
COLOR_OPTION_T)
yLista += int(50*scale)
indiceDir = indiceDir + 1
if indiceDir == nDirectorios or \
indiceDir == paginaDirectorios * 20 + 20:
terminar = True
if indiceDir == paginaDirectorios * 20 + 20:
if indiceDir < nDirectorios:
self.pantalla.fill(COLOR_OPTION_B,
(int(610*scale+shift_x),
yLista-int(24*scale),
int(590*scale), int(48*scale)))
self.mostrarTexto(_("Next page") + " >>>",
self.fuente40,
(int(900*scale+shift_x), yLista),
COLOR_NEXT)
paginaSiguienteActiva = True
nDirectoriosCol2 = 10
else:
nDirectoriosCol2 = indiceDir - paginaDirectorios * 20 - 10
else:
nDirectoriosCol1 = indiceDir - paginaDirectorios * 20
nDirectoriosCol2 = 0
# about button
self.pantalla.fill(COLOR_BUTTON_B,
(int(20*scale+shift_x), int(801*scale+shift_y),
int(370*scale), int(48*scale)))
self.mostrarTexto(_("About this game"),
self.fuente40,
(int(205*scale+shift_x), int(825*scale+shift_y)),
(100, 200, 100))
# stats button
self.pantalla.fill(COLOR_BUTTON_B,
(int(420*scale+shift_x), int(801*scale+shift_y),
int(370*scale), int(48*scale)))
self.mostrarTexto(_("Stats"),
self.fuente40,
(int(605*scale+shift_x), int(825*scale+shift_y)),
(100, 200, 100))
# exit button
self.pantalla.fill(COLOR_BUTTON_B,
(int(820*scale+shift_x), int(801*scale+shift_y),
int(370*scale), int(48*scale)))
self.mostrarTexto(_("Exit"),
self.fuente40,
(int(1005*scale+shift_x), int(825*scale+shift_y)),
(100, 200, 100))
pygame.display.flip()
cambiarPagina = False
while not cambiarPagina:
clock.tick(20)
if gtk_present:
while Gtk.events_pending():
Gtk.main_iteration()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == 27: # escape: salir
if self.sound:
self.click.play()
self.save_stats()
if self.parent is not None:
self.parent.close(skip_save=True)
return 1
elif event.type == pygame.QUIT:
if self.sound:
self.click.play()
self.save_stats()
return 1
elif event.type == pygame.MOUSEBUTTONDOWN:
if self.sound:
self.click.play()
pos = event.pos
# zona de opciones
if pos[1] < 800*scale+shift_y:
if pos[1] > 175*scale+shift_y:
if pos[0] < 600*scale+shift_x: # primera columna
if pos[1] < 175*scale + shift_y + \
(nDirectoriosCol1+1)*50*scale: # mapa
self.indiceDirectorioActual = \
int((pos[1]-int(175*scale+shift_y)) //
int(50*scale)) - 1 + \
paginaDirectorios*20
if self.indiceDirectorioActual == \
paginaDirectorios*20-1 and \
paginaAnteriorActiva: # pag. ant.
paginaDirectorios = paginaDirectorios-1
paginaSiguienteActiva = True
cambiarPagina = True
elif self.indiceDirectorioActual >\
paginaDirectorios*20-1:
self.paginaDir = paginaDirectorios
return
else:
if pos[1] < 225*scale + shift_y + \
nDirectoriosCol2*50*scale or \
(paginaSiguienteActiva and
pos[1] < 775*scale+shift_y): # mapa
self.indiceDirectorioActual = \
int((pos[1]-int(225*scale+shift_y)) //
int(50*scale)) + \
paginaDirectorios*20 + 10
if self.indiceDirectorioActual == \
paginaDirectorios*20+9:
pass # ignorar; espacio vacio
elif self.indiceDirectorioActual == \
paginaDirectorios*20+20 and \
paginaSiguienteActiva: # pag. sig.
paginaDirectorios = \
paginaDirectorios + 1
paginaAnteriorActiva = True
cambiarPagina = True
elif self.indiceDirectorioActual <\
paginaDirectorios*20+20:
self.paginaDir = paginaDirectorios