edit game copy + adding game_undo

This commit is contained in:
thibault perrier committed 2021-12-10 20:45:58 +01:00
1 parent ef565007ec
commit d70f8a3516
2 files changed
+10 -1

No files matched your search

+2 -1
View File
@@ -53,7 +53,7 @@ game game_copy(cgame g1) {
game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping);
for (int i = 0; i < g2->height; i++) {
for (int j = 0; j < g2->width; j++) {
if (g1->tab_cell[i][j] == (S_BLANK | S_LIGHTBULB | S_MARK)){
if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK){
game_play_move(g2, i, j, g1->tab_cell[i][j]);
}
else {
@@ -172,6 +172,7 @@ void game_play_move(game g, uint i, uint j, square s) {
}
else {
g->hist = history_next(history_insert_after(g->hist,g->hist,s,i,j));
g->hist = history_delete_all_after(g->hist, g->hist);
}
}
+8
View File
@@ -56,6 +56,14 @@ bool game_is_wrapping(cgame g) {
}
void game_undo(game g) {
if (history_prev(g->hist) == NULL){
printf("waiting for your first move");
}
else{
game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist)));
game_update_flags(g);
g->hist = history_prev(g->hist);
}
return;
}