ajout dans game_ext de can_undo et can_redo et correction de model
This commit is contained in:
1 parent
64044f2868
commit
2a9d355b27
3 files changed
+20
-4
No files matched your search
+16
-2
@@ -59,7 +59,7 @@ bool game_is_wrapping(cgame g) {
|
||||
|
||||
void game_undo(game g) {
|
||||
// check if g->hist is not empty or if it is possible to undo
|
||||
if (g->hist == NULL || history_is_empty(history_prev(g->hist))) {
|
||||
if (!can_undo(g)) {
|
||||
printf("you are at your first move\n");
|
||||
} else {
|
||||
square tmp = game_get_state(g, history_i(g->hist), history_j(g->hist));
|
||||
@@ -70,9 +70,16 @@ void game_undo(game g) {
|
||||
}
|
||||
}
|
||||
|
||||
bool can_undo(game g) {
|
||||
if (g->hist == NULL || history_is_empty(history_prev(g->hist))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void game_redo(game g) {
|
||||
// check if g->hist is not empty or if it is possible to redo
|
||||
if (g->hist == NULL || history_next(g->hist) == NULL) {
|
||||
if (!can_redo(g)) {
|
||||
printf("you are at your last move\n");
|
||||
} else {
|
||||
g->hist = history_next(g->hist);
|
||||
@@ -81,4 +88,11 @@ void game_redo(game g) {
|
||||
game_update_flags(g);
|
||||
g->hist->state = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
bool can_redo(game g) {
|
||||
if (g->hist == NULL || history_next(g->hist) == NULL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -85,6 +85,8 @@ void game_undo(game g);
|
||||
**/
|
||||
void game_redo(game g);
|
||||
|
||||
bool can_undo(game g);
|
||||
bool can_redo(game g);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -547,14 +547,14 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e) {
|
||||
env->pressed_redo = false;
|
||||
env->pressed_solve = false;
|
||||
} else if (SDL_PointInRect(&mouse, env->rec_undo)) {
|
||||
if (!(env->g->hist == NULL || history_is_empty(history_prev(env->g->hist)))) {
|
||||
if (can_undo(env->g)) {
|
||||
env->pressed_undo = true;
|
||||
env->pressed_restart = false;
|
||||
env->pressed_redo = false;
|
||||
env->pressed_solve = false;
|
||||
}
|
||||
} else if (SDL_PointInRect(&mouse, env->rec_redo)) {
|
||||
if (!(env->g->hist == NULL || history_next(env->g->hist) == NULL)) {
|
||||
if (can_redo(env->g)) {
|
||||
env->pressed_redo = true;
|
||||
env->pressed_undo = false;
|
||||
env->pressed_restart = false;
|
||||
|
||||
Reference in new issue
Block a user