Skip to content

Commit

Permalink
read position file
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiorosa1 committed Feb 1, 2019
1 parent c3868b8 commit 0f77775
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
8 changes: 8 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ int main(int argc, char* argv[]){
// lendo cada caractere
char c = fgetc(filePointer);
if(c == '1'){
inicia_position(game,i,j,0,bomba);
j++;
//game[i][j].state =0;
//game[i][j].content = bomba;
}else if(c=='\n'){
i++;
j=0;
}else{
inicia_position(game,i,j,0,vazia);
j++;
}

// sai do loop quando eh o fim do arquivo
Expand Down
Binary file modified minesweeper
Binary file not shown.
21 changes: 14 additions & 7 deletions tGame.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ struct tgame{
};


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;
int inicia_position(tGame** g,int i,int j,int s,int c){
int valido=0; // returns 0 if successfully started the position
// // aloca espaco para a tabela e inicia os valores recebidos
// tGame* position = (tGame*) malloc(sizeof(tGame));
g[i][j].state = s;
g[i][j].state = s;
// position->state = s;
// position->content = c;

return position;
return valido;
}


Expand All @@ -31,6 +34,10 @@ tGame** inicia_tabuleiro(int sz){

tGame **tabuleiro = (tGame**) malloc(sz*sizeof(tGame*));
// alocar espaco para of ponteiros itself

tabuleiro[0] = (tGame*) malloc(sz*sizeof(tGame));
int aux=0;
for(aux=0; aux < sz; aux++){
tabuleiro[aux] = (*tabuleiro + aux);
}
return tabuleiro;
}
2 changes: 1 addition & 1 deletion tGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
typedef struct tgame tGame;

// inicia a posicao com o estado e o conteudo
tGame* inicia_tGame(int s,int c);
int inicia_position(tGame** g,int i,int j,int s,int c);

// aloca memoria para o tabuleiro
tGame** inicia_tabuleiro(int sz);
Expand Down

0 comments on commit 0f77775

Please sign in to comment.