patch + update game_text

This commit is contained in:
Théophyl Hoguet committed 2021-12-23 14:15:47 +01:00
1 parent 3839e59097
commit bec7cbdc10
5 files changed
+17 -9

No files matched your search

+4 -4
View File
@@ -162,15 +162,15 @@ bool game_check_move(cgame g, uint i, uint j, square s) {
} }
void game_play_move(game g, uint i, uint j, square s) { void game_play_move(game g, uint i, uint j, square s) {
game_set_square(g, i, j, s);
game_update_flags(g);
if (g->hist == NULL) { if (g->hist == NULL) {
g->hist = history_create_empty(); g->hist = history_create_empty();
g->hist = history_insert_first(g->hist, s, i, j); g->hist = history_insert_first(g->hist, game_get_square(g, i, j), i, j);
} else { } else {
g->hist = history_next(history_insert_after(g->hist, g->hist, s, i, j)); g->hist = history_next(history_insert_after(g->hist, g->hist, game_get_square(g, i, j), i, j));
g->hist = history_delete_all_after(g->hist, g->hist); g->hist = history_delete_all_after(g->hist, g->hist);
} }
game_set_square(g, i, j, s);
game_update_flags(g);
} }
void delete_flags(game g) { void delete_flags(game g) {
+2 -3
View File
@@ -57,7 +57,7 @@ bool game_is_wrapping(cgame g) {
void game_undo(game g) { void game_undo(game g) {
if (history_prev(g->hist) == NULL) { if (history_prev(g->hist) == NULL) {
printf("waiting for your first move"); printf("waiting for your first move\n");
} else { } else {
game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist))); 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); game_update_flags(g);
@@ -68,8 +68,7 @@ void game_undo(game g) {
void game_redo(game g) { void game_redo(game g) {
if (history_next(g->hist) == NULL) { if (history_next(g->hist) == NULL) {
printf("waiting for you to undo first"); printf("waiting for you to undo first");
} } else {
else{
game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist))); game_set_square(g, history_i(history_next(g->hist)), history_j(history_next(g->hist)), history_state(history_next(g->hist)));
game_update_flags(g); game_update_flags(g);
g->hist = history_next(g->hist); g->hist = history_next(g->hist);
+1
View File
@@ -5,6 +5,7 @@
#include <string.h> #include <string.h>
#include "game.h" #include "game.h"
#include "game_aux.h" #include "game_aux.h"
#include "game_ext.h"
bool test_dummy(void) { bool test_dummy(void) {
return true; return true;
+8
View File
@@ -40,6 +40,8 @@ void printhelp(void) {
printf("h : Affiche cette aide.\n"); printf("h : Affiche cette aide.\n");
printf("r : Réinitialise la partie.\n"); printf("r : Réinitialise la partie.\n");
printf("q : Quitter la partie (abandon).\n"); printf("q : Quitter la partie (abandon).\n");
printf("z : Annulez le coup (undo).\n");
printf("y : Annulez l'annulation du coup (redo).\n");
printf( printf(
"l <i> <j> : Place une ampoule (*light bulb*) dans la case " "l <i> <j> : Place une ampoule (*light bulb*) dans la case "
"(<i>,<j>).\n"); "(<i>,<j>).\n");
@@ -80,6 +82,12 @@ int main(void) {
game_delete(g); game_delete(g);
printf("shame\n"); printf("shame\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else if (c == 'z') {
game_undo(g);
game_print(g);
} else if (c == 'y') {
game_redo(g);
game_print(g);
} else if (c == 'l' || c == 'm' || c == 'b') { } else if (c == 'l' || c == 'm' || c == 'b') {
if (scanf(" %u %u", &i, &j) == 2) { if (scanf(" %u %u", &i, &j) == 2) {
if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB))
+2 -2
View File
@@ -54,13 +54,13 @@ square history_state(history h) {
return h->state; return h->state;
} }
square history_i(history h) { uint history_i(history h) {
if (history_is_empty(h)) if (history_is_empty(h))
errPointer(); errPointer();
return h->i; return h->i;
} }
square history_j(history h) { uint history_j(history h) {
if (history_is_empty(h)) if (history_is_empty(h))
errPointer(); errPointer();
return h->j; return h->j;