diff --git a/Makefile b/Makefile index f7cc3ef..4c6bc20 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - gcc -Wall -o minesweeper main.c + gcc -Wall -o minesweeper main.c tGame.c clean: rm -f main diff --git a/main.c b/main.c index 4645dee..a70ced6 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,6 @@ #include +#include +#include "tGame.h" int main(int argc, char* argv[]){ @@ -44,8 +46,10 @@ int main(int argc, char* argv[]){ printf("Vazia: %c\n",vazia); printf("Table Size: %d\n",tableSize); + // teste tGame + tGame* gameTeste = inicia_tGame(1,bomba); // proximas linhas 1 bomba e 0 vazia - + printPosition(gameTeste); //imprimir Estado inicial do tabuleiro diff --git a/minesweeper b/minesweeper index 430e01a..c05831c 100755 Binary files a/minesweeper and b/minesweeper differ diff --git a/tGame.c b/tGame.c new file mode 100644 index 0000000..e68b17b --- /dev/null +++ b/tGame.c @@ -0,0 +1,28 @@ +#include +#include +#include "tGame.h" + +struct tgame{ + int state; // 0 if closed and 1 if it's already open + int content; // vazia ou bomba ou numero de bombas vizinhas +}; + + +tGame* inicia_tGame(int s,int c){ + // aloca espaco para a tabela e inicia os valores recebidos + tGame* position = (tGame*) malloc(sizeof(tGame)); + position->state = s; + position->content = c; + + return position; +} + + +void printPosition(tGame* g){ + if(g == NULL){ + printf("Invalid position\n"); + return; + } + printf("Estado: %d\n",g->state); + printf("Conteudo: %c\n",g->content); +} \ No newline at end of file diff --git a/tGame.h b/tGame.h new file mode 100644 index 0000000..cf9693b --- /dev/null +++ b/tGame.h @@ -0,0 +1,17 @@ +#ifndef HEAP_H +#define TGAME_H + +// for lack of a better name +// this holds the state of each position +typedef struct tgame tGame; + +// inicia a posicao com o estado e o conteudo +tGame* inicia_tGame(int s,int c); + +// prints a specific position +void printPosition(tGame* g); + +// desaloca memoria alocada de uma tGame +void freePosition(tGame* g); + +#endif /* TGAME_H */ \ No newline at end of file