patch + update game_text
This commit is contained in:
1 parent
3839e59097
commit
bec7cbdc10
5 files changed
+22
-14
No files matched your search
@@ -56,7 +56,7 @@ game game_copy(cgame g1) {
|
|||||||
for (int j = 0; j < g2->width; j++) {
|
for (int j = 0; j < g2->width; j++) {
|
||||||
g2->tab_cell[i][j] = g1->tab_cell[i][j];
|
g2->tab_cell[i][j] = g1->tab_cell[i][j];
|
||||||
}
|
}
|
||||||
//g2->hist = history_copy(g1);
|
// g2->hist = history_copy(g1);
|
||||||
}
|
}
|
||||||
return g2;
|
return g2;
|
||||||
}
|
}
|
||||||
@@ -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) {
|
||||||
|
|||||||
+3
-4
@@ -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);
|
||||||
@@ -66,10 +66,9 @@ 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);
|
||||||
|
|||||||
+4
-3
@@ -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;
|
||||||
@@ -360,7 +361,7 @@ bool test_game_has_error(void) {
|
|||||||
/* ************** game_nb_rows ************** */
|
/* ************** game_nb_rows ************** */
|
||||||
bool test_game_nb_rows(void) {
|
bool test_game_nb_rows(void) {
|
||||||
game g = game_new_empty();
|
game g = game_new_empty();
|
||||||
if (game_nb_rows(g) != g->height){
|
if (game_nb_rows(g) != g->height) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -369,7 +370,7 @@ bool test_game_nb_rows(void) {
|
|||||||
/* ************** game_nb_cols ************** */
|
/* ************** game_nb_cols ************** */
|
||||||
bool test_game_nb_cols(void) {
|
bool test_game_nb_cols(void) {
|
||||||
game g = game_new_empty();
|
game g = game_new_empty();
|
||||||
if (game_nb_cols(g) != g->width){
|
if (game_nb_cols(g) != g->width) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -378,7 +379,7 @@ bool test_game_nb_cols(void) {
|
|||||||
/* ************** game_is_wrapping ************** */
|
/* ************** game_is_wrapping ************** */
|
||||||
bool test_game_is_wrapping(void) {
|
bool test_game_is_wrapping(void) {
|
||||||
game g = game_new_empty();
|
game g = game_new_empty();
|
||||||
if (game_is_wrapping(g) != g->wrapping){
|
if (game_is_wrapping(g) != g->wrapping) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in new issue
Block a user