elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: sudoku en dev c++ en: 3 Marzo 2019, 02:50 am
ok gracias por responder tan pronto :rolleyes:  ;-)
2  Programación / Programación C/C++ / sudoku en dev c++ en: 3 Marzo 2019, 00:37 am
Hola
me podrian ayudar  por fa    :silbar:
en estos momentos estoy creando un proyecto de progrmamacion consiste en crear un sudoku, ya casi lo termino, la pregunta es como podria en el menu de la portada definir que solo acepte los numeros (QUE NO ACEPTE LETRAS NI SImBOLOS), y tambien para que pueda retornar al menu anterior .

Ademas e incluido una libreria de colores que deben poner en la carpeta del sudoku.




#include<stdio.h>
#include <windows.h>

int color(int b, int f);

int color(int b, int f){
   HANDLE  hConsole;
   WORD    ForeColor = 0;
   WORD    BackColor;
   WORD    wAttributesOld;
   CONSOLE_SCREEN_BUFFER_INFO csbi;

  // **  Open the current console input buffer.
  // **  Abrir la consola actual memoria intermedia de entrada.
  if( ( hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,
                     0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L) )
                 == (HANDLE) -1 ) {
      printf("\nError: Unable to open console.\n");
      return( -1 );
  }

  // **  Get and Save information on the console screen buffer.
  // **  Obtener y guardar información sobre la pantalla de la consola de amortiguación.
   GetConsoleScreenBufferInfo( hConsole, &csbi );
   wAttributesOld = csbi.wAttributes;

   BackColor = b;
   ForeColor= f;
   SetConsoleTextAttribute( hConsole, (WORD) ( (BackColor << 4) | ForeColor) );
   return 0;
}










-----> Este es el codigo<------

//:proyecto final de programacion
//nombres:ronaldo salazar,andres timote
//grupo 81

#include "colores.h"
#include <stdio.h>//utilizar las funciones que están declaradas
#include <time.h>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>

/*
Donde A y B son el color de fondo y el color de texto respectivamente.

0 = Negro
1 = Azul
2 = Verde
3 = Aguamarina
4 = Rojo
5 = Purpura
6 = Amarillo
7 = Blanco
8 = Gris
9 = Azul claro
A = Verde claro
B = Aguamarina claro
C = Rojo claro
D = Purpura claro
E = Amarillo claro
F = Blanco brillante
 */
int principal();
int buscar_num(int numero,int arreglo[9][9],int tam,int j,int h);
int moverx(int teclado,int a);
int movery(int teclado,int b);
void pintar(int teclado);
void mundo(int opcion,int opcionn);
void solucion(int arreglo[9][9]);
void gotoxy(int x,int y);
void pintar();
void menu();
int m;
char mapa[9][9];

int arreglo1[9][9],arreglo2[9][9],vista2[9][9];

int bandera=0,teclado=0,b,c,contadorx=0,contadory=0,xx=5,yy=5,jota,fstop=0,aleatorio,l=0,i,conta=0,conta2=0;
int opcion,opcionn,contadoryy,contadorxx;
int condicion(int b,int c);

void menu()
{
   pintar(3);
   do
      {system("CLS");
      

           

                    /* LIBRERIA COLORES
            Colores :
            BLACK         0 Negro
            BLUE         1 Azul
            GREEN         2 Verde
            CYAN         3 Cían
            RED            4 Rojo
            MAGENTA         5 Magenta
            BROWN         6 Marrón
            LIGHTGRAY      7 Gris Claro
            DARKGRAY      8 Gris Oscuro
            LIGHTBLUE      9 Azul Claro
            LIGHTGREEN      10 Verde Claro
            LIGHTCYAN      11 Cían Claro
            LIGHTRED      12 Rojo Claro
            LIGHTMAGENTA   13 Magenta Claro
            YELLOW         14 Amarillo
            WHITE         15 Blanco
            */
           
            color(0,14);
            gotoxy(24,5);printf("S");
            gotoxy(23,5);printf("S");
            gotoxy(22,5);printf("S");
            gotoxy(21,5);printf("S");
            gotoxy(21,6);printf("S");
            gotoxy(21,7);printf("S");
            gotoxy(21,8);printf("S");
            gotoxy(22,8);printf("S");
            gotoxy(23,8);printf("S");

            gotoxy(24,8);printf("S");
            gotoxy(25,8);printf("S");
            gotoxy(25,9);printf("S");
            gotoxy(25,10);printf("S");
            gotoxy(24,10);printf("S");
            gotoxy(23,10);printf("S");
            gotoxy(22,10);printf("S");
            gotoxy(21,10);printf("S");



            gotoxy(27,5);printf("U");
            gotoxy(27,6);printf("U");
            gotoxy(27,7);printf("U");
            gotoxy(27,8);printf("U");
            gotoxy(27,9);printf("U");

            gotoxy(27,10);printf("U");
            gotoxy(28,10);printf("U");
            gotoxy(29,10);printf("U");

            gotoxy(29,9);printf("U");
            gotoxy(29,8);printf("U");
            gotoxy(29,7);printf("U");
            gotoxy(29,6);printf("U");
            gotoxy(29,5);printf("U");







            gotoxy(31,5);printf("D");
            gotoxy(31,6);printf("D");
            gotoxy(31,7);printf("D");
            gotoxy(31,8);printf("D");
            gotoxy(31,9);printf("D");
            gotoxy(31,10);printf("D");
            gotoxy(32,5);printf("D");
            gotoxy(33,5);printf("D");
            gotoxy(34,6);printf("D");
            gotoxy(35,7);printf("D");
            gotoxy(35,8);printf("D");
            gotoxy(34,9);printf("D");
            gotoxy(33,10);printf("D");
            gotoxy(32,10);printf("D");

            gotoxy(38,5);printf("O");
            gotoxy(38,6);printf("O");
            gotoxy(38,7);printf("O");
            gotoxy(38,8);printf("O");
            gotoxy(38,9);printf("O");
            gotoxy(38,10);printf("O");
            gotoxy(39,5);printf("O");
            gotoxy(39,5);printf("O");
            gotoxy(40,5);printf("O");
            gotoxy(42,5);printf("O");
            gotoxy(42,6);printf("O");
            gotoxy(42,7);printf("O");
            gotoxy(42,8);printf("O");
            gotoxy(42,9);printf("O");
            gotoxy(42,10);printf("O");
            gotoxy(41,10);printf("O");
            gotoxy(40,10);printf("O");
            gotoxy(39,10);printf("O");

            gotoxy(45,10);printf("k");
            gotoxy(45,9);printf("k");
            gotoxy(45,8);printf("k");
            gotoxy(45,7);printf("k");
            gotoxy(45,6);printf("k");
            gotoxy(45,5);printf("k");
            gotoxy(46,8);printf("k");
            gotoxy(47,9);printf("k");
            gotoxy(48,10);printf("k");
            gotoxy(48,6);printf("k");
            gotoxy(47,7);printf("k");



            gotoxy(51,5);printf("U");
            gotoxy(51,6);printf("U");
            gotoxy(51,7);printf("U");
            gotoxy(51,8);printf("U");
            gotoxy(51,9);printf("U");

            gotoxy(51,10);printf("U");
            gotoxy(52,10);printf("U");
            gotoxy(53,10);printf("U");

            gotoxy(53,9);printf("U");
            gotoxy(53,8);printf("U");
            gotoxy(53,7);printf("U");
            gotoxy(53,6);printf("U");
            gotoxy(53,5);printf("U");




            color(0,10);
            gotoxy(25,14);printf("PROYECTO FINAL PROGRAMACION");
            gotoxy(28,16);printf("INGENIERIA EN SISTEMAS");
            gotoxy(25,18);printf("Andres Timote,Ronaldo Salazar");
            gotoxy(27,20);printf("preciona 1 para continuar");
             
           scanf("%d",&m);
           
                
           
               
                 

            color(0,12);
             system("cls");
            gotoxy(24,11);printf(" ELIGE UNA OPCION PARA COMENZAR: ");
            gotoxy(30,12);printf(" 1. Automatico ");
            gotoxy(30,13);printf(" 2. Manual");
           scanf("%d",&opcion);
      }while(opcion<1 || opcion>2);
              if(opcion!=1)
               {
         do
         {system("CLS");
            printf("Eliga una opcion: \n 1. Facil \n 2. Medio \n 3. Dificil");
            scanf("%d",&opcionn);
         }while(opcionn<1||opcionn>3);
               }
      system("CLS");
}
main(void)
{   
while(bandera==0)
   {
      bandera=0;teclado=0;contadorx=0;contadory=0;xx=5;yy=5;jota=0;fstop=0;aleatorio=0;opcion=0;opcionn=0;
      menu();
      solucion(arreglo1);
      mundo(opcion,opcionn);
      bandera=principal();
   }
}
int principal()
{
   gotoxy(xx,yy);
   while(teclado!=27 && teclado!=120) //RUTINA DEL JUEGO
      {
                     teclado=getch();
                   if(teclado==97 || teclado==100)
                   {
                         xx=moverx(teclado,xx);
                         gotoxy(xx,yy);
                         if(teclado==100){contadorx=contadorx+1;}
                         else if(teclado==97){contadorx=contadorx-1;}
                        if(contadorx>8){contadorx=0;}
                         if(contadorx<0){contadorx=8;}
                   }
                   else if(teclado==119 || teclado==115)
                   {
                         yy=movery(teclado,yy);
                         gotoxy(xx,yy);
                         if(teclado==115){contadory=contadory+1;}
                         else if(teclado==119){contadory=contadory-1;}
                         if(contadory>8){contadory=0;}
                         if(contadory<0){contadory=8;}
                   }
                  if((teclado==49||teclado==50||teclado==51||teclado==52||teclado==53||
                     teclado==54||teclado==55||teclado==56||teclado==57) && mapa[contadory][contadorx]=='°')
                  {
                     if(teclado==49)jota=1;
                     if(teclado==50)jota=2;
                     if(teclado==51)jota=3;
                     if(teclado==52)jota=4;
                     if(teclado==53)jota=5;
                     if(teclado==54)jota=6;
                     if(teclado==55)jota=7;
                     if(teclado==56)jota=8;
                     if(teclado==57)jota=9;
                     fstop=0;
                     fstop=buscar_num(jota,arreglo2,9,contadory,contadorx);
                     arreglo2[contadory][contadorx]=jota;
                     if(fstop==1){pintar(2);}
                     else{pintar(1);}
                     printf("%d",jota);
                     gotoxy(xx,yy);   
                  }   
                  if(teclado==8 && mapa[contadory][contadorx]=='°')
                  {
                     pintar(3);
                     gotoxy(xx,yy);
                     printf("°");
                     mapa[contadory][contadorx]='°';
                     arreglo2[contadory][contadorx]=0;
                     gotoxy(xx,yy);      
                  }               
      }
      if(teclado==120)
      {
         system("CLS");
         return 0;   
      }
      else
      {
         gotoxy(5,27);
         return 1;
      }
}

int moverx(int teclado,int x) //CONTROLA EL MOVIMIENTO DEL CURSOR EN EL EJE X
{                                                       
                  if(teclado==97)
                  {
                     x-=6;
                     if(x==23){x=17;}
                     else if(x==47){x=41;}
                     else if(x<5){x=65;}
                  }
                  if(teclado==100)
                  {
                     x+=6;
                     if(x==23){x=29;}
                     else if(x==47){x=53;}
                     else if(x>65){x=5;}
                  }
return   x;
}

int movery(int teclado,int y) //CONTROLA EL MOVIMIENTO DEL CURSOR EN EL EJE Y
{
                  if(teclado==119)
                  {
                        y-=2;
                        if(y==11){y=9;}
                        else if(y==19){y=17;}
                        else if(y<5){y=25;}
                  }
                  else if(teclado==115)
                  {
                        y+=2;
                        if(y==11){y=13;}
                        else if(y==19){y=21;}
                        else if(y>25){y=5;}   
                  }
return   y;
}
void gotoxy(int x,int y)// CONTROLA LA POSICION DEL CURSOR EN LOS EJES X,Y
{
HANDLE hCon;
hCon=GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X=x;
dwPos.Y=y;
SetConsoleCursorPosition(hCon,dwPos);
}
void mundo(int opcion,int opcionn)
{
pintar(3);color(0,14);
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° SUDOKU °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n \n");
srand(time(NULL));
for(b=0;b<9;b++)
{
   printf("\n \n");                     
   if(b==3 || b==6){ color(0,14);printf(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n\n");}
   for(c=0;c<9;c++)
   {
      if(c==3 || c==6){color(0,14);printf("    ::");}
      if(opcion!=1)
      {color(0,11);
         arreglo2[c]=0;
         mapa[c]='°';
         if(rand()%(opcionn+1)==1)
         {color(0,11);
            printf("%6d",arreglo1[c]);
            arreglo2[c]=arreglo1[c];
            mapa[c]='|';
         }
         else{printf("%6c",mapa[c]);}   
      }
      else{mapa[c]='|'; printf("%6d",arreglo1[c]);}
   }
}                  
}
void solucion(int arreglo1[9][9])
{   
srand(time(NULL));  //  La generación de números aleatorios
do{
   conta2=0;conta=0;
   for(b=0;b<9;b++)
   {
      for(c=0;c<9;c++)
      {
         arreglo1[c]=0;
         vista2[c]=0;   
      }
   }
   for(b=0;b<9;b++)
   {
      for(c=0;c<9;c++)
      {
         conta=0;
         i=condicion(b,c);
            do
            {
               aleatorio=1+rand()%9;
               fstop=buscar_num(aleatorio,arreglo1,9,b,c);
               conta++;
               if(conta>100)
               {
                  fstop=0;
                  vista2[aleatorio-1]=0;
                  c=9;
                  b=9;
               }
            }while(fstop==1 || vista2[aleatorio-1]==1 );
            if(c<3){vista2[aleatorio-1]=1;}
            else if(c>2 && c<6){vista2[aleatorio-1]=1;}
            else if(c>5 && c<9){vista2[aleatorio-1]=1;}   
            arreglo1[c]=aleatorio;
             conta2++;   
      }
   }
}while(conta2!=81);
}
int buscar_num(int numero,int arreglo[9][9],int tam,int b,int c) // CONTROLA LOS ALEATORIOS QUE SE REPITEN
{
int i,stop=0;         
   for(i=0;(i<tam && stop==0);i++)
   {                         
      if(arreglo==numero || arreglo[c]==numero){stop=1;}
   }
return stop;
}
void pintar(int teclado) // CONTROLA EL COLOR DE LOS NUMEROS QUE SE DIGITAN EN EL TABLERO DEL SUDOKU
{                       //   ----- El tipo HANDLE lo que hace es obtener la “salida” de la consola
HANDLE hConsoleOutput; //  "hConsoleOutput" manipulador del buffer de pantalla de consola
COORD coord;
hConsoleOutput = GetStdHandle (STD_OUTPUT_HANDLE); //   "GetStdHandle" dispositivo input, output o error
if(teclado==2){SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),12);}
else if(teclado==1){SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),10);}
else if(teclado==120){SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),15);}// despues de dar "salida" SetConsoleTextAttribute(). cambia color
else if(teclado==3){SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),11);}
}

int condicion(int b,int c)
{
         if(b<3)
         {
            if(c<3){i=0;}
            else if(c>2 && c<6){i=1;}
            else if(c>5 && c<9){i=2;}
         }
         else if(b>2 && b<6)
         {
            if(c<3){i=3;}
             if(c>2 && c<6){i=4;}
             if(c>5 && c<9){i=5;}
         }
            else if(b>5 && b<9)
         {
            if(c<3){i=6;}
             if(c>2 && c<6){i=7;}
             if(c>5 && c<9){i=8;}
         }
return i;   
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines