Created
July 1, 2014 00:13
-
-
Save ricardosiri68/affc11e6358923526490 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame,time | |
from pygame.locals import * | |
from configuracion import * | |
from principal import* | |
def LlenarLista(file): #Lleno la lista con cada linea del archivo. | |
lista=[] | |
for linea in file.readlines(): | |
linea=linea[:-1] | |
lista.append(linea) | |
return lista | |
def IngresarNombre(): #Ingresa el nombre del usuario | |
## pygame.init() | |
## visor=pygame.display.set_mode((800,600),0,32) | |
## tamano=30 #Tamano de las letras | |
## color0=(249,94,89) | |
## defaultFont= pygame.font.Font( pygame.font.get_default_font(), tamano) #defino la fuente del dibujo | |
## fila=400 #posicion de fila | |
## columna=300 #posicion de columna | |
salir=False | |
contador=0 | |
max_caracter=10 | |
while not salir: | |
name=str(input("Ingrese un nombre:")) | |
#visor.blit(defaultFont.render(("Ingrese su nombre:"), 3, color0),(fila-50,columna-50)) | |
#name=str(input) | |
#pygame.display.flip() #Refresheo la pantalla | |
if len(name)>max_caracter: | |
#visor.blit(defaultFont.render("Error presione solo puede usar 10 caracteres", 3, color0),(fila-50,columna-50)) | |
print("Error presione solo puede usar 10 caracteres") | |
#pygame.display.flip() #Refresheo la pantalla | |
else: | |
salir=True | |
return name | |
def Interrupcion(inc,UserPoints,NewScore,NewRecord,filePuntos,fileRecords): | |
NewScore.insert(inc,UserPoints) #Insertar el puntaje en esa posicion de la lista | |
UserName=IngresarNombre() #Perdirle el nombre al Usuario que hizo el puntaje | |
NewRecord.insert(inc,UserName) #Insertarlo en la lista de records | |
filePuntos.write(str(UserPoints)+'\n') #Agregar el puntaje al archivo | |
fileRecords.write(UserName+'\n') #Agregar el nombre al archivo | |
return True | |
def DibujarRecords(lnombres,lpuntos,tope): | |
os.environ["SDL_VIDEO_CENTERED"] = "1" | |
pygame.init() | |
while True: | |
visor=pygame.display.set_mode((800,600),0,32) #Preparo el visor | |
tamano=30 #Tamano de las letras | |
color0=(249,94,89) | |
color1=(216,181,17) | |
defaultFont= pygame.font.Font( pygame.font.get_default_font(), tamano) #defino el frente | |
fila=130 #posicion de fila | |
columna=130 #posicion de columna | |
visor.blit(defaultFont.render("Puntos", 3, color0),(fila-50,columna-50)) #Dibujo la palabra Puntos | |
visor.blit(defaultFont.render("Nombre", 3, color0),(fila+230,columna-50)) #Dibujo la palabra Nombre | |
for i in range(tope): #De 0 hasta el tope | |
ren0 = defaultFont.render(str(lpuntos[i]), 3, color1) #Defino el puntaje | |
ren1= defaultFont.render(str(lnombres[i]), 3, color1) #Defino el nombre | |
posicion1=(fila-20,columna) #Posición para los puntos | |
posicion2=(fila+250,columna) #Posicion para los nombres | |
visor.blit(ren0,posicion1) #Dibujo el puntaje | |
visor.blit(ren1,posicion2) #Dibujo el nombre | |
columna=columna+40 #Incremento las columnas para que los nombres aparezcan uno abajo del otro | |
pygame.display.flip() #Refresheo la pantalla | |
for event in pygame.event.get(): #Para salir del evento | |
if event.type==QUIT: | |
pygame.quit() | |
sys.exit() | |
#Recibe los puntos de la partida reciente. | |
def MejoresRecords(UserPoints): | |
NewRecord=[] #Creo una lista de records nueva. | |
NewScore=[] #Creo una lista de puntos nueva. | |
top=10 #Es la cantidad de puntajes que quiero mostrar por pantalla | |
fileRecords=open("records.txt","r+") #Abro archivo de Records | |
filePuntos=open("puntos.txt","r+") #Abro archivo de Puntos | |
records=LlenarLista(fileRecords) #Creo una lista de records | |
puntos=LlenarLista(filePuntos) #Creo una lista de puntos | |
for i in range(len(puntos)): #Transformo mi lista de strings en una de integers | |
NewScore.append(int(puntos[i])) | |
NewScore.sort(reverse=True) #Ordeno la nueva lista de mayor a menor | |
for i in range(len(records)): #Busco que posicion de la lista coincide con el nombre | |
for j in range(len(puntos)): | |
if NewScore[i]==int(puntos[j]): | |
NewRecord.append(records[j]) #Cuando lo encuentro lo agrego a una nueva lista | |
salir=False #Condicion para salir del proximo ciclo. | |
inc=0 #Una variable que utilizo para ir incrementando el indice de mi lista. | |
while not salir: | |
if NewScore[inc]<UserPoints and inc<top: #Si el puntaje que recibo es mayor a alguno de la lista | |
salir=Interrupcion(inc,UserPoints,NewScore,NewRecord,filePuntos,fileRecords) | |
#La interrupcion permite dibujar el ingreso a la pantalla del nuevo nombre y devuelve True cuando termina | |
elif inc==top-1: | |
salir=True | |
else: | |
inc+=1 | |
fileRecords.close() #Cierro el archivo de Records | |
filePuntos.close() #Cierro el archivo de Puntos | |
DibujarRecords(NewRecord,NewScore,top) #Dibuja en pantalla los "top" records | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from collections import namedtuple | |
#Tipo de letras | |
VOCAL = 'aeiou' | |
CONSONANTE = 'bcdfghlmnprstv' | |
DIFICIL = 'jkqwxyz' | |
FLAG = True | |
CORRIMIENTO = 200 | |
TAMANNO_LETRA = 30 | |
ANCHO_COL = TAMANNO_LETRA + 5 | |
ANCHO_FIL = TAMANNO_LETRA + 2 | |
FILAS = 3 | |
COLUMNAS = 10 | |
ANCHO = (COLUMNAS + 20) * ANCHO_COL | |
ALTO = 2 * (FILAS + 4) * ANCHO_FIL | |
PISO = ALTO # -2*FILAS | |
## en segundos | |
TIEMPO_MAX = 20 | |
INTENTOS_INICIALES = 5 | |
# Frames per second, un frame cada 1/FPS segundos | |
FPS_inicial = 8 | |
# Colores | |
COLOR_LETRAS = (20, 200, 20) | |
COLOR_FONDO = (0, 0, 0) | |
COLOR_TEXTO = (200, 200, 200) | |
COLOR_TIEMPO_FINAL = (200, 20, 10) | |
COLOR_RESALTADO = (200, 20, 15) | |
Punto = namedtuple('Punto', 'x y') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from pygame.locals import * | |
from configuracion import * | |
# Input flechas: | |
# | |
# direccion[0] es vertical | |
# direccion[1] es horizontal | |
# 1 | |
# -1 1 | |
# -1 | |
'''def FlechaApretada(key, direccion): | |
if key == K_UP and direccion[0] < 1 : | |
direccion[0] += 1 | |
elif key == K_DOWN and direccion[0] > -1 : | |
direccion[0] -= 1 | |
elif key == K_LEFT and direccion[1] > -1 : | |
direccion[1] -= 1 | |
elif key == K_RIGHT and direccion[1] < 1: | |
direccion[1] += 1 | |
''' | |
def ShowDireccion(direccion): | |
direcciones = { | |
(-1, -1): "Abajo - izquierda", | |
(-1, 0): "Abajo", | |
(-1, 1): "Abajo - derecha", | |
(0, -1): "Izquierda", | |
(0, 0): "<con el cursor> (8 dir)", | |
(0, 1): "Derecha", | |
(1, -1): "Arriba - izquierda", | |
(1, 0): "Arriba", | |
(1, 1): "Arriba - derecha" | |
} | |
direcciones[direccion] | |
''' | |
# Incluye teclas del NumPad | |
def NumeroApretado(key): | |
if key == K_0 or key == K_KP0: | |
return("0") | |
elif key == K_1 or key == K_KP1: | |
return("1") | |
elif key == K_2 or key == K_KP2: | |
return("2") | |
elif key == K_3 or key == K_KP3: | |
return("3") | |
elif key == K_4 or key == K_KP4: | |
return("4") | |
elif key == K_5 or key == K_KP5: | |
return("5") | |
elif key == K_6 or key == K_KP6: | |
return("6") | |
elif key == K_7 or key == K_KP7: | |
return("7") | |
elif key == K_8 or key == K_KP8: | |
return("8") | |
elif key == K_9 or key == K_KP9: | |
return("9") | |
else: | |
return("") | |
def InputNumber(key, number): | |
caracter = NumeroApretado(key) | |
if caracter.isdigit(): | |
number += caracter | |
if key == K_BACKSPACE: | |
number = number[:-1] | |
return number | |
''' | |
def LetraApretada(key): | |
keymaps = { | |
K_a: "a", | |
K_b: "b", | |
K_c: "c", | |
K_d: "d", | |
K_e: "e", | |
K_f: "f", | |
K_g: "g", | |
K_h: "h", | |
K_i: "i", | |
K_j: "j", | |
K_k: "k", | |
K_l: "l", | |
K_m: "m", | |
K_n: "n", | |
K_o: "o", | |
K_p: "p", | |
K_q: "q", | |
K_r: "r", | |
K_s: "s", | |
K_t: "t", | |
K_u: "u", | |
K_v: "v", | |
K_w: "w", | |
K_x: "x", | |
K_y: "y", | |
K_z: "z" | |
} | |
return keypamps.default(key, "") | |
def PrintMatriz(M, filas): | |
''' | |
Esta funcion es opcional, sirve para debugging | |
''' | |
for i in range(filas): | |
print(M[i]) | |
print() | |
def escribirEnPantalla(screen, palabra, posicion, tamano, color): | |
''' | |
Es opcional usar esta funcion | |
''' | |
defaultFont= pygame.font.Font( pygame.font.get_default_font(), tamano) | |
ren = defaultFont.render(palabra, 1, color) | |
screen.blit(ren, posicion) | |
def dibujar(screen, candidata, letras, posiciones, puntos, segundos): | |
defaultFont= pygame.font.Font( pygame.font.get_default_font(), 20) | |
#Linea del piso | |
pygame.draw.line( | |
screen, | |
(255, 255, 255), | |
(0, ALTO - 70), | |
(ANCHO, ALTO - 70), | |
5 | |
) | |
ren1 = defaultFont.render(candidata, 1, COLOR_TEXTO) | |
ren2 = defaultFont.render("Puntos: " + puntos, 1, COLOR_TEXTO) | |
if segundos < 15: | |
ren3 = defaultFont.render( | |
"Tiempo: " + str(int(segundos)), | |
1, | |
COLOR_TIEMPO_FINAL | |
) | |
else: | |
ren3 = defaultFont.render( | |
"Tiempo: " + str(int(segundos)), | |
1, | |
COLOR_TEXTO | |
) | |
for i in range(len(letras)): | |
screen.blit( | |
defaultFont.render( | |
letras[i], | |
1, | |
COLOR_LETRAS | |
), | |
posiciones[i] | |
) | |
screen.blit(ren1, (190, 570)) | |
screen.blit(ren2, (680, 10)) | |
screen.blit(ren3, (10, 100)) | |
def PosicionEnRango(fil, col): | |
return (0 <= fil) and (fil <= FILAS) and (0 <= col) and (col <= COLUMNAS) | |
### "Coordenadas gordas" | |
def dibujarMatriz(screen, MatLetras, puntos, intentos, palabra, fil, col, direccion, ganador, segundos, inputField): | |
defaultFont = pygame.font.Font( | |
pygame.font.get_default_font(), | |
TAMANNO_LETRA | |
) | |
#dibuja grilla | |
bordeDerecha = (COLUMNAS + 0.4) * ANCHO_COL | |
#Dibuja las lineas en el eje Y | |
for i in range(FILAS): | |
coordY = PISO - i * ANCHO_FIL | |
pygame.draw.line( | |
screen, | |
(255, 255, 255), | |
(CORRIMIENTO, coordY), | |
(bordeDerecha + CORRIMIENTO, coordY), | |
2 | |
) | |
coordY -= ANCHO_FIL | |
pygame.draw.line( | |
screen, | |
(255, 255, 255), | |
(CORRIMIENTO, coordY), | |
(bordeDerecha + CORRIMIENTO, coordY), | |
2 | |
) | |
#Dibuja las lineas en el eje X | |
for j in range(COLUMNAS): | |
coordX = j * ANCHO_COL + CORRIMIENTO | |
pygame.draw.line( | |
screen, | |
(255, 255, 255), | |
(coordX, coordY), | |
(coordX, PISO), | |
2 | |
) | |
coordX -= ANCHO_FIL | |
pygame.draw.line( | |
screen, | |
(255, 255, 255), | |
(bordeDerecha + CORRIMIENTO, coordY), | |
(bordeDerecha + CORRIMIENTO, PISO), | |
2 | |
) | |
ren1a = defaultFont.render("Puntos: " + puntos, 1, COLOR_TEXTO) | |
ren1b = defaultFont.render( | |
"Intentos disponibles: " + str(intentos), | |
1, | |
COLOR_TEXTO | |
) | |
ren2 = defaultFont.render(ganador, 1, COLOR_TEXTO) | |
#Dibuja las letras en la pantalla | |
for i in range(FILAS): | |
for j in range(COLUMNAS): | |
if MatLetras[i][j] != 0: | |
aux = str(MatLetras[i][j]) | |
else: | |
aux = " " | |
screen.blit( | |
defaultFont.render(aux, 1, COLOR_LETRAS), | |
( | |
CORRIMIENTO + ((j + 0.3) * ANCHO_COL), | |
PISO - (i + 1) * ANCHO_FIL) | |
) | |
if inputField == -1: | |
screen.blit( | |
defaultFont.render( | |
"Mal pibe...", 1, COLOR_RESALTADO), | |
(bordeDerecha / 2, ALTO / 2 - ANCHO_FIL) | |
) | |
if inputField == 0: | |
color3a = COLOR_RESALTADO | |
color3b = COLOR_TEXTO | |
color3c = COLOR_TEXTO | |
color3d = COLOR_TEXTO | |
elif inputField == 1: | |
color3a = COLOR_TEXTO | |
color3b = COLOR_RESALTADO | |
color3c = COLOR_TEXTO | |
color3d = COLOR_TEXTO | |
elif inputField == 2: | |
color3a = COLOR_TEXTO | |
color3b = COLOR_TEXTO | |
color3c = COLOR_RESALTADO | |
color3d = COLOR_TEXTO | |
elif inputField == 3: | |
color3a = COLOR_TEXTO | |
color3b = COLOR_TEXTO | |
color3c = COLOR_TEXTO | |
color3d = COLOR_RESALTADO | |
if(fil != ""): | |
f = int(fil) | |
else: | |
f =- 2 | |
if(col!=""): | |
c = int(col) | |
else: | |
c = -2 | |
if PosicionEnRango(f, c): | |
screen.blit( | |
defaultFont.render(str(MatLetras[f][c]), 1, COLOR_RESALTADO), | |
((c+0.4) * ANCHO_COL, PISO - (f+1) * ANCHO_FIL) | |
) | |
else: | |
color3a = COLOR_TEXTO | |
color3b = COLOR_TEXTO | |
color3c = COLOR_TEXTO | |
color3d = COLOR_TEXTO | |
ren3a = defaultFont.render("Palabra: " + palabra, 1, color3a) | |
#ren3b = defaultFont.render("Fila: " + fil, 1, color3b) | |
#ren3c = defaultFont.render("Columna: " + col, 1, color3c) | |
#ren3d = defaultFont.render("Direccion: " + direccion, 1, color3d) | |
ren6 = defaultFont.render( | |
"Intentos Disponibles: " + str(intentos), | |
1, | |
COLOR_TEXTO | |
) | |
if intentos == 0 or segundos == 0: | |
# CAMBIAR POR ALGO MAS LINDO | |
ren4 = defaultFont.render("Perdiste...", 1, (200, 20, 10)) | |
screen.blit(ren4, (ANCHO_COL, ALTO / 2 + ANCHO_FIL)) | |
pygame.mixer.music.stop() | |
sonido5 = pygame.mixer.Sound('fin.ogg') | |
sonido5.play() | |
FLAG = False | |
return FLAG | |
if segundos < 15: | |
color9 = COLOR_TIEMPO_FINAL | |
else: | |
color9 = COLOR_TEXTO | |
ren9 = defaultFont.render("Tiempo: " + str(int(segundos)), 1, color9) | |
screen.blit(ren1a, (ANCHO_COL, 10)) | |
screen.blit(ren1b, (ANCHO_COL, 10 + ANCHO_FIL)) | |
screen.blit(ren2, (ANCHO_COL, PISO + ANCHO_FIL * 5 / 3)) | |
screen.blit(ren3a, (ANCHO_COL, ALTO / 2)) | |
# screen.blit(ren4, (ANCHO_COL, ALTO / 2 + ANCHO_FIL)) | |
# screen.blit(ren3c, (bordeDerecha + ANCHO_COL, ALTO / 2 + 2* ANCHO_FIL)) | |
# screen.blit(ren3d, (bordeDerecha + ANCHO_COL, ALTO / 2 + 3* ANCHO_FIL)) | |
screen.blit(ren9, (bordeDerecha + CORRIMIENTO, 10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import random | |
from principal import * | |
from extras import * | |
from configuracion import * | |
def NuevaLetra(): | |
probabilidad = random.randint(0, 9) # La probabilidad varia entre 0 y 9 | |
if probabilidad <= 5: # Si la probabilidad es del 60% sale una CONSONANTE | |
letra = random.choice(CONSONANTE) | |
elif probabilidad > 5 and probabilidad <= 8: | |
# Si la probabilidad es del 30% sale una VOCAL | |
letra = random.choice(VOCAL) | |
else: | |
letra = random.choice(DIFICIL) | |
# Si la probabilidad es del 10% sale una DIFICIL | |
return letra # Devuelvo una letra al azar | |
def Puntos(palabra): | |
''' | |
Calcula el puntaje de una palabra y lo devuelve. | |
''' | |
puntaje = 0 | |
for letra in palabra: # Por cada letra en la palabra me fijo lo siguiente: | |
if letra in VOCAL: # Si la letra es una VOCAL suma 1 | |
puntaje = puntaje + 1 | |
elif letra in CONSONANTE: # Si la letra es una CONSONANTE suma 2 | |
puntaje = puntaje + 2 | |
else: # Si la letra es una DIFICIL suma 5 | |
puntaje = puntaje + 5 | |
return puntaje | |
def InitLemario(): | |
''' | |
Leo un archivo y creo una lista que contenga todas las palabras del mismo. | |
''' | |
lemario = [] # Creo una lista | |
f = open("lemario.txt", "r") # Abro el archivo | |
for linea in file.readlines(): # Lleno la lista que cree con el lemario | |
linea = linea[:-1] | |
lemario.append(linea) | |
f.close() # Cierro el archivo | |
return lemario # Devuelvo el lemario en una lista | |
def InitMat(mat): | |
''' | |
Recibe la matriz y la relleno posicion a posicion con letras al azar | |
''' | |
return [[NuevaLetra() for j in range(COLUMNAS)] for i in range(FILAS)] | |
def EnDiccionario(palabra, lemario): | |
''' | |
Compara posicion a posicion del lemario, con la palabra. | |
En caso de que la encuentre, devuelve True, Sino False. | |
''' | |
for i in range(len(lemario)): | |
if palabra == lemario[i]: | |
return True | |
return False | |
def NoRepetida(palabra, salieron): | |
''' | |
Compara cada palabra de la lista, con la que le pase, si hay coincidencia | |
devuelve False, sino True. | |
''' | |
for i in range(len(salieron)): | |
if palabra == salieron[i]: | |
return False | |
return True | |
def PalabraEnMatriz(palabra, tira): | |
''' | |
Va recorriendo la matriz y buscando la palabra en la tira, si esta devuelve | |
True, sino False. | |
''' | |
cadena = "" # Creo una cadena vacia | |
NuevaLista = [] # Creo una lista vacia | |
for i in range(FILAS): | |
for j in range(COLUMNAS): | |
# Recorro la matriz posicion a posicion y cargo cada elemento en la | |
# nueva lista | |
NuevaLista.append(tira[i][j]) | |
for letra in palabra: # Tomo cada letra de la palabra y voy comparando | |
if letra in NuevaLista: | |
# Si la letra esta en la lista, la agrego a la cadena | |
cadena = cadena + letra | |
# El método .remove, remueve la primera ocurrencia del valor en la | |
# lista y devuelve un ValueError si la ocurrencia no esta. | |
NuevaLista.remove(letra) | |
# Comparo la cadena que se formo con la palabra, si son iguales devuelvo | |
# True, sino False | |
return cadena == palabra |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os, random, sys, math | |
import pygame | |
from pygame.locals import * | |
from configuracion import * | |
from funciones import * | |
from extras import * | |
from BestRecords import* | |
pygame.init() | |
#Funcion principal | |
def main(): | |
pygame.mixer.music.load('audiob.wav') | |
sonido1=pygame.mixer.Sound('efecto2.ogg') | |
sonido2=pygame.mixer.Sound('efecto3.ogg') | |
sonido4=pygame.mixer.Sound('win.wav') | |
#Centrar la ventana y despues inicializar pygame | |
os.environ["SDL_VIDEO_CENTERED"] = "1" | |
pygame.init() | |
#pygame.mixer.init() | |
fondo=pygame.image.load('fondo.bmp') | |
#Preparar la ventana | |
pygame.display.set_caption("SACA PALABRAS") | |
screen = pygame.display.set_mode((800,600))#((ANCHO, ALTO)) | |
#tiempo total del juego | |
gameClock = pygame.time.Clock() | |
totaltime = 0 | |
segundos = TIEMPO_MAX | |
fps = FPS_inicial | |
matriz = [ [0 for j in range(COLUMNAS)] for i in range(FILAS)] | |
mat= InitMat(matriz) | |
ganador = "" | |
puntos = 0 | |
intentos = INTENTOS_INICIALES | |
lemario = InitLemario() | |
salieron = [] | |
pygame.mixer.music.play(-1) | |
#inputField | |
# 0: palabra | |
# 1: fila | |
# 2: columna | |
# 3: direccion | |
inputField = 0 | |
palabra = "" | |
fil = col = "" | |
direccion = [0,0] | |
showDireccion = "" | |
dibujarMatriz(screen, mat, "0", intentos, palabra, fil, col, "", ganador, segundos, inputField) | |
while segundos > fps/1000 and intentos>0: | |
bandera=True | |
# 1 frame cada 1/fps segundos | |
gameClock.tick(fps) | |
totaltime += gameClock.get_time() | |
if True: | |
fps = 3 | |
#Buscar la tecla apretada del modulo de eventos de pygame | |
for e in pygame.event.get(): | |
#QUIT es apretar la X en la ventana | |
if e.type == QUIT: | |
pygame.quit() | |
return() | |
#Ver si fue apretada alguna tecla | |
if e.type == KEYDOWN: | |
#Ingresar palabra | |
if inputField < 1: | |
letra = LetraApretada(e.key) | |
palabra += letra | |
if e.key == K_BACKSPACE: | |
palabra = palabra[0:len(palabra)-1] | |
if e.key == K_RETURN and palabra != "": | |
inputField = 1 | |
''' #Ingresar fila | |
if inputField == 1: | |
fil = InputNumber(e.key, fil) | |
if e.key == K_RETURN and fil != "": | |
inputField += 1 | |
#Ingresar columna | |
if inputField == 2: | |
col = InputNumber(e.key, col) | |
if e.key == K_RETURN and col != "": | |
inputField += 1 | |
#Ingresar direccion | |
if inputField == 3: | |
FlechaApretada(e.key, direccion) | |
if e.key == K_RETURN and direccion != [0,0]: | |
inputField += 1 | |
''' | |
#if inputField > 3: | |
if inputField == 1: | |
#Esta comentado para testear el resto | |
# cuando ande el resto, descomentar y sacar la siguiente linea | |
# if EnDiccionario(palabra, lemario) and PalabraEnMatriz(palabra, mat, int(fil), int(col), direccion[0], direccion[1]): | |
if PalabraEnMatriz(palabra, mat) and EnDiccionario(palabra,lemario) and NoRepetida(palabra,salieron): | |
sonido1.play() | |
puntos += Puntos(palabra) | |
inputField = 0 | |
salieron.append(palabra) | |
else: | |
sonido2.play() | |
inputField = -1 | |
intentos -= 1 | |
palabra = "" | |
fil = col = "" | |
direccion = [0,0] | |
showDireccion = "" | |
segundos = TIEMPO_MAX - pygame.time.get_ticks()/1000 | |
# if not Actualizar(mat): | |
# intentos = 0 | |
#Limpiar pantalla anterior | |
screen.fill(COLOR_FONDO) | |
if int(segundos)%15 == 0 and int(segundos) != 0: #Renueva la matriz cada 5 segundos | |
mat=InitMat(mat) | |
pygame.time.wait(1000) | |
#segundos -= 1 | |
#Dibujar de nuevo todo | |
dibujarMatriz(screen, mat, str(puntos), intentos, palabra, fil, col, ShowDireccion(direccion), ganador, segundos, inputField) | |
pygame.display.flip() | |
if segundos < 0.0 : | |
pygame.mixer.music.stop() | |
sonido4.play() | |
while 1: | |
#Esperar el QUIT del usuario | |
for e in pygame.event.get(): | |
if e.type == QUIT: | |
pygame.quit() | |
MejoresRecords(puntos) | |
return | |
#Programa Principal ejecuta Main | |
if __name__ == "__main__": | |
main() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from configuracion import * | |
from funciones import * | |
from BestRecords import * | |
# Prueba NuevaLetra | |
print("Letra:", NuevaLetra()) | |
# Prueba InitLemario | |
# Sacarle los comentarios al print si quieren imprimir todo el lemario. | |
# print(InitLemario()) | |
# Prueba InitMat | |
mat = [[0 for j in range(COLUMNAS)] for i in range(FILAS)] # Defino una matriz | |
matriz = InitMat(mat) # Relleno la matriz con letras | |
print(matriz) | |
#Prueba EnDiccionario | |
print(EnDiccionario('zocalo', InitLemario())) | |
#Debe devolver True pues la palabra 'zocalo' esta en el lemario | |
print(EnDiccionario('azdfgh', InitLemario())) | |
#Debe devolver False pues la palabra 'azdfgh' no esta en el lemario | |
#Prueba NoRepetida | |
salieron = ['manzana', 'banana', 'pera'] | |
salieron1 = [] | |
print("La palabra %s no se repite?" % 'pera', NoRepetida('pera', salieron)) | |
print("La palabra %s no se repite?" % 'pera', NoRepetida('pera', salieron1)) | |
print( | |
"La palabra %s no se repite?" % 'naranja', | |
NoRepetida('naranja', salieron) | |
) | |
#Prueba PalabraEnMatriz | |
mat = [ | |
['f', 'o', 'c', 'v', 'm', 'd', 'n', 'f', 'b', 'h'], | |
['a', 'd', 'n', 'n', 'r', 'b', 'g', 'ñ', 'o', 'u'], | |
['a', 'u', 'f', 't', 'e', 'v', 's', 't', 'ñ', 'u'] | |
] | |
# Puedo formar casa en la tira | |
print("PEM casa:", PalabraEnMatriz("casa", mat)) | |
# Puedo formar saca en la tira | |
print("PEM saca:", PalabraEnMatriz("saca", mat)) | |
print("PEM oso:", PalabraEnMatriz("oso", mat)) # Puedo formar oso en la tira | |
print("PEM zocalo", PalabraEnMatriz("zocalo", mat)) # No puedo formar zocalo | |
print("PEM ggg", PalabraEnMatriz("ggg", mat)) # N o tengo 3 g | |
# Prueba Puntos | |
print(Puntos('arbol')) # Debe mostrar 8 pntos | |
print(Puntos('')) # Debe mostrar 0 pntos | |
print(Puntos('joya')) # Debe mostrar 12 pntos | |
#Prueba Records | |
MejoresRecords(77) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment