Code:
#include <stdio.h>
#define DIM 9
int menu();
int start(int jogo[][DIM], char num[][DIM]);
void whoosh();
void set(int jogo[][DIM]);
void show(int jogo[][DIM], char num[][DIM]);
main()
{
int startpoint;
int jogo[DIM][DIM] = {{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,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}};
char num[DIM][DIM] = {{'0', '1', '1', '2', 'X', '2', '1', '1', '0'}, {'1', '2', 'X', '2', '1', '2', 'X', '2', '1'}, {'X', '2', '1', '1', '0', '1', '1', '2', 'X'}, {'1', '1', '0', '0', '0','0', '0', '1', '1'}, {'1', '1', '2', '1', '1', '0', '0', '0', '0'}, {'1', 'X', '2', 'X', '2', '1', '1', '0', '0'}, {'1', '1', '2', '1', '3', 'X', '2', '0', '0'}, {'0', '1', '1', '1', '2', 'X', '2', '0', '0'}, {'0', '1', 'X', '1', '1', '1', '1', '0', '0'}};
do
{
startpoint = menu();
if(startpoint == 1)
start(jogo, num);
}
while(startpoint!=2);
return 0;
}
int menu()
{
int valor;
printf("\tCAMPO MINADO\n\nDigite um numero:\n1: JOGAR\n2: SAIR\n\n");
scanf("%d", &valor);
switch(valor)
{
case 1:
case 2:
break;
default:
whoosh;
printf("Numero invalido\n");
}
return valor;
}
start(int jogo[][DIM], char num[][DIM])
{
int x, y;
int gameOver = 0;
while(gameOver==0)
{
set(jogo);
whoosh();
show(jogo, num);
do
{
printf("Linha: ");
scanf("%d", &x);
printf("Coluna: ");
scanf("%d", &y);
if(x<1 || y<1 || x>9 || y>9)
printf("Posicao invalida\n\n");}
while(x<1 || y<1 || x>9 || y>9);
}
jogo[x--][y--]=1;
if (gameOver==1)
{printf("Voce ganhou!");
return 0;}
else
{
printf("Voce perdeu");
return 0;
}
}
void whoosh()
{
int i;
for (i=0;i<100;i++)
putchar('\n');
}
void set(int jogo[][DIM])
{
int x, y;
for(x=0;x<DIM;x++)
for(y=0;y<DIM;y++)
jogo[x][y] = 0;
}
void show(int jogo[DIM][DIM], char num[DIM][DIM])
{
int x, y;
printf("-------------------\n");
for(x=0;x<DIM;x++)
{for(y=0;y<DIM;y++)
{
if (y==DIM-DIM)
printf("|");
if(jogo[x][y]==0)
printf(" ");
else
printf("%c", num[x][y]);
printf("|");
if(y==DIM-1)
printf("\n-------------------\n");}
}
putchar('\n');
}
The printed text is in Portuguese because it's my native language, but the point is after the player inputs the coordinates, their value is supposed to change from 0 to 1 so the squares open when the show function runs, but none of the contents of the squares are showing, so I think the values aren't changing. What am I doing wrong?