1
Using a two-dimensional matrix, create a program to implement a minefield game. To fill the matrix positions, use random numbers so that 0 represents a free position and 1 represents a pump. The user must be able to make 3 mistakes. Freely chosen positions shall be marked by (ASCII 2); positions with pumps already chosen shall be marked (ASCII 15) and positions not marked shall be marked with (ASCII 63).
How do I hide the positions of the houses with the figures (ASCII 2)?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define tam 10
int matri[tam][tam];
void forma()
{
int i, e;
for(i=0; i<10; i++)
{
for(e=0; e<10; e++)
{
matri[e][i]= rand()%2;
}
}
}
void mostra()
{
int i, e;
for(i=0; i<10; i++)
{
for(e=0; e<10; e++)
{
printf("%3d",matri[e][i]);
}
printf("\n");
}
}
//
void jogar()
{
int L,C, erros=0;
char a = 2, b = 15;
do
{
printf("\n\n linha L ?");
scanf("%d", &L);
printf("\n\n coluna C ?");
scanf("%d", &C);
if(matri[L][C] = 0)
{
matri[L][C] = a;
}
else if(matri[L][C] = 1)
{
erros++;
matri[L][C] = b;
}
}
while(erros = 3);
}
int main(int argc, char *argv[])
{
forma();
mostra();
esconde();
jogar();
return 0;
}
The image you have placed is not working. Take advantage of it and explain your doubts better. What part you can’t make and what you’ve tried to make it
– Isac
image was of question question. I added
– Pedro Joao
doubt is how I hide the positions of the houses with the figures (ANCII 2)
– Pedro Joao
Separate the presentation layer from the representation layer. The logical representation of the pump should be treated as unknown terrain
– Jefferson Quesado
The problem is that it will need more logic to know what the user has already chosen. If the two-dimensional matrix has only free(0) and pumps(1), you have no way of knowing which users have already chosen to show or hide bombs
– Isac
It also helps to separate the map of explored land from the actual land. As if to apply a Fog of War same CLI
– Jefferson Quesado
try not to use code characters between 0 and 31 - they are "non-printable". Some, such as 0x0a (10) and 0x0d (13) have well-defined behavior in printing, but this is not the case for others. ASCII is 32 until 127.
– jsbueno