home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume12
/
saa
/
patch1
/
patches01
Wrap
Text File
|
1991-08-16
|
9KB
|
308 lines
*** saa.c.orig Thu Jun 13 06:37:54 1991
--- saa.c Thu Jun 13 06:51:08 1991
Prereq: 1.1
***************
*** 1,5 ****
/* Streets and Alleys */
! /* This is saa.c version 1.1 of 91/05/17. */
/* Streets and Alleys is a game of solitaire. This implementation is
in ANSI C and uses the curses package. You can play games with less
--- 1,5 ----
/* Streets and Alleys */
! /* This is saa.c version 1.2 of 91/06/13. */
/* Streets and Alleys is a game of solitaire. This implementation is
in ANSI C and uses the curses package. You can play games with less
***************
*** 14,20 ****
software for any purpose. It is provided "as is" without express or
implied warranty. */
! static char what[] = "@(#)saa.c 1.1";
/* If your machine does not have an ANSI C compiler, but it does have
the curses package, there is a good chance you can get this program
--- 14,20 ----
software for any purpose. It is provided "as is" without express or
implied warranty. */
! static char what[] = "@(#)saa.c 1.2";
/* If your machine does not have an ANSI C compiler, but it does have
the curses package, there is a good chance you can get this program
***************
*** 260,266 ****
#define board_height 19
#define title_height 1
! #define stack_indent 12
#define card_size 6
int prompt_row, status_row, command_row, board_row, title_row;
--- 260,266 ----
#define board_height 19
#define title_height 1
! #define stack_indent 11
#define card_size 6
int prompt_row, status_row, command_row, board_row, title_row;
***************
*** 351,357 ****
addch(',');
}
goto_stack_top(8, 0);
! addstr("q, r, or ?.");
move(status_row, 0);
addstr("Status:");
clear_status();
--- 351,357 ----
addch(',');
}
goto_stack_top(8, 0);
! addstr("q, r, s, or ?.");
move(status_row, 0);
addstr("Status:");
clear_status();
***************
*** 362,368 ****
}
char *help[] = {
! "\tStreets and Alleys version 1.1\n\n",
"There are eight stacks of cards and a foundation for each suit. A\n",
"card may be moved from the top of a stack to its foundation or to\n",
"the top of another stack. The object of the game is to order the\n",
--- 362,368 ----
}
char *help[] = {
! "\tStreets and Alleys version 1.2\n\n",
"There are eight stacks of cards and a foundation for each suit. A\n",
"card may be moved from the top of a stack to its foundation or to\n",
"the top of another stack. The object of the game is to order the\n",
***************
*** 375,387 ****
"card of the stack has rank one greater than the card being moved. A\n",
"card can always be moved to an empty stack.\n",
"\n",
! "Commands:\n",
"\n",
! " 0\tSelect a foundation.\n",
! " 1-8\tSelect a stack.\n",
! " q\tQuit the game.\n",
! " r\tRefresh the display.\n",
! " ?\tPrint this help.\n",
};
int show_help()
--- 375,388 ----
"card of the stack has rank one greater than the card being moved. A\n",
"card can always be moved to an empty stack.\n",
"\n",
! "Commands:\t\t\t\tCommand Aliases:\n",
"\n",
! " 0\tSelect a foundation.\t\t <space> = 0,\n",
! " 1-8\tSelect a stack.\t\t\t j = 1, k = 2, l = 3, ; = 4,\n",
! " q\tQuit the game.\t\t\t u = 5, i = 6, o = 7, p = 8.\n",
! " r\tRestore a game from a file.\n",
! " s\tSave a game in a file.\n",
! " ?\tPrint this help and then refresh screen.\n",
};
int show_help()
***************
*** 397,402 ****
--- 398,517 ----
return show_game();
}
+ /* Byron Burke suggested adding the ability to save and restore games,
+ so you could save a game, try some things, and restore the game if
+ things didn't work. Thanks Byron. */
+
+ #if !defined SAVE_FILE_NAME
+ #define SAVE_FILE_NAME "saa.sav"
+ #endif
+
+ #if !defined MAGIC_NUMBER
+ #define MAGIC_NUMBER 13921
+ #endif
+
+ int bad_read(f)
+ FILE *f;
+ {
+ addstr("Restore error: Read error.");
+ fclose(f);
+ return 1; /* generate new game. */
+ }
+
+ int restore_game()
+ {
+ int i;
+ FILE *f;
+ clear_status();
+ clear_prompt();
+ addstr("Type space to restore game in file ");
+ addstr(SAVE_FILE_NAME);
+ addstr(". ");
+ refresh();
+ clear_status();
+ if (' ' != getch()) {
+ addstr("The restoration of the old game was aborted.");
+ return 0;
+ }
+ if (NULL == (f = fopen(SAVE_FILE_NAME, "r"))) {
+ addstr("Restore error: Cannot open ");
+ addstr(SAVE_FILE_NAME);
+ addstr(". Game not restored.");
+ return 0;
+ }
+ if (1 != fread(&i, sizeof(int), 1, f) || i != MAGIC_NUMBER) {
+ addstr("Restore error: Bad save file format.");
+ fclose(f);
+ return 0;
+ }
+ free_list_init(); /* read cards. */
+ if (1 != fread(&cards, sizeof(int), 1, f)) return bad_read(f);
+ for (i = 0; i < nsuits; i++) /* read foundations. */
+ if (1 != fread(board.foundation + i, sizeof(card_t), 1, f))
+ return bad_read(f);
+ for (i = 0; i < nstacks; i++) { /* read stacks. */
+ int len;
+ if (1 != fread(&len, sizeof(int), 1, f)) return bad_read(f);
+ board.stack[i] = NIL;
+ for (; len > 0; len--) {
+ card_t c;
+ if (1 != fread(&c, sizeof(card_t), 1, f)) return bad_read(f);
+ push_card(c, i);
+ }
+ }
+ fclose(f);
+ return show_game();
+ }
+
+ int bad_write()
+ {
+ addstr("Save error: Write failed. Game not saved.");
+ return 0;
+ }
+
+ int save_game()
+ {
+ int i;
+ FILE *f;
+ card_t stack[board_height];
+ clear_status();
+ clear_prompt();
+ addstr("Type space to save game in file ");
+ addstr(SAVE_FILE_NAME);
+ addstr(". ");
+ refresh();
+ clear_status();
+ if (' ' != getch()) {
+ addstr("The saving of the game was aborted.");
+ return 0;
+ }
+ if (NULL == (f = fopen(SAVE_FILE_NAME, "w"))) {
+ addstr("Save error: Cannot open ");
+ addstr(SAVE_FILE_NAME);
+ addstr(". Game not saved.");
+ return 0;
+ }
+ i = MAGIC_NUMBER;
+ if (1 != fwrite(&i, sizeof(int), 1, f)) return bad_write();
+ if (1 != fwrite(&cards, sizeof(cards), 1, f)) return bad_write();
+ for (i = 0; i < nsuits; i++) /* write foundations. */
+ if (1 != fwrite(board.foundation + i, sizeof(card_t), 1, f))
+ return bad_write();
+ for (i = 0; i < nstacks; i++) { /* write stacks. */
+ card_list_t list = board.stack[i];
+ int j = 0;
+ for (; list != NIL; list = list->rest, j++)
+ stack[j] = list->card;
+ if (1 != fwrite(&j, sizeof(int), 1, f)) return bad_write();
+ for (j--; j >= 0; j--)
+ if (1 != fwrite(stack + j, sizeof(card_t), 1, f))
+ return bad_write();
+ }
+ fclose(f);
+ addstr("Game saved.");
+ return 0;
+ }
+
int is_stack_done(p)
int p;
{
***************
*** 469,474 ****
--- 584,606 ----
return 0;
}
+ int getcmd() /* Implements aliases for commands. */
+ {
+ int c = getch();
+ switch (c) {
+ case ' ': return '0'; /* Aliases for use when there is no */
+ case 'j': return '1'; /* numeric keypad. */
+ case 'k': return '2';
+ case 'l': return '3';
+ case ';': return '4';
+ case 'u': return '5';
+ case 'i': return '6';
+ case 'o': return '7';
+ case 'p': return '8';
+ default: return c;
+ }
+ }
+
int get_other_move(from)
int from;
{
***************
*** 480,488 ****
addch(from+'1');
addstr(" to ");
refresh();
! to = getch();
if (to == EOF || to == 'q') return 1;
! if (to == 'r') return show_game();
if (to == '?') return show_help();
to -= '1';
clear_status();
--- 612,621 ----
addch(from+'1');
addstr(" to ");
refresh();
! to = getcmd();
if (to == EOF || to == 'q') return 1;
! if (to == 'r') return restore_game();
! if (to == 's') return save_game();
if (to == '?') return show_help();
to -= '1';
clear_status();
***************
*** 500,508 ****
clear_prompt();
addstr("Move from stack ");
refresh();
! from = getch();
if (from == EOF || from == 'q') return 1;
! if (from == 'r') return show_game();
if (from == '?') return show_help();
from -= '1';
if (from < 0 || from >= 8) {
--- 633,642 ----
clear_prompt();
addstr("Move from stack ");
refresh();
! from = getcmd();
if (from == EOF || from == 'q') return 1;
! if (from == 'r') return restore_game();
! if (from == 's') return save_game();
if (from == '?') return show_help();
from -= '1';
if (from < 0 || from >= 8) {