First commit 16/08/1996
This commit is contained in:
143
MINAS.CPP
Normal file
143
MINAS.CPP
Normal file
@ -0,0 +1,143 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int matriz[12][12];
|
||||
int i,j,x,y,c=0,c1=0,fin=0;
|
||||
|
||||
clrscr();
|
||||
textcolor(5);
|
||||
//inicializacion de variables
|
||||
|
||||
for(i=0;i<12;i++)
|
||||
{
|
||||
for(j=0;j<12;j++)
|
||||
{
|
||||
matriz[i][j]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//introduccion de minas al azar
|
||||
|
||||
randomize();
|
||||
i=0;
|
||||
while(i<10)
|
||||
{
|
||||
x=(rand() %9)+1;
|
||||
y=(rand() %9)+1;
|
||||
if(matriz[x][y]!=1)
|
||||
{
|
||||
matriz[x][y]=1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//muestra matriz
|
||||
|
||||
for(i=4;i<24;i=i+2)
|
||||
{
|
||||
for(j=4;j<24;j=j+2)
|
||||
{
|
||||
gotoxy(abs(j/2)*2,abs(i/2));
|
||||
cprintf("*");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// pone coordenada
|
||||
|
||||
gotoxy(1,1);
|
||||
cprintf("b a1 2 3 4 5 6 7 8 9 10");
|
||||
for(i=1;i<11;i++)
|
||||
{
|
||||
gotoxy(1,i+1);
|
||||
cprintf("%d",i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// introduce coordenada
|
||||
|
||||
gotoxy(1,20);
|
||||
printf("introduzca coordenada[a,b]:");
|
||||
while((c1<90)&&(fin==0))
|
||||
{
|
||||
x=0;y=0;
|
||||
while(((x<1)||(x>10))||((y<1)||(y>10)))
|
||||
{
|
||||
gotoxy(28,20);
|
||||
scanf("%d,%d",&x,&y);
|
||||
gotoxy(28,20);
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
|
||||
//comprueba si ya existe
|
||||
if(matriz[x][y]==2)
|
||||
{
|
||||
gotoxy(1,22);
|
||||
printf("coordenada ya introducida(pulse una tecla)");
|
||||
getch();
|
||||
gotoxy(1,22);
|
||||
printf(" ");
|
||||
}
|
||||
else if(matriz[x][y]!=1) c1++;
|
||||
|
||||
//comprueba las minas de alrededor
|
||||
|
||||
if(matriz[x][y]==1) fin=1;
|
||||
else matriz[x][y]=2;
|
||||
|
||||
for(i=x-1;i<x+2;i++)
|
||||
{
|
||||
for(j=y-1;j<y+2;j++)
|
||||
{
|
||||
if (matriz[i][j]==1)
|
||||
{
|
||||
c=c+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
gotoxy(x*2+2,y+1);
|
||||
printf("%d",c);
|
||||
c=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//resolucion final
|
||||
|
||||
|
||||
textcolor(2);
|
||||
for(i=1;i<11;i++)
|
||||
{
|
||||
for(j=1;j<11;j++)
|
||||
if(matriz[i][j]==1)
|
||||
{
|
||||
gotoxy(i*2+2,j+1);
|
||||
cprintf("B");
|
||||
}
|
||||
}
|
||||
getch();
|
||||
clrscr();
|
||||
if(c1==90)
|
||||
printf("has ganado");
|
||||
else
|
||||
printf("has perdido");
|
||||
printf("\npresiona una tecla para volver a jugar");
|
||||
getch();
|
||||
}
|
||||
|
Reference in New Issue
Block a user