home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume12 / saa / patch1 / patches01
Text File  |  1991-08-16  |  9KB  |  308 lines

  1. *** saa.c.orig    Thu Jun 13 06:37:54 1991
  2. --- saa.c    Thu Jun 13 06:51:08 1991
  3. Prereq: 1.1
  4. ***************
  5. *** 1,5 ****
  6.   /* Streets and Alleys */
  7. ! /* This is saa.c version 1.1 of 91/05/17. */
  8.   
  9.   /* Streets and Alleys is a game of solitaire.  This implementation is
  10.   in ANSI C and uses the curses package.  You can play games with less
  11. --- 1,5 ----
  12.   /* Streets and Alleys */
  13. ! /* This is saa.c version 1.2 of 91/06/13. */
  14.   
  15.   /* Streets and Alleys is a game of solitaire.  This implementation is
  16.   in ANSI C and uses the curses package.  You can play games with less
  17. ***************
  18. *** 14,20 ****
  19.   software for any purpose.  It is provided "as is" without express or
  20.   implied warranty.  */
  21.   
  22. ! static char what[] = "@(#)saa.c    1.1";
  23.   
  24.   /* If your machine does not have an ANSI C compiler, but it does have
  25.   the curses package, there is a good chance you can get this program
  26. --- 14,20 ----
  27.   software for any purpose.  It is provided "as is" without express or
  28.   implied warranty.  */
  29.   
  30. ! static char what[] = "@(#)saa.c    1.2";
  31.   
  32.   /* If your machine does not have an ANSI C compiler, but it does have
  33.   the curses package, there is a good chance you can get this program
  34. ***************
  35. *** 260,266 ****
  36.   #define board_height 19
  37.   #define title_height 1
  38.   
  39. ! #define stack_indent 12
  40.   #define card_size 6
  41.   
  42.   int prompt_row, status_row, command_row, board_row, title_row;
  43. --- 260,266 ----
  44.   #define board_height 19
  45.   #define title_height 1
  46.   
  47. ! #define stack_indent 11
  48.   #define card_size 6
  49.   
  50.   int prompt_row, status_row, command_row, board_row, title_row;
  51. ***************
  52. *** 351,357 ****
  53.       addch(',');
  54.     }
  55.     goto_stack_top(8, 0);
  56. !   addstr("q, r, or ?.");
  57.     move(status_row, 0);
  58.     addstr("Status:");
  59.     clear_status();
  60. --- 351,357 ----
  61.       addch(',');
  62.     }
  63.     goto_stack_top(8, 0);
  64. !   addstr("q, r, s, or ?.");
  65.     move(status_row, 0);
  66.     addstr("Status:");
  67.     clear_status();
  68. ***************
  69. *** 362,368 ****
  70.   }
  71.   
  72.   char *help[] = {
  73. !   "\tStreets and Alleys version 1.1\n\n",
  74.     "There are eight stacks of cards and a foundation for each suit.  A\n",
  75.     "card may be moved from the top of a stack to its foundation or to\n",
  76.     "the top of another stack.  The object of the game is to order the\n",
  77. --- 362,368 ----
  78.   }
  79.   
  80.   char *help[] = {
  81. !   "\tStreets and Alleys version 1.2\n\n",
  82.     "There are eight stacks of cards and a foundation for each suit.  A\n",
  83.     "card may be moved from the top of a stack to its foundation or to\n",
  84.     "the top of another stack.  The object of the game is to order the\n",
  85. ***************
  86. *** 375,387 ****
  87.     "card of the stack has rank one greater than the card being moved.  A\n",
  88.     "card can always be moved to an empty stack.\n",
  89.     "\n",
  90. !   "Commands:\n",
  91.     "\n",
  92. !   "  0\tSelect a foundation.\n",
  93. !   "  1-8\tSelect a stack.\n",
  94. !   "  q\tQuit the game.\n",
  95. !   "  r\tRefresh the display.\n",
  96. !   "  ?\tPrint this help.\n",
  97.   };
  98.     
  99.   int show_help()
  100. --- 375,388 ----
  101.     "card of the stack has rank one greater than the card being moved.  A\n",
  102.     "card can always be moved to an empty stack.\n",
  103.     "\n",
  104. !   "Commands:\t\t\t\tCommand Aliases:\n",
  105.     "\n",
  106. !   "  0\tSelect a foundation.\t\t  <space> = 0,\n",
  107. !   "  1-8\tSelect a stack.\t\t\t  j = 1, k = 2, l = 3, ; = 4,\n",
  108. !   "  q\tQuit the game.\t\t\t  u = 5, i = 6, o = 7, p = 8.\n",
  109. !   "  r\tRestore a game from a file.\n",
  110. !   "  s\tSave a game in a file.\n",
  111. !   "  ?\tPrint this help and then refresh screen.\n",
  112.   };
  113.     
  114.   int show_help()
  115. ***************
  116. *** 397,402 ****
  117. --- 398,517 ----
  118.     return show_game();
  119.   }
  120.   
  121. + /* Byron Burke suggested adding the ability to save and restore games,
  122. + so you could save a game, try some things, and restore the game if
  123. + things didn't work.  Thanks Byron.  */
  124. + #if !defined SAVE_FILE_NAME
  125. + #define SAVE_FILE_NAME "saa.sav"
  126. + #endif
  127. + #if !defined MAGIC_NUMBER
  128. + #define MAGIC_NUMBER 13921
  129. + #endif
  130. + int bad_read(f)
  131. +      FILE *f;
  132. + {
  133. +   addstr("Restore error: Read error.");
  134. +   fclose(f);
  135. +   return 1;            /* generate new game. */
  136. + }
  137. + int restore_game()
  138. + {
  139. +   int i;
  140. +   FILE *f;
  141. +   clear_status();
  142. +   clear_prompt();
  143. +   addstr("Type space to restore game in file ");
  144. +   addstr(SAVE_FILE_NAME);
  145. +   addstr(". ");
  146. +   refresh();
  147. +   clear_status();
  148. +   if (' ' != getch()) {
  149. +     addstr("The restoration of the old game was aborted.");
  150. +     return 0;
  151. +   }
  152. +   if (NULL == (f = fopen(SAVE_FILE_NAME, "r"))) {
  153. +     addstr("Restore error: Cannot open ");
  154. +     addstr(SAVE_FILE_NAME);
  155. +     addstr(".  Game not restored.");
  156. +     return 0;
  157. +   }
  158. +   if (1 != fread(&i, sizeof(int), 1, f) || i != MAGIC_NUMBER) {
  159. +     addstr("Restore error: Bad save file format.");
  160. +     fclose(f);
  161. +     return 0;
  162. +   }
  163. +   free_list_init();        /* read cards. */
  164. +   if (1 != fread(&cards, sizeof(int), 1, f)) return bad_read(f);
  165. +   for (i = 0; i < nsuits; i++)    /* read foundations. */
  166. +     if (1 != fread(board.foundation + i, sizeof(card_t), 1, f))
  167. +       return bad_read(f);
  168. +   for (i = 0; i < nstacks; i++) { /* read stacks. */
  169. +     int len;
  170. +     if (1 != fread(&len, sizeof(int), 1, f)) return bad_read(f);
  171. +     board.stack[i] = NIL;
  172. +     for (; len > 0; len--) {
  173. +       card_t c;
  174. +       if (1 != fread(&c, sizeof(card_t), 1, f)) return bad_read(f);
  175. +       push_card(c, i);
  176. +     }
  177. +   }
  178. +   fclose(f);
  179. +   return show_game();
  180. + }
  181. + int bad_write()
  182. + {
  183. +   addstr("Save error: Write failed.  Game not saved.");
  184. +   return 0;
  185. + }
  186. + int save_game()
  187. + {
  188. +   int i;
  189. +   FILE *f;
  190. +   card_t stack[board_height];
  191. +   clear_status();
  192. +   clear_prompt();
  193. +   addstr("Type space to save game in file ");
  194. +   addstr(SAVE_FILE_NAME);
  195. +   addstr(". ");
  196. +   refresh();
  197. +   clear_status();
  198. +   if (' ' != getch()) {
  199. +     addstr("The saving of the game was aborted.");
  200. +     return 0;
  201. +   }
  202. +   if (NULL == (f = fopen(SAVE_FILE_NAME, "w"))) {
  203. +     addstr("Save error: Cannot open ");
  204. +     addstr(SAVE_FILE_NAME);
  205. +     addstr(".  Game not saved.");
  206. +     return 0;
  207. +   }
  208. +   i = MAGIC_NUMBER;
  209. +   if (1 != fwrite(&i, sizeof(int), 1, f)) return bad_write();
  210. +   if (1 != fwrite(&cards, sizeof(cards), 1, f)) return bad_write();
  211. +   for (i = 0; i < nsuits; i++)    /* write foundations. */
  212. +     if (1 != fwrite(board.foundation + i, sizeof(card_t), 1, f))
  213. +       return bad_write();
  214. +   for (i = 0; i < nstacks; i++) { /* write stacks. */
  215. +     card_list_t list = board.stack[i];
  216. +     int j = 0;
  217. +     for (; list != NIL; list = list->rest, j++)
  218. +       stack[j] = list->card;
  219. +     if (1 != fwrite(&j, sizeof(int), 1, f)) return bad_write();
  220. +     for (j--; j >= 0; j--)
  221. +       if (1 != fwrite(stack + j, sizeof(card_t), 1, f))
  222. +     return bad_write();
  223. +   }
  224. +   fclose(f);
  225. +   addstr("Game saved.");
  226. +   return 0;
  227. + }
  228.   int is_stack_done(p)
  229.        int p;
  230.   {
  231. ***************
  232. *** 469,474 ****
  233. --- 584,606 ----
  234.     return 0;
  235.   }
  236.   
  237. + int getcmd()            /* Implements aliases for commands. */
  238. + {
  239. +   int c = getch();
  240. +   switch (c) {
  241. +   case ' ': return '0';        /* Aliases for use when there is no */
  242. +   case 'j': return '1';        /* numeric keypad. */
  243. +   case 'k': return '2';
  244. +   case 'l': return '3';
  245. +   case ';': return '4';
  246. +   case 'u': return '5';
  247. +   case 'i': return '6';
  248. +   case 'o': return '7';
  249. +   case 'p': return '8';
  250. +   default: return c;
  251. +   }
  252. + }
  253.   int get_other_move(from)
  254.        int from;
  255.   {
  256. ***************
  257. *** 480,488 ****
  258.     addch(from+'1');
  259.     addstr(" to ");
  260.     refresh();
  261. !   to = getch();
  262.     if (to == EOF || to == 'q') return 1;
  263. !   if (to == 'r') return show_game();
  264.     if (to == '?') return show_help();
  265.     to -= '1';
  266.     clear_status();
  267. --- 612,621 ----
  268.     addch(from+'1');
  269.     addstr(" to ");
  270.     refresh();
  271. !   to = getcmd();
  272.     if (to == EOF || to == 'q') return 1;
  273. !   if (to == 'r') return restore_game();
  274. !   if (to == 's') return save_game();
  275.     if (to == '?') return show_help();
  276.     to -= '1';
  277.     clear_status();
  278. ***************
  279. *** 500,508 ****
  280.     clear_prompt();
  281.     addstr("Move from stack ");
  282.     refresh();
  283. !   from = getch();
  284.     if (from == EOF || from == 'q') return 1;
  285. !   if (from == 'r') return show_game();
  286.     if (from == '?') return show_help();
  287.     from -= '1';
  288.     if (from < 0 || from >= 8) {
  289. --- 633,642 ----
  290.     clear_prompt();
  291.     addstr("Move from stack ");
  292.     refresh();
  293. !   from = getcmd();
  294.     if (from == EOF || from == 'q') return 1;
  295. !   if (from == 'r') return restore_game();
  296. !   if (from == 's') return save_game();
  297.     if (from == '?') return show_help();
  298.     from -= '1';
  299.     if (from < 0 || from >= 8) {
  300.