game new and game new empty comments + opti
This commit is contained in:
1 parent
fb0de1f20d
commit
76cc227c23
1 file changed
+5
-6
@@ -18,8 +18,7 @@ game game_new_empty(void) {
|
|||||||
// alloc struct
|
// alloc struct
|
||||||
game g = (game)malloc(sizeof(struct game_s));
|
game g = (game)malloc(sizeof(struct game_s));
|
||||||
if (g == NULL) {
|
if (g == NULL) {
|
||||||
fprintf(stderr, "not enough memory\n");
|
memoryError();
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
// set variable of struct
|
// set variable of struct
|
||||||
g->wrapping = false;
|
g->wrapping = false;
|
||||||
@@ -29,22 +28,22 @@ game game_new_empty(void) {
|
|||||||
// alloc the tab with variables set before
|
// alloc the tab with variables set before
|
||||||
g->tab_cell = (square**)malloc(sizeof(square*) * g->height);
|
g->tab_cell = (square**)malloc(sizeof(square*) * g->height);
|
||||||
if (g->tab_cell == NULL) {
|
if (g->tab_cell == NULL) {
|
||||||
fprintf(stderr, "not enough memory\n");
|
memoryError();
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < g->height; i++) {
|
for (int i = 0; i < g->height; i++) {
|
||||||
g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width);
|
g->tab_cell[i] = (square*)malloc(sizeof(square) * g->width);
|
||||||
if (g->tab_cell[i] == NULL) {
|
if (g->tab_cell[i] == NULL) {
|
||||||
fprintf(stderr, "not enough memory\n");
|
memoryError();
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
for (int j = 0; j < g->width; j++) {
|
for (int j = 0; j < g->width; j++) {
|
||||||
g->tab_cell[i][j] = S_BLANK;
|
g->tab_cell[i][j] = S_BLANK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// init history with an cell (if there is only this cell we consider the history as empty)
|
||||||
g->hist = history_insert_first(g->hist, F_ERROR, 0, 0);
|
g->hist = history_insert_first(g->hist, F_ERROR, 0, 0);
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
game game_copy(cgame g1) {
|
game game_copy(cgame g1) {
|
||||||
game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping);
|
game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping);
|
||||||
for (int i = 0; i < g2->height; i++) {
|
for (int i = 0; i < g2->height; i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user