Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Main.py
blob: 042d318fe2edb563cac48b397601fe8c0f50b638 (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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#   Main.py por:
#   Flavio Danesse <fdanesse@gmail.com>
#   CeibalJAM! - Uruguay

# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import pygame
import sys
import threading
import random
import gc
import gtk

from pygame.locals import *

gc.enable()

import BiblioJAM
from BiblioJAM.JAMButton import JAMButton
from BiblioJAM.JAMLabel import JAMLabel
from BiblioJAM.JAMDialog import JAMDialog
import BiblioJAM.JAMGlobals as JAMG

import Globals as VG
from Cria_Bichos_Main import Cria_Bichos_Main, Ooteca
from Archivos_y_Directorios import Archivos_y_Directorios
from Bicho import Bicho

def Traduce_posiciones(VA, VH):
    eventos= pygame.event.get(pygame.MOUSEBUTTONDOWN)
    for event in eventos:
        x, y = event.pos
        xx= x/VA
        yy= y/VH
        event_pos= (xx, yy)
    for event in eventos:
        evt = pygame.event.Event(pygame.MOUSEBUTTONDOWN, pos= event_pos, button=event.button)
        pygame.event.post(evt)
        
    eventos= pygame.event.get(pygame.MOUSEMOTION)
    for event in eventos:
        x, y = event.pos
        xx= x/VA
        yy= y/VH
        event_pos= (xx, yy)
    for event in eventos:
        evt = pygame.event.Event(pygame.MOUSEMOTION, pos= event_pos, rel=event.rel, buttons=event.buttons)
        pygame.event.post(evt)
        
class Main():
    def __init__(self, res= None):
        self.resolucionreal= res
        # Variables para JAMatrix
        self.ventana= None
        self.name= "CucaraSims"
        
        # Variables del Juego
        self.fondo= None
        self.reloj= None
        
        # Escalado
        self.ventana_real= None
        self.VA= None
        self.VH= None
        
        self.sonido_select = None
        self.sprites = pygame.sprite.OrderedUpdates()
        self.Archivos_y_Directorios = None
        self.base_de_datos = None
        self.creditos = None
        self.dialog_cerrar = None
        self.menu = None
        self.mensaje = None
        self.Cria_Bichos= None
        
        self.interval = 0
        self.nivel = None
        
        self.Juegos_guardados = None
        
        self.preset()
        self.load()
        self.run()
        
    def run(self):
        self.nivel = "Menu"
        self.sprites= self.menu
        self.RunMenu()
        
    def RunMenu(self):
        pygame.mouse.set_visible(True)
        self.Cria_Bichos.set_musica()
        self.fondo= self.get_fondo2()
        self.ventana.blit(self.fondo, (0,0))
        self.ventana_real.blit(pygame.transform.scale(self.ventana, self.resolucionreal), (0,0))
        pygame.display.update()
        
        while self.nivel == "Menu":
            self.reloj.tick(35)
            while gtk.events_pending():
                gtk.main_iteration(False)
            Traduce_posiciones(self.VA, self.VH)
            if self.mensaje: self.pause_menu()
            self.sprites.clear(self.ventana, self.fondo)
            self.sprites.update()
            self.handle_event()
            pygame.event.clear()
            self.sprites.draw(self.ventana)
            self.ventana_real.blit(pygame.transform.scale(self.ventana, self.resolucionreal), (0,0))
            pygame.display.update()
            
        if self.nivel == "CucaraSims":
            self.Cria_Bichos.Run()
        if self.nivel == "Creditos":
            self.RunCreditos()
            
    def handle_event(self):
        if pygame.event.get(pygame.VIDEORESIZE): print "OK"
        for event in pygame.event.get(pygame.KEYDOWN):
            tecla= event.key
            if tecla== pygame.K_ESCAPE:
                if self.nivel == "Menu" and not self.mensaje:
                    self.selecciona_mensaje_cerrar(None)
                elif self.nivel == "Creditos":
                    self.nivel = "Menu"
                elif self.mensaje:
                    self.deselecciona_mensaje(None)
                    
    def pause_menu(self):
        self.ventana.blit(self.fondo, (0,0))
        while self.mensaje.sprites():
            self.reloj.tick(35)
            while gtk.events_pending():
                gtk.main_iteration(False)
            Traduce_posiciones(self.VA, self.VH)
            self.mensaje.clear(self.ventana, self.fondo)
            self.mensaje.update()
            self.handle_event()
            pygame.event.clear()
            self.mensaje.draw(self.ventana)
            self.ventana_real.blit(pygame.transform.scale(self.ventana, self.resolucionreal), (0,0))
            pygame.display.update()
            
    def deselecciona_mensaje(self, button= None):
        self.mensaje= pygame.sprite.OrderedUpdates()
        
    def selecciona_mensaje_cerrar(self, button= None):
        self.mensaje= self.dialog_cerrar
        
    def selecciona_menu_cargar(self, button= None):
        self.deselecciona_mensaje(None)
        self.Juegos_guardados= Juegos_Guardados(self.Archivos_y_Directorios, self)
        self.mensaje= self.Juegos_guardados
        
    def cargar_juego(self, datos):
    # Carga el juegon Juego guardado seleccionado
        # poner todo a cero
        self.Cria_Bichos.Bichos.empty()
        self.Cria_Bichos.cadaveres.empty()
        self.Cria_Bichos.alimento.empty()
        self.Cria_Bichos.ootecas.empty()
        self.Cria_Bichos.agua.empty()
        self.Cria_Bichos.ficha = pygame.sprite.OrderedUpdates()
        self.Cria_Bichos.puntos = 0
        self.Cria_Bichos.tiempo_de_juego = 0
        self.Cria_Bichos.horas = 0
        self.Cria_Bichos.dias = 0
        self.Cria_Bichos.anios = 0
        self.Cria_Bichos.machos, self.Cria_Bichos.hembras = 0,0
        
        self.Cria_Bichos.secuencia_muda = 0
        self.Cria_Bichos.reproduccion = 0
        self.Cria_Bichos.nacimientos = 0
        self.Cria_Bichos.muertes = 0
        self.Cria_Bichos.plaga = 0
        
        # recuperar datos
        (base, datos_juego, cucas, ootecas) = datos # return (base, datos_juego, cucas, Ootecas)
        
        self.base_de_datos = base
        
        # datos generales del juego
        # datos 0 Tabla Juego [anios, dias, horas, puntos]
        self.Cria_Bichos.anios = int(datos_juego[1])
        self.Cria_Bichos.dias = int(datos_juego[2])
        self.Cria_Bichos.horas = int(datos_juego[3])
        self.Cria_Bichos.puntos = int(datos_juego[4])
        
        for cuca in cucas:
        # datos de cucarachas
        # datos 1 Tabla Cucas [sexo, anios, dias, horas, hambre, sed]
            contador, sexo, anios, dias, horas, hambre, sed = cuca
            tipo = None
            while tipo != sexo:
                bicho = Bicho(self.Cria_Bichos)
                tipo = bicho.sexo
            self.Cria_Bichos.Bichos.add(bicho)
            
            if bicho.sexo == "M":
                self.Cria_Bichos.machos += 1
            elif bicho.sexo == "F":
                self.Cria_Bichos.hembras += 1
                
            bicho.anios = int(anios)
            bicho.dias = int(dias)
            bicho.horas = int(horas)
            bicho.hambre = int(hambre)
            bicho.sed = int(sed)
            
            # escalar
            for dia in range (0, bicho.dias):
            # desde dia cero hasta los dias que tiene el bicho
                if dia == bicho.control_mudas: # bicho.control_mudas es una lista de dias de mudas
                
                    indice = bicho.dias_mudas.index(dia)
                    bicho.set_muda(escala=bicho.escalas_mudas[indice]) # se obtiene el tamaño
                    bicho.velocidad += int(bicho.velocidad/3)
                    
                    if indice+1 < len(bicho.dias_mudas):
                        bicho.control_mudas = bicho.dias_mudas[indice+1]
                    else:
                        bicho.control_mudas = bicho.dias_mudas[0]
                        
            print "CUCA: ", bicho.anios, bicho.dias, bicho.horas, bicho.hambre, bicho.sed
            
        if self.Cria_Bichos.hembras + self.Cria_Bichos.machos != len(cucas):
            print "HAY INCOHERENCIAS DE CANTIDAD DE BICHOS ALMACENADOS/CARGADOS"
            
        for ooteca in ootecas:
        # datos de cucarachas
        # datos 2 Tabla ootecas [dias, horas, huevos]
            contador, dias, horas, huevos = ooteca
            ooteca = Ooteca(self.Cria_Bichos, posicion=(0,0))
            self.Cria_Bichos.ootecas.add(ooteca)
            ooteca.dias = int(dias)
            ooteca.horas = int(horas)
            ooteca.huevos = int(huevos)
            print "ooteca: ", ooteca.dias, ooteca.horas, ooteca.huevos
            
        self.deselecciona_mensaje(None)
        self.nivel = "CucaraSims"
        
    def get_new_game(self, button):
        self.base_de_datos= self.Archivos_y_Directorios.CrearBasededatos()
        self.Cria_Bichos.get_nuevo_Juego()
        if self.base_de_datos:
            self.nivel = "CucaraSims"
        else:
            print "Error al crear la base de datos"
        #self.nivel = "CucaraSims"
        
    def RunCreditos(self):
        pygame.mixer.music.load(VG.MUSICA2)
        pygame.mixer.music.play(-1, 0.0)
        self.ventana.blit(self.fondo, (0,0))
        pygame.display.update()
        while self.nivel == "Creditos":
            self.reloj.tick(35)
            while gtk.events_pending():
                gtk.main_iteration(False)
            Traduce_posiciones(self.VA, self.VH)
            self.creditos.clear(self.ventana, self.fondo)
            self.creditos.update()
            self.handle_event()
            pygame.event.clear()
            self.creditos.draw(self.ventana)
            self.ventana_real.blit(pygame.transform.scale(self.ventana, self.resolucionreal), (0,0))
            pygame.display.update()
        if self.nivel == "Menu":
            self.RunMenu()
            
    def get_fondo2(self, tamanio=VG.RESOLUCION):
        superficie = pygame.transform.scale(pygame.image.load(VG.FONDO4), (VG.RESOLUCION))
        return superficie
    
    def get_creditos(self, button):
        self.nivel= "Creditos"
        
    def preset(self):
        pygame.mouse.set_visible(False)
        pygame.display.set_mode( (0,0), pygame.DOUBLEBUF | pygame.FULLSCREEN, 0)
        A, B= VG.RESOLUCION
        self.ventana= pygame.Surface( (A, B), flags=HWSURFACE )
        self.ventana_real= pygame.display.get_surface()
        C, D= (0, 0)
        if not self.resolucionreal:
            C= pygame.display.Info().current_w
            D= pygame.display.Info().current_h
            self.resolucionreal= (C,D)
        else:
            C, D= self.resolucionreal
        self.VA= float(C)/float(A)
        self.VH= float(D)/float(B)
        pygame.display.set_caption("CucaraSims")
        pygame.event.set_blocked([JOYAXISMOTION, JOYBALLMOTION,
            JOYHATMOTION, JOYBUTTONUP, JOYBUTTONDOWN,
            KEYUP, VIDEORESIZE, VIDEOEXPOSE, USEREVENT, QUIT, ACTIVEEVENT])
        pygame.event.set_allowed([MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN, KEYDOWN])
        
    def load(self):
        pygame.mixer.init()
        if not self.Archivos_y_Directorios: self.Archivos_y_Directorios= Archivos_y_Directorios(VG.DIRECTORIO_DATOS)
        if not self.sonido_select: self.sonido_select= JAMG.get_sound_select()
        if not self.reloj: self.reloj= pygame.time.Clock()
        if not self.fondo: self.fondo= self.get_fondo()
        if not self.menu:
            self.menu= Menu()
            self.menu.boton_nuevo.connect(callback= self.get_new_game, sonido_select= self.sonido_select)
            self.menu.boton_cargar.connect(callback= self.selecciona_menu_cargar, sonido_select= self.sonido_select)
            self.menu.boton_creditos.connect(callback= self.get_creditos, sonido_select= self.sonido_select)
            self.menu.boton_salir.connect(callback= self.selecciona_mensaje_cerrar, sonido_select= self.sonido_select)
            
        if not self.creditos: self.creditos= Creditos(self)
        
        if not self.dialog_cerrar:
            a,b,c= JAMG.get_estilo_naranja()
            self.dialog_cerrar= JAMDialog(mensaje= "¿Deseas Salir del Juego?",
                funcion_ok= self.salir, funcion_cancel= self.deselecciona_mensaje)
            self.dialog_cerrar.set_colors_dialog(base= c, bordes= b)
            self.dialog_cerrar.set_colors_buttons(colorbas= a, colorbor= b, colorcara= c)
            
        if not self.Cria_Bichos: self.Cria_Bichos= Cria_Bichos_Main(self)
        
    def get_fondo(self, color=(0,0,0,1), tamanio=VG.RESOLUCION):
        superficie = pygame.Surface( tamanio, flags=HWSURFACE )
        superficie.fill(color)
        return superficie
    
    def salir(self, button):
        pygame.quit()
        sys.exit()
        
class Menu(pygame.sprite.OrderedUpdates):
    def __init__(self):
        pygame.sprite.OrderedUpdates.__init__(self)
        
        separador = 40
        ancho = 500
        alto = 100
        
        a,b,c= JAMG.get_estilo_celeste()
        self.boton_nuevo = JAMButton("Juego Nuevo", None)
        self.boton_cargar = JAMButton("Cargar Juego", None)
        self.boton_creditos = JAMButton("Creditos", None)
        self.boton_salir = JAMButton("Salir", None)
        
        self.boton_nuevo.set_text(tamanio= 50)
        self.boton_cargar.set_text(tamanio= 50)
        self.boton_creditos.set_text(tamanio= 50)
        self.boton_salir.set_text(tamanio= 50)
        
        self.boton_nuevo.set_tamanios(tamanio= (ancho,alto))
        self.boton_cargar.set_tamanios(tamanio= (ancho,alto))
        self.boton_creditos.set_tamanios(tamanio= (ancho,alto))
        self.boton_salir.set_tamanios(tamanio= (ancho,alto))
        
        self.boton_nuevo.set_colores(colorbas= a, colorbor= b, colorcara= c)
        self.boton_cargar.set_colores(colorbas= a, colorbor= b, colorcara= c)
        self.boton_creditos.set_colores(colorbas= a, colorbor= b, colorcara= c)
        self.boton_salir.set_colores(colorbas= a, colorbor= b, colorcara= c)
        
        y = 150
        x = VG.RESOLUCION[0]/2 - self.boton_nuevo.get_tamanio()[0]/2
        self.boton_nuevo.set_posicion(punto=(x,y))
        
        y += self.boton_nuevo.get_tamanio()[1] + separador
        x = VG.RESOLUCION[0]/2 - self.boton_cargar.get_tamanio()[0]/2
        self.boton_cargar.set_posicion(punto=(x,y))
        
        y += self.boton_cargar.get_tamanio()[1] + separador
        x = VG.RESOLUCION[0]/2 - self.boton_creditos.get_tamanio()[0]/2
        self.boton_creditos.set_posicion(punto=(x,y))
        
        y += self.boton_creditos.get_tamanio()[1] + separador
        x = VG.RESOLUCION[0]/2 - self.boton_salir.get_tamanio()[0]/2
        self.boton_salir.set_posicion(punto=(x,y))
        
        self.add(self.boton_nuevo)
        self.add(self.boton_cargar)
        self.add(self.boton_creditos)
        self.add(self.boton_salir)
        
class Creditos(pygame.sprite.OrderedUpdates):
    def __init__(self, main):
        pygame.sprite.OrderedUpdates.__init__(self)
        self.grupo1 = {}
        self.grupo2 = {}
        self.get_sprites()
        self.seleccion = 1
        self.velocidad = 4
        
        self.main= main
        self.cerrar= JAMButton("", None)
        self.cerrar.set_imagen(origen= JAMG.get_icon_exit())
        self.cerrar.set_tamanios(grosorbor= 1, espesor= 1)
        self.cerrar.set_posicion(punto= (VG.RESOLUCION[0] - self.cerrar.get_tamanio()[0], 0) )
        self.cerrar.connect(callback= self.salir, sonido_select= None)
        a,b,c= JAMG.get_estilo_celeste()
        self.cerrar.set_colores(colorbas= a, colorbor= b, colorcara= c)
        self.add(self.cerrar)
        
    def salir(self, button):
        self.main.nivel = "Menu"
        
    def update(self):
        if self.seleccion == 1:
            for num in self.grupo1.keys():
                etiqueta, (x,y) = self.grupo1[num]
                x, y= etiqueta.get_posicion()
                y -= self.velocidad
                etiqueta.set_posicion((x,y))
            if y < -50:
                self.seleccion = 2
                for num in self.grupo1.keys():
                    etiqueta, (x,y) = self.grupo1[num]
                    etiqueta.set_posicion((x,y))
                    
        if self.seleccion == 2:
            for num in self.grupo2.keys():
                etiqueta, (x,y) = self.grupo2[num]
                x, y= etiqueta.get_posicion()
                y -= self.velocidad
                etiqueta.set_posicion((x,y))
            if y < -50:
                self.seleccion = 1
                for num in self.grupo2.keys():
                    etiqueta, (x,y) = self.grupo2[num]
                    etiqueta.set_posicion((x,y))
        self.cerrar.update()
        
    def get_sprites(self):
        Textos1 = ["CucaraSims.",
        "El Sims de las Cucarachas.",
        "Para Aprender Jugando y Jugar Aprendiendo.",
        "Dedicado con Cariño a mis Compañeros Voluntarios de",
        "CeibalJAM!, RAP Ceibal y a Todos los Niños y Jóvenes",
        "del Uruguay y demás comunidades Sugar."]
        
        Textos2 = ["Idea Original, Edición de Audio y Video,",
        "Diseño Gráfico, Desarrollo y Contenidos:",
        "Flavio Danesse - fdanesse@gmail.com",
        "Imágenes e Información: Wikipedia - Wikiespecies",
        "Música: MATI - ARUAL - http://www.jamendo.com"]
        
        color= JAMG.get_celeste1()
        contador= 1
        
        #logo= JAMLabel("")
        #logo.set_imagen(origen= VG.LOGO)
        logo= Logo()
        x, y = VG.RESOLUCION[0]/2 - logo.get_tamanio()[0]/2, VG.RESOLUCION[1]
        logo.set_posicion((x,y))
        self.add(logo)
        self.grupo1[contador]= logo, (x,y)
        
        y += 95
        contador += 1
        # textos1
        for texto in Textos1:
            etiqueta= JAMLabel(texto)
            etiqueta.set_text(tamanio= 40, color= color)
            
            x = VG.RESOLUCION[0]/2 - etiqueta.get_tamanio()[0]/2
            etiqueta.set_posicion((x,y))
            self.add(etiqueta)
            self.grupo1[contador] = etiqueta, (x,y)
            y += 100
            contador += 1
            
        contador = 1
        y = VG.RESOLUCION[1]
        for texto in Textos2:
            etiqueta= JAMLabel(texto)
            etiqueta.set_text(tamanio= 40, color= color)
            x = VG.RESOLUCION[0]/2 - etiqueta.get_tamanio()[0]/2
            etiqueta.set_posicion((x,y))
            self.add(etiqueta)
            self.grupo2[contador] = etiqueta, (x,y)
            y += 100
            contador += 1
            
class Logo(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image= pygame.image.load(VG.LOGO)
        self.rect= self.image.get_rect()
    def get_tamanio(self):
        return (self.rect.w, self.rect.h)
    def set_posicion(self, punto= (0,0)):
        self.rect.x, self.rect.y= punto
    def get_posicion(self, punto= (0,0)):
        return (self.rect.x, self.rect.y)
    
class Juegos_Guardados(pygame.sprite.OrderedUpdates):
    def __init__(self, archivosydirectorios, main):
        pygame.sprite.OrderedUpdates.__init__(self)
        self.juego_base= main
        self.Archivos_y_Directorios= archivosydirectorios
        lista_juegos_guardados= self.Archivos_y_Directorios.get_juegos()
        self.directorio= lista_juegos_guardados[0]	# string
        self.juegos= lista_juegos_guardados[1]		# lista
        
        y = 50
        self.items = []
        w, h= (0,0)
        for juego in self.juegos:
            item= Item_Juego(self.Archivos_y_Directorios, juego, self)
            item.agregate(self)
            if item.etiqueta_juego.get_tamanio()[1] > h: h= item.etiqueta_juego.get_tamanio()[1]
            if item.etiqueta_juego.get_tamanio()[0] > w: w= item.etiqueta_juego.get_tamanio()[0]
            self.items.append(item)
        for item in self.items:
            x= VG.RESOLUCION[0]/2 - w/2
            item.set_posicion(punto= (x, y))
            y+= h+ 30
            
        self.cerrar= JAMButton("", None)
        self.cerrar.set_imagen(origen= JAMG.get_icon_exit())
        self.cerrar.set_tamanios(grosorbor= 1, espesor= 1)
        self.cerrar.set_posicion(punto= (VG.RESOLUCION[0] - self.cerrar.get_tamanio()[0], 0) )
        self.cerrar.connect(callback= self.salir, sonido_select= None)
        a,b,c= JAMG.get_estilo_celeste()
        self.cerrar.set_colores(colorbas= a, colorbor= b, colorcara= c)
        
        self.add(self.cerrar)
        
    def salir(self, button= None):
        self.juego_base.deselecciona_mensaje(None)
        
    def reordenar_juegos(self, item):
        self.items.remove(item)
        #y= 50
        #for item in self.items:
        #	x = VG.RESOLUCION[0]/2 - item.etiqueta_juego.rect.w/2
        #	item.set_posicion(punto= (x, y))
        #	y += item.etiqueta_juego.get_tamanio()[1] + 30
        
class Item_Juego():
    def __init__(self, archivosydirectorios, juego, grupo):
        self.grupo= grupo
        self.Archivos_y_Directorios= archivosydirectorios
        self.juego= juego
        self.separador= 10
        
        a,b,c= JAMG.get_estilo_celeste()
        self.etiqueta_juego= JAMLabel(juego)
        self.etiqueta_juego.set_text(tamanio= 40)
        self.etiqueta_juego.set_text(color= c)
        
        self.boton_borrar= JAMButton("Borrar", None)
        self.boton_borrar.set_text(tamanio= 30)
        self.boton_borrar.set_tamanios(tamanio= (50, self.etiqueta_juego.get_tamanio()[1]), grosorbor= 1, espesor= 1)
        self.boton_borrar.set_colores(colorbas= a, colorbor= b, colorcara= c)
        
        self.boton_load= JAMButton("Cargar", None)
        self.boton_load.set_text(tamanio= 30)
        self.boton_load.set_tamanios(tamanio= (50, self.etiqueta_juego.get_tamanio()[1]), grosorbor= 1, espesor= 1)
        self.boton_load.set_colores(colorbas= a, colorbor= b, colorcara= c)
        
        self.boton_borrar.connect(callback= self.delete_game, sonido_select= None)
        self.boton_load.connect(callback= self.carga_game, sonido_select= None)
        
    def agregate(self, grupo):
        grupo.add(self.etiqueta_juego)
        grupo.add(self.boton_borrar)
        grupo.add(self.boton_load)
        
    def set_posicion(self, punto= (0,0)):
        (x,y)= punto
        self.etiqueta_juego.set_posicion((x,y))
        a= x - self.separador - self.boton_borrar.get_tamanio()[0]
        self.boton_borrar.set_posicion((a,y))
        b= x + self.separador + self.etiqueta_juego.get_tamanio()[0]
        self.boton_load.set_posicion((b,y))
        
    def delete_game(self, button= None):
        self.Archivos_y_Directorios.borrar_tabla(self.juego)
        self.etiqueta_juego.kill()
        self.boton_borrar.kill()
        self.boton_load.kill()
        self.grupo.reordenar_juegos(self)
        return
    
    def carga_game(self, button= None):
        self.grupo.juego_base.cargar_juego(self.Archivos_y_Directorios.Leer_Base_de_Datos(self.juego))