Jordiiii te pillé jajajaja, suerte con esto!
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menúcase 2:
while(i>=51 && j>=51){
if (matriu[i][j]==1){
if (matriu[i][j]==matriu[i+1][j] && matriu[i][j]==matriu[i][j+1] && matriu[i][j]==matriu[i][j-1])
error=1;
break;
}
}
#include <stdio.h>
void imprimir (int matriu[50][50]);
void pelota (int matriu[50][50]);
void cambiartabla (int matriu[50][50]);
int main()
{
int num,inicio,i,j,cont=0,fila,columna,error=0;
char direccion;
int matriu[50][50]={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,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
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
while(num!=5)
{
printf("\n");
printf("Que acción desea realizar:\n");
printf("\t1.- Mostrar la tabla.\n");
printf("\t2.- Tirar una bola.\n");
printf("\t3.- Tirar 20 bolas.\n");
printf("\t4.- Cambiar la tabla.\n");
printf("\t5.- Salida.\n");
scanf("%d",&num);
switch(num)
{
case 1:
imprimir (matriu);
break;
case 2:
pelota (matriu);
break;
case 3:
printf("caso 3\n");
break;
case 4:
cambiartabla (matriu);
break;
case 5:
printf("Adios.\n");
printf("\n");
break;
default:
printf("El numero introducido no pertenece al menú, intentelo de nuevo.\n");
}
}
}
void imprimir (int matriu[50][50]){
int i,j;
for (i = 0; i < 50; i++){
for (j = 0; j < 50; j++){
if(matriu[i][j]==1)
printf("X",matriu[i][j]);
else
printf(".",matriu[i][j]);
}
printf ("\n");
}}
void pelota (int matriu[50][50]){
int inicio,i,j,cont=0;
char direccion;
do{
printf("\nIntroducir el numero de columna por el cual desea lanzar la primera bola (1-50): ");
scanf("%d",&inicio);
}while(inicio>=51);
inicio--;
do{
printf("\nEn caso de encontrarse con un obstaculo, en que direccion\n quiere que se dirija la bola, derecha (D-d) o izquierda (I-i): ");
scanf(" %c", &direccion);
}while(direccion!='D' && direccion!='d' && direccion!='I' && direccion!='i');
i=0,j=inicio,cont=2;
matriu[i][j]=cont++;
while(i<49){
if (j==-1)
matriu[i][++j]=cont++;
else if (j==50)
matriu[i][--j]=cont++;
else if (matriu[i+1][j]==0)
matriu[++i][j]=cont++;
else if (direccion=='D' || direccion=='d' && matriu[i][j+1]==0 )
matriu[i][++j]=cont++;
else if (direccion=='D' || direccion=='d' && matriu[i][j+1]==1 )
matriu[i][--j]=cont++;
else if (direccion=='I' || direccion=='i' && matriu[i][j-1]==0)
matriu[i][--j]=cont++;
else if (direccion=='I' || direccion=='i' && matriu[i][j-1]==1)
matriu[i][++j]=cont++;
}
for(i=0;i<50;i++)
{
printf("\t\t");
for(j=0;j<50;j++)
{
if(matriu[i][j]==1)
printf("X ");
else if(matriu[i][j]==0 )
printf(". ");
else
printf("%d ",matriu[i][j]-2);
}
printf("\n");
}
}
void cambiartabla (int matriu[50][50]){
int i,j,fila,columna,error=0;
char seguir;
while(seguir!=2)
{
printf("\n");
printf("Presiona 1 si quieres seguir cambiando valores.\n");
printf("Presiona 2 si quieres ver la tabla.\n");
scanf("%d",&seguir);
switch(seguir)
{
case 1:
do{
printf("\nIntroducir la fila del valor que quieres cambiar (1-50): ");
scanf("%d",&columna);
printf("\nIntroducir la columna del valor que quieres cambiar (1-50): ");
scanf("%d",&fila);
}while(columna>=51 && fila>=51);
break;
default:
printf("El numero introducido es incorrecto.\n");
}
}
i=columna,j=fila;
if (matriu[i][j] == 0)
matriu[i][j] == 1;
else matriu[i][j] = 0;
while(i<49){
if (matriu[i+1][j]==1 && matriu[i-1][j]==1 && matriu[i][j-1]==1)
printf("ERROR");
error=1;
break;
}
for(i=0;i<50;i++)
{
printf("\t\t");
for(j=0;j<50;j++)
{
if(matriu[i][j]==1)
printf("X");
else if(matriu[i][j]==0 )
printf(".");
}
printf("\n");
}
}
void cambiartabla (int matriu[50][50]){
int i,j,fila,columna,error=0;
char seguir;
while(seguir!=2)
{
printf("\n");
printf("Presiona 1 si quieres seguir cambiando valores.\n");
printf("Presiona 2 si quieres ver la tabla.\n");
scanf("%d",&seguir);
switch(seguir)
{
case 1:
do{
printf("\nIntroducir la fila del valor que quieres cambiar (1-50): ");
scanf("%d",&columna);
printf("\nIntroducir la columna del valor que quieres cambiar (1-50): ");
scanf("%d",&fila);
}while(columna>=51 && fila>=51);
break;
default:
printf("El numero introducido es incorrecto.\n");
}
}
i=columna,j=fila;
if (matriu[i][j] = 0)
matriu[i][j] = 1;
else matriu[i][j] = 0;
while(i<49){
if (matriu[i+1][j]==1 && matriu[i-1][j]==1 && matriu[i][j-1]==1)
printf("ERROR");
error=1;
break;
}
for(i=0;i<50;i++)
{
printf("\t\t");
for(j=0;j<50;j++)
{
if(matriu[i][j]==1)
printf("X");
else if(matriu[i][j]==0 )
printf(".");
}
printf("\n");
}
}
i=columna,j=fila;
if (matriu[i][j] = 0)
matriu[i][j] = 1;
else matriu[i][j] = 0;
do{
printf("\nIntroducir el numero de columna por el cual desea lanzar la primera bola: ");
scanf("%d",&inicio);
}while(inicio>=9);
do{
printf("\nEn caso de encontrarse con un obstaculo, en que direccion quiere que se dirija la bola, derecha (D) o izquierda (I): ");
fflush(stdin);
scanf("%c", &direccion);
}while(direccion!='D' && direccion!='d' && direccion!='I' && direccion!='i');
inicio=matriu[0][inicio];
contador=0;
while(i++){
contador +=1;
}
for(i=0;i<10;i++)
{
printf("\t");
for(j=0;j<10;j++)
{
//if(matriu[i][j]==matriu[0][inicio])
// printf("%d ",contador);
if(matriu[i][j]==1)
printf("X ");
else
{
if(matriu[i][j] == matriu[i][inicio])
printf("&d",contador");
else (matriu[i][j]==0 && matriu[i][j]==0 != matriu[i][inicio])
printf(". ");
}}printf("\n");
}
contador=0;
while(i++){
contador +=1;
}
}