void pruebasDesplazarIzd(){ tablero t; long long int puntuacion=0; iniciar(t,TAMANIOTABLERO); entornoIniciar(TAMANIOTABLERO); //generamos unos valores iniciales en cualquier casilla t.m[1][1]=2; t.m[1][2]=2; pintarTablero(t);//mostramos los cambios en la pantalla entornoPausa(2000000); desplazarIzd(t,puntuacion);//Accedemos al módulo pintarTablero(t); entornoPausa(2000000); if(t.m[1][0]==4){ //Como sabemos que si el módulo funcionase debería desplazar y sumar los numeros //que hemos puesto,comprobamos que la casilla en la que teóricamente queda el resultado //tiene el valor esperado cout<<"Veremos como los valores se desplazan a la izquierda"<<endl; cout<<"El modulo funciona"<<endl; } else{ cout<<"Fallo en el módulo de desplazar izquierda"<<endl; } }
int main() { // Turn off miniblip buzzer PwmOut speaker(P0_8); speaker=0.0; // Create a temporary DigitalIn so we can configure the pull-down resistor. DigitalIn(DATA_PIN, PullDown); // The pixel array control class. neopixel::PixelArray array(DATA_PIN); //Genero la variable que representa el potenciometro AnalogIn ain(POTEN); for(int j=0;j<NLEDS;j++){ tablero[j]= EMPTY; } tablero[bird]=BIRD; while (1) { if(ciclos==0){ ciclos = NUMEROCICLOSPORJUEGADA; if(!lose)generarTablero(); } pintarTablero(); colorbrigthness::calculatecolorMatrix(lista,NLEDS,255*ain); array.update(lista,NLEDS); ciclos--; wait_ms(100); } }
void pruebasEstaLleno(){ tablero t; int i,j; //Iniciamos un tablero y lo mostramos en el entorno iniciar(t,TAMANIOTABLERO); entornoIniciar(TAMANIOTABLERO); //Ahora recorreremos la matriz del tablero asignandole valores a las casillas //y luego comprobaremos si el módulo que se encarga de ver si está lleno funciona for(i=0;i<TAMANIOTABLERO;i++){ for(j=0;j<TAMANIOTABLERO;j++){ t.m[i][j]=2; } } pintarTablero(t);//Pintamos el tablero para mostrar los cambios en pantalla entornoPausa(5000000); if(EstaLleno(t)==true){ cout<<"El modulo detecta que todas las casillas estan llenas y finaliza el juego"<<endl; cout<<" "<<endl; cout<<"El módulo da el resultado esperado"<<endl; } else{ cout<<"Error en el módulo para comprobar si está lleno"<<endl; } }
void pruebasGenerar(){ //La prueba de este módulo es similar a la del anterior tablero t;//Iniciamos un tablero t iniciar(t,TAMANIOTABLERO); entornoIniciar(TAMANIOTABLERO); generar(t);//Generamos un valor en el tablero pintarTablero(t);//Mostramos los cambios en pantalla durante unos segundos entornoPausa(5000000); cout<<"Se genrará 1 numero aleatorio (2 o 4) en una casilla aleatoria vacia del tablero"<<endl; }
void sudoku::initGui(){ for(int i = 0;i < 9; i++){ for(int j = 0; j < 9; j++){ numbertext[i][j] = new QTextEdit(NULL); ui->numberPad->addWidget(numbertext[i][j], i, j); connect(numbertext[i][j],SIGNAL(textChanged()),this,SLOT(correccionInGame())); } } pintarTablero(); }
void pruebasGenerar_inicial(){ tablero t;//Iniciamos un tablero t int numiniciar=2; iniciar(t,TAMANIOTABLERO); entornoIniciar(TAMANIOTABLERO); generar_inicial(t,numiniciar);//Generamos dos valores iniciales en un lugar aleatorio del tablero pintarTablero(t);//Mostramos los cambios en pantalla durante unos segundos entornoPausa(5000000); //Se podrá comprobar que el módulo es correcto de manera visual si se generan 2 valores //en algún lugar del tablero que sea 2 ó 4 cout<<"Se generarán 2 números (2 o 4)aleatorios en cualquier casilla del tablero"<<endl; }
void sudoku::CorreccionFila(int i,int j){ /**validacion in game para filas*/ for(int k = 0; k < 9; k++){ if(k!=j){ if(getDisplayValue(i,j)==getDisplayValue(i,k)){ QPalette p = numbertext[i][j]->palette(); p.setColor(QPalette::Base, QColor(255, 150, 150)); numbertext[i][j]->setPalette(p); numbertext[i][k]->setPalette(p); QMessageBox::information(this, "Advertencia", "Este numero ya fue ingresado en la fila"); return; }else pintarTablero(); } } }
void pruebasPuntuacionMax(){ tablero t;//Iniciamos un tablero t para la prueba //Declaramos la variable que nos servirá de referencia como valor máximo en la prueba int maxPrueba=64; iniciar(t,TAMANIOTABLERO); entornoIniciar(TAMANIOTABLERO);//Mostramos el tablero en el entorno gráfico t.m[0][0]=64;//Le damos a una de las casillas el valor máximo pintarTablero(t);//Pintamos el tablero para mostrar los cambios entornoPausa(5000000); if(puntuacionMax(t,maxPrueba)==true){ //Si el módulo funciona tal y como se espera se mostrará un mensaje cout<<"EL modulo finalizará al haber encontrado el valor máximo que es 64"<<endl; cout<<" "<<endl; cout<<"El módulo funciona correctamente"<<endl; } else{ //En caso contrario se mostraría un mensaje de error cout<<"El módulo no funciona de manera correcta"<<endl; } }
void sudoku::CorreccionCuadrante(int i,int j){ int despy=(i/3) *3; int despx=(j/3) *3; /**validacion in game para cuadrantes*/ for(int y = despy; y < despy+3; y++){ for(int x =despx ; x < despx+3; x++){ if(((y!=i) && (x!=j))){ if(getDisplayValue(i,j)==getDisplayValue(y,x)){ QPalette p = numbertext[i][j]->palette(); p.setColor(QPalette::Base, QColor(255, 150, 150)); numbertext[i][j]->setPalette(p); numbertext[y][x]->setPalette(p); QMessageBox::information(this, "Advertencia", "Este numero ya fue ingresado en el cuadrante"); return; }else pintarTablero(); } } } }
/**JUEGO NUEVO*/ void sudoku::on_nuevoJuego_clicked(){ int i=0, j=0, k=0, aleatorio; QStringList valores; miliseg=0; seg=0; min=0; timer->start(10); update(); /**Semilla del aleatorio*/ QTime *seed = new QTime; seed->start(); qsrand(seed->msec()); QString niveles = ui->textNivel->text(); if(niveles == "Juvenil") valores = plantilla1.split(","); else if(niveles == "Profesional") valores = plantilla2.split(","); else if(niveles == "Experto") valores = plantilla3.split(","); for(i = 0;i < 9; i++){ for(j = 0; j < 9; j++){ aleatorio = rand() % 10; if(niveles == "Juvenil") if (aleatorio <= 6){ numbertext[i][j]->setTextColor(Qt::blue); numbertext[i][j]->setText(valores[k]); numbertext[i][j]->setDisabled(true); }else{ numbertext[i][j]->setDisabled(false); numbertext[i][j]->setText(""); } else if(niveles == "Profesional") if (aleatorio <= 4){ numbertext[i][j]->setTextColor(Qt::blue); numbertext[i][j]->setText(valores[k]); numbertext[i][j]->setDisabled(true); }else{ numbertext[i][j]->setDisabled(false); numbertext[i][j]->setText(""); } else if(niveles == "Experto") if (aleatorio <= 2){ numbertext[i][j]->setTextColor(Qt::blue); numbertext[i][j]->setText(valores[k]); numbertext[i][j]->setDisabled(true); }else{ numbertext[i][j]->setDisabled(false); numbertext[i][j]->setText(""); } numbertext[i][j]->setAlignment(Qt::AlignRight); k++; } } /**Comenzar el cronometro*/ timer->start(10); pintarTablero(); }