Some changes.
This commit is contained in:
parent
802350e051
commit
ce8400740a
15
src/game.c
15
src/game.c
@ -11,7 +11,6 @@
|
||||
#include "deck.h"
|
||||
#include "draw.h"
|
||||
#include "cursor.h"
|
||||
#include "curses.h"
|
||||
#include "common.h"
|
||||
|
||||
static int foundation_begin_x(int x) {
|
||||
@ -22,7 +21,7 @@ static int foundation_begin_x(int x) {
|
||||
case 3: return(FOUNDATION_3_BEGIN_X);
|
||||
default:
|
||||
endwin();
|
||||
end_game();
|
||||
game_end();
|
||||
assert(false && "invalid stack");
|
||||
}
|
||||
}
|
||||
@ -38,7 +37,7 @@ static int maneuvre_begin_x(int x) {
|
||||
case 6: return(MANEUVRE_6_BEGIN_X);
|
||||
default:
|
||||
endwin();
|
||||
end_game();
|
||||
game_end();
|
||||
assert(false && "maneuvre_begin_x called x < 0 || x > 6");
|
||||
}
|
||||
}
|
||||
@ -160,13 +159,9 @@ static void deal_cards(struct deck *deck) {
|
||||
}
|
||||
}
|
||||
|
||||
void initialize_game() {
|
||||
clear();
|
||||
refresh();
|
||||
|
||||
void game_init() {
|
||||
allocate_cursor(&cursor);
|
||||
initialize_cursor(cursor);
|
||||
|
||||
allocate_deck(&deck);
|
||||
initialize_deck(deck);
|
||||
|
||||
@ -188,7 +183,7 @@ void initialize_game() {
|
||||
draw_deck(deck);
|
||||
}
|
||||
|
||||
void end_game() {
|
||||
free_deck(deck);
|
||||
void game_end() {
|
||||
free_cursor(cursor);
|
||||
free_deck(deck);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ bool maneuvre_stack(struct stack *);
|
||||
bool valid_move(struct stack *, struct stack *);
|
||||
void move_card(struct stack **, struct stack **);
|
||||
void greet_player();
|
||||
void initialize_game();
|
||||
void end_game();
|
||||
void game_init();
|
||||
void game_end();
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "game.h"
|
||||
#include "cursor.h"
|
||||
#include "draw.h"
|
||||
#include "curses.h"
|
||||
|
||||
static struct stack **cursor_stack(struct cursor *cursor) {
|
||||
if (cursor->y == CURSOR_BEGIN_Y) {
|
||||
@ -20,7 +19,7 @@ static struct stack **cursor_stack(struct cursor *cursor) {
|
||||
case CURSOR_INVALID_SPOT_X: return(NULL);
|
||||
default:
|
||||
endwin();
|
||||
end_game();
|
||||
game_end();
|
||||
assert(false && "invalid stack");
|
||||
}
|
||||
} else {
|
||||
@ -34,7 +33,7 @@ static struct stack **cursor_stack(struct cursor *cursor) {
|
||||
case CURSOR_MANEUVRE_6_X: return(&(deck->maneuvre[6]));
|
||||
default:
|
||||
endwin();
|
||||
end_game();
|
||||
game_end();
|
||||
assert(false && "invalid stack");
|
||||
}
|
||||
}
|
||||
@ -122,7 +121,7 @@ static void handle_card_movement(struct cursor *cursor) {
|
||||
case 'q':
|
||||
case 'Q':
|
||||
endwin();
|
||||
end_game();
|
||||
game_end();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,14 @@ const char *program_name;
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
program_name = *argv;
|
||||
int key;
|
||||
|
||||
setlocale(LC_ALL, "en_US.utf-8"); /* Support unicode characters. */
|
||||
setlocale(LC_ALL, ""); /* Support unicode characters. */
|
||||
initscr();
|
||||
raw(); /* Disable line buffers. */
|
||||
raw(); /* Disable line buffers. */
|
||||
noecho();
|
||||
keypad(stdscr, TRUE); /* Enable arrow keys. */
|
||||
start_color(); /* I want colors. */
|
||||
curs_set(FALSE); /* Invisible cursor. */
|
||||
keypad(stdscr, TRUE); /* Give us keyboard key symbols. */
|
||||
start_color();
|
||||
curs_set(FALSE); /* We have our own cursor. */
|
||||
set_escdelay(0);
|
||||
assume_default_colors(COLOR_WHITE, COLOR_GREEN);
|
||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
||||
@ -27,27 +26,29 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
draw_greeting();
|
||||
|
||||
while (key != KEY_SPACEBAR) {
|
||||
int key;
|
||||
do {
|
||||
switch (key = getch()) {
|
||||
case KEY_SPACEBAR:
|
||||
initialize_game();
|
||||
clear();
|
||||
refresh();
|
||||
game_init();
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
endwin();
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
} while (key != KEY_SPACEBAR);
|
||||
|
||||
while (1) {
|
||||
do {
|
||||
if ((key = getch()) == 'q' || key == 'Q') {
|
||||
endwin();
|
||||
end_game();
|
||||
return(0);
|
||||
game_end();
|
||||
} else {
|
||||
handle_keyboard_event(key);
|
||||
}
|
||||
}
|
||||
} while (key != 'q' && key != 'Q');
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user