Skip to content
Snippets Groups Projects
Commit 545b5540 authored by remi.greub's avatar remi.greub
Browse files

correction (inverser height et width)

parent edcbea33
Branches
No related tags found
No related merge requests found
......@@ -13,13 +13,13 @@ grid game;
* et alloue la mémoire dynamiquement
***********************************/
struct cell **Create_grid2D(){
struct cell** cells = malloc(game.height*sizeof(struct cell*));
for(int k =0; k<game.height; k++){
cells[k] = malloc(game.width*sizeof(struct cell));
struct cell** cells = malloc(game.width*sizeof(struct cell*));
for(int k =0; k<game.width; k++){
cells[k] = malloc(game.height*sizeof(struct cell));
}
//initialise les positions et les valeurs de base
for(int i = 0; i<game.height; i++){
for(int j=0; j<game.width; j++){
for(int i = 0; i<game.width; i++){
for(int j=0; j<game.height; j++){
cells[i][j].pressed = false;
cells[i][j].symbol = EMPTY;
cells[i][j].i_pos = i;
......@@ -30,8 +30,8 @@ struct cell **Create_grid2D(){
}
void print_cells(struct cell **cell){
for(int i=0; i<game.height; i++){
for(int j=0; j<game.width; j++){
for(int i=0; i<game.width; i++){
for(int j=0; j<game.height; j++){
printf("%d, ", cell[i][j].symbol);
}
printf("\n");
......@@ -91,7 +91,7 @@ int is_cell_free(int j_p, int i, symbol_t symbol){
//retourne la ligne disponible
return i;
}else{
if(i<(game.width-1)){
if(i<(game.height-1)){
return is_cell_free(j_p, i+1, symbol);
}else{
printf("il n'y a plus de case de disponible sur cette colonne\n");
......@@ -108,13 +108,13 @@ int Launch_puissance4(){
//print_grille();
print_gameCells();
printf("au tour de %d de jouer\n", game.curr_player);
printf("balance un chiffre entre 0 et %d\n", game.height-1);
printf("balance un chiffre entre 0 et %d\n", game.width-1);
do{
scanf("%d",&chiffre);
if(chiffre >= game.height || chiffre < 0){
if(chiffre >= game.width || chiffre < 0){
printf("HEP HEPHEP !! donne un chiffre dans la plage donnee manche a couille\n");
}
}while((chiffre >= game.height) || (chiffre < 0) || is_cell_free(chiffre, 0, game.players[game.curr_player].symbol)<0);
}while((chiffre >= game.width) || (chiffre < 0) || is_cell_free(chiffre, 0, game.players[game.curr_player].symbol)<0);
game.gamePlayed -= 1; //peut être le mettre plus bas non ?
int i = 0;
......@@ -235,7 +235,7 @@ symbol_t CheckWin_in_a_direction(int dir[2], struct cell **grid, struct cell cel
int x2 = cell.j_pos+dir[1];
symbol_t result = EMPTY;
if(x1<game.height && x1>=0 && x2<game.width && x2>=0){
if(x1<game.width && x1>=0 && x2<game.height && x2>=0){
if(grid[x1][x2].symbol==cell.symbol){
if(cell.symbol == CIRCLE){
game.players[0].check_win += 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment