home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume13 / engarde / part02 < prev    next >
Encoding:
Internet Message Format  |  1992-02-10  |  11.7 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v13i025:  engarde - an X/MOTIF strategy game involving "magnets", Part02/02
  5. Message-ID: <2344@masterCNA.TEK.COM>
  6. Date: 25 Jan 92 01:24:29 GMT
  7. Sender: news@masterCNA.TEK.COM
  8. Lines: 358
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: Bill James <wjames@Jupiter.SAIC.COM>
  12. Posting-number: Volume 13, Issue 25
  13. Archive-name: engarde/Part02
  14. Environment: SUNOS SYSVR4 X11R4 MOTIF Sun HP
  15.  
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 2 (of 2)."
  24. # Contents:  Makefile board.h engarde.RULES menus.c menus.h
  25. #   patchlevel.h sun40add.c
  26. # Wrapped by billr@saab on Fri Jan 24 17:21:01 1992
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'Makefile'\"
  30. else
  31. echo shar: Extracting \"'Makefile'\" \(550 characters\)
  32. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  33. XINCDIR = -I/usr/include/X11/Motif1.0
  34. XLIBS = -lXm -lXt -lX11 
  35. XLIBDIR = -L/usr/lib/X11/Motif1.0 -L/usr/lib
  36. XCFLAGS = -D_NO_PROTO $(INCDIR) -O
  37. XLFLAGS = -s
  38. X
  39. X# Use this for SunOs 4.0x, if the MOTIF libraries were compiled with 4.1x
  40. XTOBJS = engarde.o board.o xboard.o menus.o sun40add.o
  41. X
  42. X# Use this for SunOs 4.1x 
  43. X# TOBJS = engarde.o board.o xboard.o menus.o 
  44. X
  45. X
  46. Xengarde: $(TOBJS)
  47. X    cc -o engarde $(LFLAGS) $(LIBDIR) $(TOBJS) $(LIBS)
  48. X
  49. Xboard.o: board.h xboard.h
  50. Xxboard.o: board.h xboard.h menus.h
  51. Xengarde.o: board.h xboard.h bitmaps.h help.h
  52. Xmenus.o: menus.h
  53. END_OF_FILE
  54. if test 550 -ne `wc -c <'Makefile'`; then
  55.     echo shar: \"'Makefile'\" unpacked with wrong size!
  56. fi
  57. # end of 'Makefile'
  58. fi
  59. if test -f 'board.h' -a "${1}" != "-c" ; then 
  60.   echo shar: Will not clobber existing file \"'board.h'\"
  61. else
  62. echo shar: Extracting \"'board.h'\" \(750 characters\)
  63. sed "s/^X//" >'board.h' <<'END_OF_FILE'
  64. X#define POSITIVE    1
  65. X#define NEGATIVE    -1
  66. X#define UNCHARGED    0
  67. X#define BOARD_WIDTH    6
  68. X#define BOARD_HEIGHT    6
  69. X#define PIECE_BLACK    1
  70. X#define PIECE_WHITE    0
  71. X#define PIECE_ROUND    0
  72. X#define PIECE_SQUARE    1
  73. X#define NPIECES        6
  74. X
  75. X#define MIN2(x,y)    (((x)<(y))? (x):(y))
  76. X
  77. Xstruct _PieceType {
  78. X   int color;
  79. X   int type;
  80. X};
  81. Xtypedef struct _PieceType PieceType;
  82. X
  83. Xstruct _SideType {
  84. X   PieceType *p[6];
  85. X};
  86. Xtypedef struct _SideType SideType;
  87. X
  88. Xvoid FlipPiece();
  89. X
  90. Xstruct _BoardType {
  91. X   char **magnets;
  92. X   PieceType ***pieces;
  93. X   int height, width;
  94. X};
  95. Xtypedef struct _BoardType BoardType;
  96. X
  97. Xvoid Magnetize();
  98. Xvoid KillBoard();
  99. Xvoid InitBoard();
  100. XPieceType * GetPiece();
  101. Xint GetPolarity();
  102. Xint MovePiece();
  103. Xvoid BoardShuffle();
  104. Xint SumSet();
  105. Xint CheckWinner();
  106. Xvoid Randomize();
  107. END_OF_FILE
  108. if test 750 -ne `wc -c <'board.h'`; then
  109.     echo shar: \"'board.h'\" unpacked with wrong size!
  110. fi
  111. # end of 'board.h'
  112. fi
  113. if test -f 'engarde.RULES' -a "${1}" != "-c" ; then 
  114.   echo shar: Will not clobber existing file \"'engarde.RULES'\"
  115. else
  116. echo shar: Extracting \"'engarde.RULES'\" \(3657 characters\)
  117. sed "s/^X//" >'engarde.RULES' <<'END_OF_FILE'
  118. X
  119. X                             ENGARDE v1.0
  120. X--------------------------------------------------------------------------
  121. X      A game written for X11R4 with OSF/MOTIF widgets by Bill James.
  122. X--------------------------------------------------------------------------
  123. X
  124. XOBJECT:
  125. X
  126. XTo have 4 pieces in a row, column, diagonal that are all of one player's 
  127. Xcolor, that player is to be considered the winner.
  128. X
  129. X
  130. XDESIGNATIONS:
  131. X
  132. X -  The center set of squares is know as the "grid".
  133. X -  The single columns to the right and left of the grid are
  134. X      called "side-bars", possible preceded by a "left" or "right".
  135. X -  The squares and circles are called "pieces", with the unfilled
  136. X      piece being "white", and the filled piece being "black".
  137. X
  138. X
  139. XCHARACTERISTICS OF THE BOARD:
  140. X
  141. X    Each piece is to be considered a magnet with one pole painted 
  142. Xwhite, and the other painted black.  A piece is considered to be
  143. Xwhite if the white side is face up, else it is black.  On circular 
  144. Xpieces the positive side is painted white, while on the squares it 
  145. Xis the negative side.  The grid is also merely a set of magnetized 
  146. Xsquares, with either the positive or negative side facing upwards.
  147. XThe grid also contains spaces that are not magnets at all, but are 
  148. Xmerely null spots, and do not affect the pieces at all.  
  149. X
  150. XExamples:
  151. XSample Grid :
  152. X    
  153. X   + + - + O -     + = positive grid face up
  154. X   - - + - + -     - = negative grid face up
  155. X   O - + - - +     O = null grid space
  156. X   + + - + + -
  157. X   - + + O - -
  158. X   - - - - + +
  159. X
  160. XEvery new game, the board shuffles it's magnets to form a new
  161. Xgrid.
  162. X
  163. XWhen a player moves a piece onto the grid, the magnetic interactions
  164. Xcause the piece to show the color painted on the magnet side with
  165. Xthe same polarity as the grid place.  e.g. when a piece moves on
  166. Xa positive grid place, the positive side of the magnet is repulsed, 
  167. Xand is therefore face up.
  168. X
  169. X  Before Move          After Move Piece is:
  170. X   Piece is:      When moved onto grid with magnet:
  171. X--------------------------------------------------
  172. X| Shape | Color ||| Positive | Negative |  Null  |
  173. X--------------------------------------------------
  174. X|  SQU  |  Wh   |||    Bl    |    Wh    |   Wh   |   
  175. X|  SQU  |  Bl   |||    Bl    |    Wh    |   Bl   |
  176. X|  CIR  |  Wh   |||    Wh    |    Bl    |   Wh   |
  177. X|  CIR  |  Bl   |||    Wh    |    Bl    |   Bl   |
  178. X--------------------------------------------------
  179. X
  180. XRULES OF MOVEMENT:
  181. X
  182. XThe arrows to either side of the message box designate whose turn it is.
  183. XThis player has the following options:
  184. X
  185. X1.  The player may take a piece from his side-bar and place it
  186. X    on any space on the center grid where there is no other piece.
  187. X
  188. X2.  The player may move any piece that is currently on the grid
  189. X    EXCEPT the last piece moved to another spot guided by these rules:
  190. X    2a.  Piece cannot move to occupied place.
  191. X    2b.  Piece may only move in one direction.
  192. X    2c.  Piece cannot move more than 2 spaces in a single direction,
  193. X           either Up, Down, Left, Right, or the Diagonals.
  194. X    2d.  Piece may only be moved 2 spaces in a direction if the first
  195. X           space in that direction is occupied (it jumps the first piece).
  196. X    2e.  Piece may not be placed back onto side-bar.
  197. X    
  198. X
  199. XSTRATEGY HINTS:
  200. X
  201. X - Try to save a piece on your side-bar, being able to place it anywhere
  202. X      on the grid may save your neck.
  203. X
  204. X - Try to keep track of what polarity the grid locations are as you find
  205. X      them out, they won't change until the next game.
  206. X
  207. X - Don't forget about the null spaces.  If a piece keeps the same color
  208. X      when it moves, a null space is always a possibility.
  209. X
  210. X----------------------------------------------------------------------------
  211. END_OF_FILE
  212. if test 3657 -ne `wc -c <'engarde.RULES'`; then
  213.     echo shar: \"'engarde.RULES'\" unpacked with wrong size!
  214. fi
  215. # end of 'engarde.RULES'
  216. fi
  217. if test -f 'menus.c' -a "${1}" != "-c" ; then 
  218.   echo shar: Will not clobber existing file \"'menus.c'\"
  219. else
  220. echo shar: Extracting \"'menus.c'\" \(2093 characters\)
  221. sed "s/^X//" >'menus.c' <<'END_OF_FILE'
  222. X/*********************************************************************
  223. X                                Engarde
  224. X                             File: menus.c
  225. X
  226. X  This file contains a convenience function to create menus from 
  227. X  a structure tree.
  228. X
  229. X  Version 1:  1/9/92  (Bill James)
  230. X*********************************************************************/
  231. X#include <X11/Intrinsic.h>
  232. X#include <X11/StringDefs.h>
  233. X#include <Xm/Xm.h>
  234. X#include <Xm/Separator.h>
  235. X#include <Xm/PushB.h>
  236. X#include <Xm/CascadeB.h>
  237. X#include <Xm/RowColumn.h>
  238. X#include <Xm/Label.h>
  239. X#include "menus.h"
  240. X
  241. Xvoid xs_create_menu_buttons(title, menu, menulist, nitems) 
  242. Xchar *title;
  243. XWidget menu;
  244. Xxs_menu_struct *menulist;
  245. Xint nitems;
  246. X{
  247. XArg wargs[1];
  248. Xint i;
  249. XWidgetList buttons;
  250. Xint separators = 0;
  251. X   buttons = (WidgetList) XtMalloc (nitems * sizeof(Widget));
  252. X   if (title) {
  253. X      XtCreateManagedWidget(title, xmLabelWidgetClass, menu, NULL, 0);
  254. X      XtCreateManagedWidget("separator", xmSeparatorWidgetClass, menu, NULL,0);
  255. X   }
  256. X   for (i = 0; i < nitems; i++) {
  257. X      if (menulist[i].name == NULL) {
  258. X         XtCreateManagedWidget("separator", xmSeparatorWidgetClass, 
  259. X                menu, NULL, 0);
  260. X         separators++;
  261. X      }
  262. X      else if (menulist[i].func) {
  263. X         buttons[i-separators] = XtCreateWidget(menulist[i].name,
  264. X                        xmPushButtonWidgetClass,
  265. X                        menu, NULL, 0);
  266. X         XtAddCallback(buttons[i-separators], XmNactivateCallback, 
  267. X            menulist[i].func, menulist[i].data);
  268. X      }
  269. X      else if (!menulist[i].sub_menu) 
  270. X         buttons[i-separators] = XtCreateWidget(menulist[i].name,
  271. X                        xmLabelWidgetClass,
  272. X                        menu, NULL, 0);
  273. X      else {
  274. X         Widget sub_menu;
  275. X         sub_menu = XmCreatePulldownMenu(menu, menulist[i].sub_menu_title,
  276. X                        NULL, 0);
  277. X         XtSetArg(wargs[0], XmNsubMenuId, sub_menu);
  278. X         buttons[i-separators] = XtCreateWidget(menulist[i].name,
  279. X                        xmCascadeButtonWidgetClass,
  280. X                        menu, wargs, 1);
  281. X         xs_create_menu_buttons(menulist[i].sub_menu_title, sub_menu,
  282. X                menulist[i].sub_menu, menulist[i].n_sub_items);
  283. X      }
  284. X   }
  285. X   XtManageChildren(buttons, nitems - separators);
  286. X}
  287. END_OF_FILE
  288. if test 2093 -ne `wc -c <'menus.c'`; then
  289.     echo shar: \"'menus.c'\" unpacked with wrong size!
  290. fi
  291. # end of 'menus.c'
  292. fi
  293. if test -f 'menus.h' -a "${1}" != "-c" ; then 
  294.   echo shar: Will not clobber existing file \"'menus.h'\"
  295. else
  296. echo shar: Extracting \"'menus.h'\" \(211 characters\)
  297. sed "s/^X//" >'menus.h' <<'END_OF_FILE'
  298. Xtypedef struct _menu_struct {
  299. X   char * name;
  300. X   void (*func)();
  301. X   caddr_t data;
  302. X   struct _menu_struct *sub_menu;
  303. X   int n_sub_items;
  304. X   char *sub_menu_title;
  305. X} xs_menu_struct;
  306. X
  307. Xvoid xs_create_menu_buttons();
  308. END_OF_FILE
  309. if test 211 -ne `wc -c <'menus.h'`; then
  310.     echo shar: \"'menus.h'\" unpacked with wrong size!
  311. fi
  312. # end of 'menus.h'
  313. fi
  314. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  315.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  316. else
  317. echo shar: Extracting \"'patchlevel.h'\" \(25 characters\)
  318. sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  319. X#define PATCHLEVEL    "1.0"
  320. END_OF_FILE
  321. if test 25 -ne `wc -c <'patchlevel.h'`; then
  322.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  323. fi
  324. # end of 'patchlevel.h'
  325. fi
  326. if test -f 'sun40add.c' -a "${1}" != "-c" ; then 
  327.   echo shar: Will not clobber existing file \"'sun40add.c'\"
  328. else
  329. echo shar: Extracting \"'sun40add.c'\" \(470 characters\)
  330. sed "s/^X//" >'sun40add.c' <<'END_OF_FILE'
  331. X/*********************************************************************
  332. X                                Engarde
  333. X                           File: sun40add.c
  334. X
  335. X  This file is needed by SunOs 4.0x in order to compile correctly with
  336. X  MOTIF libraries compiled with SunOs 4.1x .  Do not add this unless
  337. X  necessary.
  338. X
  339. X  Version 1:  1/9/92  (Bill James)
  340. X*********************************************************************/
  341. Xchar tolower(c)
  342. Xchar c;
  343. X{
  344. X   return(c - 'A' + 'a');
  345. X}
  346. END_OF_FILE
  347. if test 470 -ne `wc -c <'sun40add.c'`; then
  348.     echo shar: \"'sun40add.c'\" unpacked with wrong size!
  349. fi
  350. # end of 'sun40add.c'
  351. fi
  352. echo shar: End of archive 2 \(of 2\).
  353. cp /dev/null ark2isdone
  354. MISSING=""
  355. for I in 1 2 ; do
  356.     if test ! -f ark${I}isdone ; then
  357.     MISSING="${MISSING} ${I}"
  358.     fi
  359. done
  360. if test "${MISSING}" = "" ; then
  361.     echo You have unpacked both archives.
  362.     rm -f ark[1-9]isdone
  363. else
  364.     echo You still need to unpack the following archives:
  365.     echo "        " ${MISSING}
  366. fi
  367. ##  End of shell archive.
  368. exit 0
  369.