home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume13 / engarde / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-02-10  |  55.0 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: v13i024:  engarde - an X/MOTIF strategy game involving "magnets", Part01/02
  5. Message-ID: <2343@masterCNA.TEK.COM>
  6. Date: 25 Jan 92 01:24:03 GMT
  7. Sender: news@masterCNA.TEK.COM
  8. Lines: 1693
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: Bill James <wjames@Jupiter.SAIC.COM>
  12. Posting-number: Volume 13, Issue 24
  13. Archive-name: engarde/Part01
  14. Environment: SUNOS SYSVR4 X11R4 MOTIF Sun HP
  15.  
  16. [From the author...]
  17. [[  This game is evolved from a board game called Touche, with
  18. some changes in rules and concepts that make the game harder
  19. to master and easier to play.  It's my first project in X/MOTIF,
  20. so enjoy it.]]
  21.  
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then unpack
  24. # it by saving it into a file and typing "sh file".  To overwrite existing
  25. # files, type "sh file -c".  You can also feed this as standard input via
  26. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  27. # will see the following message at the end:
  28. #        "End of archive 1 (of 2)."
  29. # Contents:  README MANIFEST bitmaps.h board.c engarde.c help.h
  30. #   xboard.c xboard.h
  31. # Wrapped by billr@saab on Fri Jan 24 17:21:01 1992
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f 'README' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'README'\"
  35. else
  36. echo shar: Extracting \"'README'\" \(2884 characters\)
  37. sed "s/^X//" >'README' <<'END_OF_FILE'
  38. X            Engarde v1.0
  39. X                           by Bill James, 1992
  40. X-----------------------------------------------------------------------
  41. X
  42. XThis game was written in C, compiled by the SUN C compiler (cc), and
  43. Xuses X11R4 and OSF/MOTIF v1.1 function calls.  The current list of
  44. Xarchitectures under which it has been run are:
  45. X
  46. XSun SparcStation (1,2,SLC,ELC)
  47. XHewlett-Packard Series 9000/300
  48. XHewlett-Packard Apollo Series 700
  49. X
  50. X
  51. XSome lines you may want to add to your .Xdefaults are:
  52. X
  53. XEnGarde.geometry:    700x500+100+100
  54. XEnGarde*Menu*fontList: -adobe-helvetica-bold-o-normal--17-120-100-100-p-92-iso8859-1
  55. XEnGarde*Message.fontList: -adobe-new century schoolbook-medium-i-normal--17-120-100-100-p-92-iso8859-1
  56. XEnGarde*HelpText.fontList: -b&h-lucidatypewriter-medium-r-normal-sans-17-120-100-100-m-100-iso8859-1
  57. XEnGarde*HelpOk*fontList: -adobe-new century schoolbook-medium-i-normal--17-120-100-100-p-92-iso8859-1
  58. XEnGarde*About*fontList: -sony-fixed-medium-r-normal--24-170-100-100-c-120-iso8859-1
  59. X
  60. XNOTE: the HelpText.fontList font MUST be fixed width.
  61. XNOTE: the geometry MUST be bigger than 200x200 for the game to 
  62. X        work correctly, you'll want it bigger if you want it
  63. X        to look good.
  64. X
  65. XIf you don't have the fonts listed, feel free to change them.
  66. X
  67. XNOTE: changing other resources has not been tested, so if it doesn't
  68. Xwork, send me a suggestion about adding that to the list of changeable
  69. Xresources.
  70. X
  71. X
  72. X
  73. X/********************DISCLAIMER*************************************/
  74. X
  75. XThis software is distributed AS IS, and no guarantees about it's 
  76. Xperformance or compatibility are issued.  If you find bugs or
  77. Xhave suggestions (other than "make it color",etc. I can come up
  78. Xwith those myself), please send them to wjames@jupiter.saic.com .
  79. X
  80. X/*******************************************************************/
  81. X/*******************DISTRIBUTION INSTRUCTIONS***********************/
  82. X
  83. XThis software is distributed in source code form, and is to be
  84. Xdistributed only in the original form and in it's entirety.  Changes
  85. Xto code can be documented and sent to the author, and any such changes may
  86. Xbe incorporated into a new version without notice.
  87. X
  88. X/*******************************************************************/
  89. X
  90. X
  91. XFeatures to come in future releases:
  92. X
  93. X1.  Computer player for 1-player games.
  94. X2.  Save game ability.
  95. X3.  Win-loss record keeping.
  96. X4.  Faster drawing, better-looking pieces.
  97. X
  98. X
  99. X***************NOTES FROM THE AUTHOR******************************
  100. X
  101. XThanx for trying this out, this is my first X/MOTIF program,
  102. Xand I think the game is a decent idea.  
  103. X
  104. XBill James
  105. Xwjames@jupiter.saic.com
  106. X
  107. XLook for B J Products computer utilities on MS-DOS BBS's in California.
  108. X
  109. X
  110. X******************SPECIAL THANKS:*********************************
  111. X
  112. XMark Botta:  HP play-and-compile-tester, aesthetics.
  113. XKral Ferch:  MOTIF widget help.
  114. X******************************************************************
  115. END_OF_FILE
  116. if test 2884 -ne `wc -c <'README'`; then
  117.     echo shar: \"'README'\" unpacked with wrong size!
  118. fi
  119. # end of 'README'
  120. fi
  121. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  122.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  123. else
  124. echo shar: Extracting \"'MANIFEST'\" \(579 characters\)
  125. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  126. X   File Name        Archive #    Description
  127. X-----------------------------------------------------------
  128. X MANIFEST                   1    This shipping list
  129. X Makefile                   2    
  130. X README                     1    
  131. X bitmaps.h                  1    
  132. X board.c                    1    
  133. X board.h                    2    
  134. X engarde.RULES              2    
  135. X engarde.c                  1    
  136. X help.h                     1    
  137. X menus.c                    2    
  138. X menus.h                    2    
  139. X patchlevel.h               2    
  140. X sun40add.c                 2    
  141. X xboard.c                   1    
  142. X xboard.h                   1    
  143. END_OF_FILE
  144. if test 579 -ne `wc -c <'MANIFEST'`; then
  145.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  146. fi
  147. # end of 'MANIFEST'
  148. fi
  149. if test -f 'bitmaps.h' -a "${1}" != "-c" ; then 
  150.   echo shar: Will not clobber existing file \"'bitmaps.h'\"
  151. else
  152. echo shar: Extracting \"'bitmaps.h'\" \(8067 characters\)
  153. sed "s/^X//" >'bitmaps.h' <<'END_OF_FILE'
  154. X/* My logo */
  155. X#define BJ_width 40
  156. X#define BJ_height 40
  157. Xstatic char BJ_bits[] = {
  158. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
  159. X   0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00,
  160. X   0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xe3, 0xff, 0xff, 0xff, 0xc7, 0x83,
  161. X   0xff, 0xff, 0xff, 0xc1, 0x03, 0x00, 0xf0, 0x03, 0xc0, 0x03, 0x00, 0xc0,
  162. X   0x01, 0xc0, 0x03, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x80, 0x01, 0xc0,
  163. X   0x03, 0xb0, 0x81, 0x01, 0xc0, 0x03, 0x10, 0x83, 0x01, 0xc0, 0x03, 0x10,
  164. X   0x82, 0x03, 0xc0, 0x03, 0x10, 0x02, 0x03, 0xc0, 0x03, 0x10, 0x03, 0x03,
  165. X   0xc0, 0x03, 0xf0, 0x01, 0x03, 0xc0, 0x03, 0xf0, 0x01, 0x03, 0xc0, 0x03,
  166. X   0x10, 0x03, 0x03, 0xc0, 0x03, 0x10, 0x06, 0x03, 0xc0, 0x03, 0x10, 0x04,
  167. X   0x07, 0xc0, 0x03, 0x10, 0x04, 0x06, 0xc0, 0x03, 0x10, 0x04, 0x06, 0xc0,
  168. X   0x03, 0x10, 0x06, 0x06, 0xc0, 0x03, 0x30, 0x03, 0x06, 0xc0, 0x03, 0xe0,
  169. X   0x01, 0x06, 0xc0, 0x03, 0x00, 0x00, 0x06, 0xc0, 0x03, 0x00, 0x00, 0x07,
  170. X   0xc0, 0x03, 0x03, 0x00, 0x03, 0xc0, 0x03, 0x07, 0x80, 0x03, 0xc0, 0x03,
  171. X   0x3e, 0xc0, 0x01, 0xc0, 0x03, 0xfc, 0xff, 0x00, 0xc0, 0x03, 0xe0, 0x7f,
  172. X   0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0,
  173. X   0x03, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
  174. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  175. X
  176. X/* En Garde Label */
  177. X#define Emblem_width 40
  178. X#define Emblem_height 40
  179. Xstatic char Emblem_bits[] = {
  180. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
  181. X   0x00, 0x00, 0xc0, 0x03, 0x00, 0x7e, 0x00, 0xc0, 0x03, 0x00, 0x7f, 0x00,
  182. X   0xc0, 0x03, 0x00, 0x03, 0x00, 0xc0, 0x03, 0x80, 0x03, 0x00, 0xc0, 0x03,
  183. X   0x80, 0x01, 0x00, 0xc0, 0x03, 0xc0, 0x01, 0x00, 0xc0, 0x03, 0xc0, 0x00,
  184. X   0x00, 0xc0, 0x03, 0xc0, 0x07, 0x02, 0xc0, 0x03, 0xe0, 0x07, 0x1e, 0xc0,
  185. X   0x03, 0x60, 0x00, 0x36, 0xc0, 0x03, 0x70, 0x00, 0x23, 0xc0, 0x03, 0x30,
  186. X   0x00, 0x21, 0xc0, 0x03, 0x38, 0x80, 0x31, 0xc0, 0x03, 0x18, 0x80, 0x10,
  187. X   0xc0, 0x03, 0xf8, 0xc7, 0x18, 0xc0, 0x03, 0xf0, 0x47, 0x08, 0xc0, 0x03,
  188. X   0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00,
  189. X   0x00, 0xc0, 0xc3, 0x03, 0x00, 0x00, 0xc0, 0xf3, 0x07, 0x00, 0x00, 0xc0,
  190. X   0x33, 0x06, 0x00, 0x30, 0xc0, 0x3b, 0x00, 0x00, 0x30, 0xc0, 0x1b, 0x00,
  191. X   0x00, 0x30, 0xc0, 0x1b, 0x00, 0x00, 0x30, 0xc0, 0x1b, 0x00, 0x00, 0x30,
  192. X   0xcf, 0x1b, 0xe0, 0x74, 0xbe, 0xd9, 0x9b, 0xb7, 0x7d, 0xbf, 0xd9, 0x9b,
  193. X   0x97, 0x0d, 0xb3, 0xcf, 0x1b, 0x16, 0x0d, 0xb3, 0xc1, 0x3b, 0x96, 0x0d,
  194. X   0xb3, 0xc1, 0x33, 0xf7, 0x0d, 0xbf, 0xcf, 0xf3, 0x63, 0x0d, 0x3e, 0xcf,
  195. X   0xe3, 0x01, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
  196. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  197. X
  198. X#define winright_width 40
  199. X#define winright_height 40
  200. Xstatic char winright_bits[] = {
  201. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
  202. X   0x00, 0x00, 0xc0, 0x03, 0x80, 0xff, 0x01, 0xc0, 0x03, 0xe0, 0xff, 0x07,
  203. X   0xc0, 0x03, 0x78, 0xf0, 0x1f, 0xc0, 0x03, 0x1e, 0xf0, 0x7f, 0xc0, 0x03,
  204. X   0x07, 0xf0, 0xff, 0xc0, 0x83, 0x01, 0xf0, 0xff, 0xc1, 0xc3, 0x00, 0xf0,
  205. X   0xff, 0xc3, 0xc3, 0xf0, 0xf0, 0xf0, 0xc3, 0x63, 0xf0, 0xf0, 0xf0, 0xc7,
  206. X   0x63, 0xf0, 0xf0, 0xf0, 0xc7, 0x33, 0xf0, 0xf0, 0xf0, 0xcf, 0x33, 0x00,
  207. X   0xf0, 0xff, 0xcf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff,
  208. X   0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b,
  209. X   0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0,
  210. X   0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf,
  211. X   0x1b, 0x00, 0xf0, 0x9f, 0xdf, 0x33, 0x00, 0xf0, 0x8f, 0xcf, 0x33, 0x00,
  212. X   0xf0, 0xc7, 0xcf, 0x63, 0xe0, 0x0f, 0xe0, 0xc7, 0x63, 0xf0, 0x0f, 0xf0,
  213. X   0xc7, 0xc3, 0x38, 0xf0, 0xff, 0xc3, 0xc3, 0x1c, 0xf0, 0xff, 0xc3, 0x83,
  214. X   0x0d, 0xf0, 0xff, 0xc1, 0x03, 0x07, 0xf0, 0xff, 0xc0, 0x03, 0x1e, 0xf0,
  215. X   0x7f, 0xc0, 0x03, 0x78, 0xf0, 0x1f, 0xc0, 0x03, 0xe0, 0xff, 0x07, 0xc0,
  216. X   0x03, 0x80, 0xff, 0x01, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
  217. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  218. X
  219. X#define winleft_width 40
  220. X#define winleft_height 40
  221. Xstatic char winleft_bits[] = {
  222. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
  223. X   0x00, 0x00, 0xc0, 0x03, 0x80, 0xff, 0x01, 0xc0, 0x03, 0xe0, 0xff, 0x07,
  224. X   0xc0, 0x03, 0x78, 0xf0, 0x1f, 0xc0, 0x03, 0x1e, 0xf0, 0x7f, 0xc0, 0x03,
  225. X   0x07, 0xf0, 0xff, 0xc0, 0x83, 0x01, 0xf0, 0xff, 0xc1, 0xc3, 0x00, 0xf0,
  226. X   0xff, 0xc3, 0xc3, 0xf0, 0xf0, 0xf0, 0xc3, 0x63, 0xf0, 0xf0, 0xf0, 0xc7,
  227. X   0x63, 0xf0, 0xf0, 0xf0, 0xc7, 0x33, 0xf0, 0xf0, 0xf0, 0xcf, 0x33, 0x00,
  228. X   0xf0, 0xff, 0xcf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff,
  229. X   0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b,
  230. X   0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0,
  231. X   0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf, 0x1b, 0x00, 0xf0, 0xff, 0xdf,
  232. X   0x1b, 0x0c, 0xf0, 0xff, 0xdf, 0x33, 0x1c, 0xf0, 0xff, 0xcf, 0x33, 0x38,
  233. X   0xf0, 0xff, 0xcf, 0x63, 0xf0, 0x0f, 0xf8, 0xc7, 0x63, 0xe0, 0x0f, 0xf0,
  234. X   0xc7, 0xc3, 0x00, 0xf0, 0xe3, 0xc3, 0xc3, 0x00, 0xf0, 0xc7, 0xc3, 0x83,
  235. X   0x01, 0xf0, 0xcf, 0xc1, 0x03, 0x07, 0xf0, 0xff, 0xc0, 0x03, 0x1e, 0xf0,
  236. X   0x7f, 0xc0, 0x03, 0x78, 0xf0, 0x1f, 0xc0, 0x03, 0xe0, 0xff, 0x07, 0xc0,
  237. X   0x03, 0x80, 0xff, 0x01, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
  238. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  239. X
  240. X
  241. X/* Left players turn */
  242. X#define lturn_width 40
  243. X#define lturn_height 40
  244. Xstatic char lturn_bits[] = {
  245. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
  246. X   0x00, 0x00, 0xc0, 0x03, 0x00, 0x30, 0x00, 0xc0, 0x03, 0x00, 0x38, 0x00,
  247. X   0xc0, 0x03, 0x00, 0x3c, 0x00, 0xc0, 0x03, 0x00, 0x36, 0x00, 0xc0, 0x03,
  248. X   0x00, 0x33, 0x00, 0xc0, 0x03, 0x80, 0x31, 0x00, 0xc0, 0x03, 0xc0, 0x30,
  249. X   0x00, 0xc0, 0x03, 0x60, 0x30, 0x00, 0xc0, 0x03, 0x30, 0x30, 0x00, 0xc0,
  250. X   0x03, 0x18, 0x30, 0x00, 0xc0, 0x03, 0x0c, 0xf0, 0xff, 0xcf, 0x03, 0x06,
  251. X   0xf0, 0xff, 0xcf, 0x03, 0x03, 0x00, 0x00, 0xcc, 0x83, 0x01, 0x00, 0x00,
  252. X   0xcc, 0xc3, 0x00, 0x00, 0x00, 0xcc, 0x63, 0x00, 0x00, 0x00, 0xcc, 0x33,
  253. X   0x00, 0x00, 0x00, 0xcc, 0x33, 0x00, 0x00, 0x00, 0xcc, 0x63, 0x00, 0x00,
  254. X   0x00, 0xcc, 0xc3, 0x00, 0x00, 0x00, 0xcc, 0x83, 0x01, 0x00, 0x00, 0xcc,
  255. X   0x03, 0x03, 0x00, 0x00, 0xcc, 0x03, 0x06, 0xf0, 0xff, 0xcf, 0x03, 0x0c,
  256. X   0xf0, 0xff, 0xcf, 0x03, 0x18, 0x30, 0x00, 0xc0, 0x03, 0x30, 0x30, 0x00,
  257. X   0xc0, 0x03, 0x60, 0x30, 0x00, 0xc0, 0x03, 0xc0, 0x30, 0x00, 0xc0, 0x03,
  258. X   0x80, 0x31, 0x00, 0xc0, 0x03, 0x00, 0x33, 0x00, 0xc0, 0x03, 0x00, 0x36,
  259. X   0x00, 0xc0, 0x03, 0x00, 0x3c, 0x00, 0xc0, 0x03, 0x00, 0x38, 0x00, 0xc0,
  260. X   0x03, 0x00, 0x30, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
  261. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  262. X
  263. X/* Right players turn */
  264. X#define rturn_width 40
  265. X#define rturn_height 40
  266. Xstatic char rturn_bits[] = {
  267. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
  268. X   0x00, 0x00, 0xc0, 0x03, 0x00, 0x0c, 0x00, 0xc0, 0x03, 0x00, 0x1c, 0x00,
  269. X   0xc0, 0x03, 0x00, 0x3c, 0x00, 0xc0, 0x03, 0x00, 0x7c, 0x00, 0xc0, 0x03,
  270. X   0x00, 0xfc, 0x00, 0xc0, 0x03, 0x00, 0xfc, 0x01, 0xc0, 0x03, 0x00, 0xfc,
  271. X   0x03, 0xc0, 0x03, 0x00, 0xfc, 0x07, 0xc0, 0x03, 0x00, 0xfc, 0x0f, 0xc0,
  272. X   0x03, 0x00, 0xfc, 0x1f, 0xc0, 0xf3, 0xff, 0xff, 0x3f, 0xc0, 0xf3, 0xff,
  273. X   0xff, 0x7f, 0xc0, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xf3, 0xff, 0xff, 0xff,
  274. X   0xc1, 0xf3, 0xff, 0xff, 0xff, 0xc3, 0xf3, 0xff, 0xff, 0xff, 0xc7, 0xf3,
  275. X   0xff, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff,
  276. X   0xff, 0xc7, 0xf3, 0xff, 0xff, 0xff, 0xc3, 0xf3, 0xff, 0xff, 0xff, 0xc1,
  277. X   0xf3, 0xff, 0xff, 0xff, 0xc0, 0xf3, 0xff, 0xff, 0x7f, 0xc0, 0xf3, 0xff,
  278. X   0xff, 0x3f, 0xc0, 0x03, 0x00, 0xfc, 0x1f, 0xc0, 0x03, 0x00, 0xfc, 0x0f,
  279. X   0xc0, 0x03, 0x00, 0xfc, 0x07, 0xc0, 0x03, 0x00, 0xfc, 0x03, 0xc0, 0x03,
  280. X   0x00, 0xfc, 0x01, 0xc0, 0x03, 0x00, 0xfc, 0x00, 0xc0, 0x03, 0x00, 0x7c,
  281. X   0x00, 0xc0, 0x03, 0x00, 0x3c, 0x00, 0xc0, 0x03, 0x00, 0x1c, 0x00, 0xc0,
  282. X   0x03, 0x00, 0x0c, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
  283. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  284. END_OF_FILE
  285. if test 8067 -ne `wc -c <'bitmaps.h'`; then
  286.     echo shar: \"'bitmaps.h'\" unpacked with wrong size!
  287. fi
  288. # end of 'bitmaps.h'
  289. fi
  290. if test -f 'board.c' -a "${1}" != "-c" ; then 
  291.   echo shar: Will not clobber existing file \"'board.c'\"
  292. else
  293. echo shar: Extracting \"'board.c'\" \(5055 characters\)
  294. sed "s/^X//" >'board.c' <<'END_OF_FILE'
  295. X/*********************************************************************
  296. X                                Engarde
  297. X                             File: board.c
  298. X
  299. X  This file contains the routines for the data of the board, magnet
  300. X  comparisons, and movement legality.
  301. X
  302. X  Version 1:  1/9/92  (Bill James)
  303. X*********************************************************************/
  304. X#include <malloc.h>
  305. X#include <stdio.h>
  306. X#include <sys/types.h>
  307. X#include <time.h>
  308. X#include "board.h"
  309. X
  310. Xextern int H,W;
  311. Xchar *SIGNSTRING[] = {"-","*","+"};
  312. XBoardType *b;
  313. X
  314. X/* 
  315. X   Flips piece from black to white or vice versa 
  316. X*/
  317. Xvoid FlipPiece(p)
  318. XPieceType *p;
  319. X{
  320. X   p->color = (p->color == PIECE_BLACK)? PIECE_WHITE:PIECE_BLACK;
  321. X}
  322. X
  323. X
  324. X/* 
  325. X   Mallocs and initializes board entity items
  326. X*/
  327. Xvoid InitBoard(s, h, w) 
  328. XSideType *s;
  329. Xint h,w;
  330. X{
  331. X    int i,j;
  332. X    PieceType *pc;
  333. X       b = (BoardType *) malloc (sizeof (BoardType));
  334. X       b->magnets = (char **) malloc (sizeof(char*) * h);
  335. X       b->pieces = (PieceType ***) malloc (sizeof(PieceType**) * h);
  336. X       for (i = 0; i < h; i++) {
  337. X          b->magnets[i] = (char *) malloc (w);
  338. X          b->pieces[i] = (PieceType **) malloc (w * sizeof(PieceType*));
  339. X          for (j = 0; j < w; j++) {
  340. X              b->magnets[i][j] = 0;
  341. X              b->pieces[i][j] = NULL;
  342. X          }
  343. X       }
  344. X       for (i = 0; i < NPIECES; i++) {
  345. X          pc = (PieceType *) malloc (sizeof(PieceType));
  346. X          s[PIECE_ROUND].p[i] = pc;
  347. X          s[PIECE_ROUND].p[i]->type = PIECE_ROUND;
  348. X          s[PIECE_ROUND].p[i]->color = PIECE_ROUND;
  349. X          pc = (PieceType *) malloc (sizeof(PieceType));
  350. X          s[PIECE_SQUARE].p[i] = pc;
  351. X          s[PIECE_SQUARE].p[i]->type = PIECE_SQUARE;
  352. X          s[PIECE_SQUARE].p[i]->color = PIECE_SQUARE;
  353. X       }
  354. X       b->height = h;
  355. X       b->width = w;
  356. X}
  357. X
  358. X
  359. X/*
  360. X   Deletes board memory items
  361. X*/
  362. Xvoid KillBoard(s) 
  363. XSideType s[2];
  364. X{
  365. X    int i,j;
  366. X    for (i = 0 ; i < b->height; i++) {
  367. X       if (s[0].p[i]) free(s[0].p[i]);
  368. X       if (s[1].p[i]) free(s[1].p[i]);
  369. X       for (j = 0; j < b->width; j++) {
  370. X          if (b->pieces[i][j]) free(b->pieces[i][j]);
  371. X       }
  372. X       free((char *) b->magnets[i]);
  373. X    }
  374. X    free((char *) b->magnets);
  375. X    free((char *) b->pieces);
  376. X}
  377. X
  378. X
  379. X#define GetPiece(b,h,w) (b)->pieces[(h)][(w)]
  380. X#define GetPolarity(b,h,w) (b)->magnets[(h)][(w)]
  381. X#define CKHW(b,h1,w1) (((h1) < (b)->height) && ((w1) < (b)->width))
  382. X
  383. X/*
  384. X   Move piece from h1,w1 to h2,w2
  385. X*/
  386. Xint MovePiece(h1, w1, h2, w2) 
  387. Xint h1,h2,w1,w2;
  388. X{
  389. X    if (!(CKHW(b,h1,w1))) return(1);
  390. X    if (!(CKHW(b,h2,w2))) return(1);
  391. X    if (b->pieces[h1][w1]) {
  392. X       if (b->pieces[h2][w2]) return(1);
  393. X       b->pieces[h2][w2] = b->pieces[h1][w1];
  394. X       Magnetize(h2,w2);
  395. X       b->pieces[h1][w1] = NULL;
  396. X       return(0);
  397. X    }
  398. X    else return (1);
  399. X}
  400. X
  401. X
  402. X/*
  403. X    Randomly shuffles board magnets
  404. X*/
  405. Xvoid BoardShuffle() 
  406. X{
  407. X    int i,j;
  408. X    char k;
  409. X    for ( i = 0; i < b->height; i++) 
  410. X       for (j = 0; j < b->width; j++) {
  411. X           k = (char) (random() % 2);
  412. X           if (k) b->magnets[i][j] = 1;
  413. X           else b->magnets[i][j] = -1;
  414. X           k = (char) (random() % 10);
  415. X           if (!k) b->magnets[i][j] = 0;
  416. X           Magnetize(i,j);
  417. X       }
  418. X}
  419. X
  420. X
  421. X
  422. X/*
  423. X   Sets piece color to correct color for it's shape/position
  424. X*/
  425. Xvoid Magnetize(h, w) 
  426. Xint h,w;
  427. X{
  428. X   PieceType *p;
  429. X   p = b->pieces[h][w];
  430. X   if (!(b->magnets[h][w])) return;
  431. X   if (p) {
  432. X      if ((p->type == PIECE_ROUND) && (b->magnets[h][w] == POSITIVE))
  433. X          p->color = PIECE_BLACK;
  434. X      if ((p->type == PIECE_ROUND) && (b->magnets[h][w] == NEGATIVE))
  435. X          p->color = PIECE_WHITE;
  436. X      if ((p->type == PIECE_SQUARE) && (b->magnets[h][w] == POSITIVE))
  437. X          p->color = PIECE_WHITE;
  438. X      if ((p->type == PIECE_SQUARE) && (b->magnets[h][w] == NEGATIVE))
  439. X          p->color = PIECE_BLACK;
  440. X   }
  441. X}
  442. X
  443. X
  444. X
  445. X/*
  446. X   Sums the colors of the set of four pieces (i,j),(i+dx,j+dy),
  447. X   (i+2dx,j+2dy),(i+3dx,j+3dy), or returns -1 if any of the 
  448. X   spaces have no piece.
  449. X*/
  450. Xint SumSet(i,j,dx,dy) 
  451. Xint i,j,dx,dy;
  452. X{
  453. Xint s,l,m,r;
  454. X  s = 0;
  455. X  for (r = 0, l = i, m = j; ((r < 4) && (l < W) && (l >= 0)) &&
  456. X                            ((m < H) && (m >= 0)); r++, l+=dx, m+=dy) {
  457. X     if (!b->pieces[l][m]) return(-1);
  458. X     s += b->pieces[l][m]->color;
  459. X  }
  460. X  if (((l >= W) || (l < 0) || (m >= H) || (m < 0)) && (r < 4)) return(-1);
  461. X  return(s);
  462. X}
  463. X
  464. X
  465. X/*
  466. X   Checks the board to find any set of 4 spaces in a row,column,diag
  467. X   that are the same color.
  468. X*/
  469. Xint CheckWinner(i, j, dx, dy)
  470. Xint *i,*j,*dx,*dy;
  471. X{
  472. Xint c,d,x,y,g;
  473. Xfor (c = 0; c < W; c++) 
  474. X   for (d = 0; d < H; d++) 
  475. X      for (x = -1; x < 2; x++) {
  476. X         for (y = -1; y < 2; y++) {
  477. X            if ((!x) && (!y)) continue;
  478. X            g = SumSet(c,d,x,y);
  479. X            if (g == (4 * PIECE_BLACK)) {
  480. X                *dx = x; *dy = y; 
  481. X                *i = c; *j = d;
  482. X        return(1);
  483. X            }
  484. X            if (g == (4 * PIECE_WHITE)) {
  485. X                *dx = x; *dy = y; 
  486. X                *i = c; *j = d;
  487. X        return(1);
  488. X            }
  489. X         }
  490. X      }
  491. Xreturn(0);
  492. X}
  493. X
  494. X
  495. Xvoid Randomize()
  496. X{
  497. Xtime_t g;
  498. Xint *h;
  499. X
  500. X  g = time();
  501. X  h = (int *) &g;
  502. X  srandom(*h);
  503. X}
  504. END_OF_FILE
  505. if test 5055 -ne `wc -c <'board.c'`; then
  506.     echo shar: \"'board.c'\" unpacked with wrong size!
  507. fi
  508. # end of 'board.c'
  509. fi
  510. if test -f 'engarde.c' -a "${1}" != "-c" ; then 
  511.   echo shar: Will not clobber existing file \"'engarde.c'\"
  512. else
  513. echo shar: Extracting \"'engarde.c'\" \(14872 characters\)
  514. sed "s/^X//" >'engarde.c' <<'END_OF_FILE'
  515. X/*********************************************************************
  516. X                                Engarde
  517. X                            File: engarde.c
  518. X
  519. X  This file contains startup routines and widget initializations
  520. X  for the display of the game.  It also calls functions to initialize
  521. X  the board magnets, etc.
  522. X
  523. X  Version 1:  1/9/92  (Bill James)
  524. X*********************************************************************/
  525. X#include <X11/Intrinsic.h>
  526. X#include <X11/StringDefs.h>
  527. X#include <X11/Xutil.h>
  528. X#include <Xm/Xm.h>
  529. X#include <Xm/RowColumn.h>
  530. X#include <Xm/Form.h>
  531. X#include <Xm/DrawingA.h>
  532. X#include <Xm/Text.h>
  533. X#include <Xm/Label.h>
  534. X#include <Xm/PushB.h>
  535. X#include <Xm/DrawnB.h>
  536. X#include "menus.h"
  537. X#include "board.h"
  538. X#include "xboard.h"
  539. X#include "bitmaps.h"
  540. X#include "help.h"
  541. X
  542. XWidget draw;
  543. XWidget lt; 
  544. XWidget rt; 
  545. XWidget mess;
  546. XWidget help;
  547. XWidget about;
  548. Xint n, H, W;
  549. XSideType s[2];
  550. XPixel fore, back;
  551. XPixmap lturn, rturn, goveright, goverleft;
  552. X
  553. Xvoid AddPixmap();
  554. XWidget MakeAboutWidget();
  555. X
  556. X
  557. Xstatic void quit(w, client_data, call_data)
  558. XWidget w;
  559. Xcaddr_t client_data;
  560. XXmAnyCallbackStruct *call_data;
  561. X{
  562. X     XtCloseDisplay(XtDisplay(w));
  563. X     exit(0);
  564. X}
  565. X
  566. Xstatic xs_menu_struct menuData_Quit[] = {
  567. X  {"Quit", quit, NULL, NULL, 0, NULL}
  568. X};
  569. X
  570. Xstatic xs_menu_struct menuData_Game[] = {
  571. X  {"New", ResetBoard, NULL, NULL, 0, NULL}
  572. X};
  573. X
  574. Xstatic xs_menu_struct menuData_Help[] = {
  575. X  {"Help", ShowHelp, NULL, NULL, 0, NULL},
  576. X  {"About...", ShowAbout, NULL, NULL, 0, NULL}
  577. X};
  578. X
  579. Xstatic xs_menu_struct menuData[] = {
  580. X  {"Game", NULL, NULL, menuData_Game, XtNumber(menuData_Game), NULL},
  581. X  {"Help", NULL, NULL, menuData_Help, XtNumber(menuData_Help), NULL},
  582. X  {"Quit", NULL, NULL, menuData_Quit, XtNumber(menuData_Quit), NULL}
  583. X};
  584. X
  585. X
  586. X
  587. Xmain(argc, argv)
  588. Xint argc;
  589. Xchar *argv[];
  590. X{
  591. XWidget menu, form, toplevel, emb, bj, helptext, helpquit; 
  592. XArg wargs[20];
  593. XPixmap embpix, bjpix;
  594. Xint i,j;
  595. XXmString str;
  596. Xstatic XtActionsRec draw_actions[] = {
  597. X         {"ButtonPress1",        ButtonPress1},
  598. X};
  599. X static char draw_translations[] =
  600. X         "<Btn1Down>:            ButtonPress1()";
  601. X
  602. X
  603. X   toplevel = XtInitialize(argv[0], "EnGarde", NULL, 0, &argc, argv);
  604. X   form = XtCreateManagedWidget("Form", xmFormWidgetClass, toplevel, NULL, 0);
  605. X   help = XmCreateFormDialog(toplevel,"Help", NULL, 0);
  606. X
  607. X   n = 0;
  608. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
  609. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  610. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  611. X   XtSetArg(wargs[n], XmNrightOffset, 10); n++;
  612. X   XtSetArg(wargs[n], XmNleftOffset, 10); n++;
  613. X   XtSetArg(wargs[n], XmNtopOffset, 5); n++;
  614. X   menu = XmCreateMenuBar(form, "Menu", wargs, n); XtManageChild(menu);
  615. X
  616. X   xs_create_menu_buttons(NULL, menu, menuData, XtNumber(menuData));
  617. X   
  618. X   n = 0;
  619. X   XtSetArg(wargs[n], XmNlabelType, XmPIXMAP); n++;
  620. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  621. X   XtSetArg(wargs[n], XmNleftOffset, 10); n++;
  622. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  623. X   XtSetArg(wargs[n], XmNbottomOffset, 20); n++;
  624. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  625. X   emb = (Widget) XmCreateLabel(form, "Emblem", wargs, n);
  626. X   XtManageChild(emb);
  627. X   AddPixmap(emb, &embpix, Emblem_bits, Emblem_width, Emblem_height);
  628. X   n = 0;
  629. X   XtSetArg(wargs[n], XmNlabelPixmap, embpix); n++;
  630. X   XtSetValues(emb, wargs, n);
  631. X
  632. X   n = 0;
  633. X   XtSetArg(wargs[n], XmNlabelType, XmPIXMAP); n++;
  634. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  635. X   XtSetArg(wargs[n], XmNrightOffset, 10); n++;
  636. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  637. X   XtSetArg(wargs[n], XmNbottomOffset, 20); n++;
  638. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  639. X   bj = (Widget) XmCreateLabel(form, "Bj", wargs, n);
  640. X   XtManageChild(bj);
  641. X   AddPixmap(bj, &bjpix, BJ_bits, BJ_width, BJ_height);
  642. X   n = 0;
  643. X   XtSetArg(wargs[n], XmNlabelPixmap, bjpix); n++;
  644. X   XtSetValues(bj, wargs, n);
  645. X
  646. X   n = 0;
  647. X   XtSetArg(wargs[n], XmNlabelType, XmPIXMAP); n++;
  648. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  649. X   XtSetArg(wargs[n], XmNleftOffset, 10); n++;
  650. X   XtSetArg(wargs[n], XmNleftWidget, emb); n++;
  651. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  652. X   XtSetArg(wargs[n], XmNbottomOffset, 20); n++;
  653. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  654. X   lt = (Widget) XmCreateLabel(form, "Lturn", wargs, n);
  655. X   XtManageChild(lt);
  656. X   AddPixmap(lt, <urn, lturn_bits, lturn_width, lturn_height);
  657. X   n = 0;
  658. X   XtSetArg(wargs[n], XmNlabelPixmap, lturn); n++;
  659. X   XtSetValues(lt, wargs, n);
  660. X
  661. X   n = 0;
  662. X   XtSetArg(wargs[n], XmNlabelType, XmPIXMAP); n++;
  663. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  664. X   XtSetArg(wargs[n], XmNrightWidget, bj); n++;
  665. X   XtSetArg(wargs[n], XmNrightOffset, 10); n++;
  666. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  667. X   XtSetArg(wargs[n], XmNbottomOffset, 20); n++;
  668. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  669. X   rt = (Widget) XmCreateLabel(form, "Rturn", wargs, n);
  670. X   XtManageChild(rt);
  671. X   AddPixmap(rt, &goveright, winright_bits, winright_width, winright_height);
  672. X   AddPixmap(rt, &goverleft, winleft_bits, 
  673. X                          winleft_width, winleft_height);
  674. X   AddPixmap(rt, &rturn, rturn_bits, rturn_width, rturn_height);
  675. X   n = 0;
  676. X   XtSetArg(wargs[n], XmNlabelPixmap, lturn); n++;
  677. X   XtSetValues(rt, wargs, n);
  678. X
  679. X   n = 0;
  680. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  681. X   XtSetArg(wargs[n], XmNleftWidget, lt); n++;
  682. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  683. X   XtSetArg(wargs[n], XmNrightWidget, rt); n++;
  684. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  685. X   XtSetArg(wargs[n], XmNbottomOffset, 10); n++;
  686. X   /*XtSetArg(wargs[n], XmNcolumns, 60); n++;*/
  687. X   XtSetArg(wargs[n], XmNrows, 2); n++;
  688. X   XtSetArg(wargs[n], XmNwordWrap, True); n++;
  689. X   XtSetArg(wargs[n], XmNscrollVertical, True); n++;
  690. X   XtSetArg(wargs[n], XmNscrollHorizontal, False); n++;
  691. X   XtSetArg(wargs[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  692. X   XtSetArg(wargs[n], XmNeditable, False); n++;
  693. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  694. X   XtSetArg(wargs[n], XmNcursorPositionVisible, False); n++;
  695. X   mess = (Widget) XmCreateScrolledText(form, "Message", wargs, n);
  696. X   XtManageChild(mess);
  697. X
  698. X   n = 0;
  699. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  700. X   XtSetArg(wargs[n], XmNleftOffset, 70); n++;
  701. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  702. X   XtSetArg(wargs[n], XmNrightOffset, 70); n++;
  703. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  704. X   XtSetArg(wargs[n], XmNbottomOffset, 10); n++;
  705. X   str = XmStringCreate("OK",XmSTRING_DEFAULT_CHARSET);
  706. X   XtSetArg(wargs[n], XmNlabelString, str); n++;
  707. X   helpquit = (Widget) XmCreatePushButton(help, "HelpOk", wargs, n);
  708. X   XtManageChild(helpquit);
  709. X
  710. X   n = 0;
  711. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  712. X   XtSetArg(wargs[n], XmNleftWidget, lt); n++;
  713. X   XtSetArg(wargs[n], XmNleftOffset, 10); n++;
  714. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  715. X   XtSetArg(wargs[n], XmNrightWidget, rt); n++;
  716. X   XtSetArg(wargs[n], XmNrightOffset, 10); n++;
  717. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
  718. X   XtSetArg(wargs[n], XmNtopOffset, 10); n++;
  719. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  720. X   XtSetArg(wargs[n], XmNbottomWidget, helpquit); n++;
  721. X   XtSetArg(wargs[n], XmNbottomOffset, 10); n++;
  722. X   XtSetArg(wargs[n], XmNcolumns, 80); n++;
  723. X   XtSetArg(wargs[n], XmNrows, 20); n++;
  724. X   XtSetArg(wargs[n], XmNwordWrap, False); n++;
  725. X   XtSetArg(wargs[n], XmNscrollVertical, True); n++;
  726. X   XtSetArg(wargs[n], XmNscrollHorizontal, False); n++;
  727. X   XtSetArg(wargs[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  728. X   XtSetArg(wargs[n], XmNeditable, False); n++;
  729. X   helptext = (Widget) XmCreateScrolledText(help, "HelpText", wargs, n);
  730. X   XtManageChild(helptext);
  731. X
  732. X   j = 0;
  733. X   for (i = 0; i < HELPLINES; i++) {
  734. X      XmTextInsert(helptext, j, helpstr[i]);
  735. X      j += strlen(helpstr[i]);
  736. X   }
  737. X
  738. X   n = 0;
  739. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  740. X   XtSetArg(wargs[n], XmNtopWidget, menu); n++;
  741. X   XtSetArg(wargs[n], XmNtopOffset, 10); n++;
  742. X   XtSetArg(wargs[n], XmNleftOffset, 10); n++;
  743. X   XtSetArg(wargs[n], XmNrightOffset, 10); n++;
  744. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  745. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  746. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  747. X   XtSetArg(wargs[n], XmNbottomWidget, mess); n++;
  748. X   XtSetArg(wargs[n], XmNbottomOffset, 10); n++;
  749. X   XtSetArg(wargs[n], XmNwidth, 300); n++;
  750. X   XtSetArg(wargs[n], XmNheight, 200); n++;
  751. X   XtSetArg(wargs[n], XmNresizePolicy, XmRESIZE_ANY); n++;
  752. X  draw = XtCreateManagedWidget("Canvas",xmDrawingAreaWidgetClass, form,wargs,n);
  753. X
  754. X   MakeAboutWidget(toplevel, bjpix, embpix);
  755. X
  756. X   n = 0;
  757. X   XtSetArg(wargs[n], XmNforeground, &fore); n++;
  758. X   XtSetArg(wargs[n], XmNbackground, &back); n++;
  759. X   XtGetValues(draw, wargs, n);
  760. X
  761. X   XtAddCallback(draw, XmNexposeCallback, DrawGame, NULL);
  762. X   XtAddCallback(draw, XmNresizeCallback, DrawGame, NULL);
  763. X   XtAddCallback(helpquit, XmNactivateCallback, CloseHelp, NULL);
  764. X   XtOverrideTranslations (draw, XtParseTranslationTable (draw_translations));
  765. X   XtAppAddActions (XtWidgetToApplicationContext (draw), draw_actions,
  766. X                         XtNumber (draw_actions));
  767. X
  768. X   W = 6; H = 6;
  769. X   Randomize();
  770. X   InitBoard(s,W,H);
  771. X   BoardShuffle();
  772. X   XtRealizeWidget(toplevel);
  773. X   XtMainLoop();
  774. X}
  775. X
  776. X
  777. Xvoid AddPixmap(w, pix, b, wid, hgt)
  778. XWidget w;
  779. XPixmap *pix;
  780. Xchar * b;
  781. Xint wid, hgt;
  782. X{
  783. XPixmap bitmap;
  784. XXGCValues vals;
  785. XGC gc;
  786. XArg wargs[10];
  787. Xint n;
  788. X   bitmap = XCreateBitmapFromData(XtDisplay(w), 
  789. X              RootWindowOfScreen(XtScreen(w)), b, wid, hgt);
  790. X   *pix = XCreatePixmap(XtDisplay(w),
  791. X              RootWindowOfScreen(XtScreen(w)), 
  792. X              wid, hgt, DefaultDepthOfScreen(XtScreen(w)));
  793. X   n = 0;
  794. X   XtSetArg(wargs[n],XtNforeground, &vals.foreground); n++;
  795. X   XtSetArg(wargs[n],XtNbackground, &vals.background); n++;
  796. X   XtGetValues(w,wargs,n);
  797. X   gc = XtGetGC(w, GCForeground|GCBackground, &vals);
  798. X   XCopyPlane(XtDisplay(w), bitmap, *pix, gc, 0, 0,
  799. X              wid, hgt, 0, 0, 1);
  800. X   XFreePixmap(XtDisplay(w), bitmap);
  801. X   XtReleaseGC(w, gc);
  802. X}
  803. X
  804. X
  805. XWidget MakeAboutWidget(w, bjpix, embpix)
  806. XWidget w;
  807. XPixmap bjpix, embpix;
  808. X{
  809. XWidget label1,label2,label3,label4,label5,label6,button;
  810. XArg wargs[20];
  811. Xint n;
  812. XXmString str[7];
  813. XDimension x,j;
  814. X
  815. X
  816. X   about = XmCreateFormDialog(w,"About", NULL, 0);
  817. X   
  818. X   n = 0;
  819. X   XtSetArg(wargs[n], XmNlabelType, XmSTRING); n++;
  820. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  821. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  822. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_FORM); n++;
  823. X   XtSetArg(wargs[n], XmNtopOffset, 20); n++;
  824. X   XtSetArg(wargs[n], XmNrightOffset, 20); n++;
  825. X   XtSetArg(wargs[n], XmNleftOffset, 20); n++;
  826. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  827. X   str[0] = XmStringCreate("En Garde",XmSTRING_DEFAULT_CHARSET);
  828. X   XtSetArg(wargs[n], XmNlabelString, str[0]); n++;
  829. X   label1 = (Widget) XmCreateLabel(about, "AboutTitle", wargs, n);
  830. X   XtManageChild(label1);
  831. X
  832. X   n = 0;
  833. X   XtSetArg(wargs[n], XmNlabelType, XmSTRING); n++;
  834. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  835. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  836. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  837. X   XtSetArg(wargs[n], XmNtopWidget, label1); n++;
  838. X   XtSetArg(wargs[n], XmNtopOffset, 10); n++;
  839. X   XtSetArg(wargs[n], XmNrightOffset, 20); n++;
  840. X   XtSetArg(wargs[n], XmNleftOffset, 20); n++;
  841. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  842. X   str[1] = XmStringCreate("Version 1.0",XmSTRING_DEFAULT_CHARSET);
  843. X   XtSetArg(wargs[n], XmNlabelString, str[1]); n++;
  844. X   label2 = (Widget) XmCreateLabel(about, "AboutVersion", wargs, n);
  845. X   XtManageChild(label2);
  846. X
  847. X   n = 0;
  848. X   XtSetArg(wargs[n], XmNlabelType, XmSTRING); n++;
  849. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  850. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  851. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  852. X   XtSetArg(wargs[n], XmNtopWidget, label2); n++;
  853. X   XtSetArg(wargs[n], XmNtopOffset, 10); n++;
  854. X   XtSetArg(wargs[n], XmNrightOffset, 20); n++;
  855. X   XtSetArg(wargs[n], XmNleftOffset, 20); n++;
  856. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  857. X   str[2] = XmStringCreate("January, 1992",XmSTRING_DEFAULT_CHARSET);
  858. X   XtSetArg(wargs[n], XmNlabelString, str[2]); n++;
  859. X   label3 = (Widget) XmCreateLabel(about, "AboutDate", wargs, n);
  860. X   XtManageChild(label3);
  861. X
  862. X   n = 0;
  863. X   XtSetArg(wargs[n], XmNlabelType, XmSTRING); n++;
  864. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  865. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  866. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  867. X   XtSetArg(wargs[n], XmNtopWidget, label3); n++;
  868. X   XtSetArg(wargs[n], XmNtopOffset, 10); n++;
  869. X   XtSetArg(wargs[n], XmNrightOffset, 20); n++;
  870. X   XtSetArg(wargs[n], XmNleftOffset, 20); n++;
  871. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  872. X   str[3] = XmStringCreate("Bill James",XmSTRING_DEFAULT_CHARSET);
  873. X   XtSetArg(wargs[n], XmNlabelString, str[3]); n++;
  874. X   label4 = (Widget) XmCreateLabel(about, "AboutAuthor", wargs, n);
  875. X   XtManageChild(label4);
  876. X
  877. X   n = 0;
  878. X   XtSetArg(wargs[n], XmNlabelType, XmSTRING); n++;
  879. X   XtSetArg(wargs[n], XmNrightAttachment, XmATTACH_FORM); n++;
  880. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  881. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  882. X   XtSetArg(wargs[n], XmNtopWidget, label4); n++;
  883. X   XtSetArg(wargs[n], XmNtopOffset, 10); n++;
  884. X   XtSetArg(wargs[n], XmNrightOffset, 20); n++;
  885. X   XtSetArg(wargs[n], XmNleftOffset, 20); n++;
  886. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  887. X   str[4] = XmStringCreate("wjames@jupiter.SAIC.COM",XmSTRING_DEFAULT_CHARSET);
  888. X   XtSetArg(wargs[n], XmNlabelString, str[4]); n++;
  889. X   label6 = (Widget) XmCreateLabel(about, "AboutMail", wargs, n);
  890. X   XtManageChild(label6);
  891. X
  892. X   n = 0;
  893. X   XtSetArg(wargs[n], XmNleftAttachment, XmATTACH_FORM); n++;
  894. X   XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  895. X   XtSetArg(wargs[n], XmNtopWidget, label6); n++;
  896. X   XtSetArg(wargs[n], XmNtopOffset, 20); n++;
  897. X   XtSetArg(wargs[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  898. X   XtSetArg(wargs[n], XmNbottomOffset, 20); n++;
  899. X   XtSetArg(wargs[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
  900. X   XtSetArg(wargs[n], XmNlabelPixmap, embpix); n++;
  901. X   XtSetArg(wargs[n], XmNlabelType, XmPIXMAP); n++;
  902. X   XtSetArg(wargs[n], XmNwidth, 100); n++;
  903. X   XtSetArg(wargs[n], XmNheight, 60); n++;
  904. X   XtSetArg(wargs[n], XmNresize, False); n++;
  905. X   button = XmCreateDrawnButton(about, "AboutButton", wargs, n);
  906. X   XtManageChild(button);
  907. X
  908. X   XtAddCallback(button, XmNactivateCallback, CloseAbout, NULL);
  909. X
  910. X   XtRealizeWidget (about);
  911. X   n = 0;
  912. X   XtSetArg(wargs[n], XmNwidth, &x); n++;
  913. X   XtGetValues(about, wargs, n);
  914. X   j = (x - 100) / 2;
  915. X   if (j < 0) j = 0;
  916. X   n = 0;
  917. X   XtSetArg(wargs[n], XmNleftOffset, j); n++;
  918. X   XtSetValues(button, wargs, n);
  919. X
  920. X}
  921. X
  922. END_OF_FILE
  923. if test 14872 -ne `wc -c <'engarde.c'`; then
  924.     echo shar: \"'engarde.c'\" unpacked with wrong size!
  925. fi
  926. # end of 'engarde.c'
  927. fi
  928. if test -f 'help.h' -a "${1}" != "-c" ; then 
  929.   echo shar: Will not clobber existing file \"'help.h'\"
  930. else
  931. echo shar: Extracting \"'help.h'\" \(4562 characters\)
  932. sed "s/^X//" >'help.h' <<'END_OF_FILE'
  933. X/*********************************************************************
  934. X                                Engarde
  935. X                            File: help.h
  936. X
  937. X  This file contains the a C version of the engarde.RULES file to
  938. X  be included into the help window of the game.
  939. X
  940. X  Version 1:  1/9/92  (Bill James)
  941. X*********************************************************************/
  942. X#define HELPLINES    93
  943. Xchar *helpstr[HELPLINES] = {
  944. X"\n",
  945. X"                             ENGARDE v1.0\n",
  946. X"--------------------------------------------------------------------------\n",
  947. X"      A game written for X11R4 with OSF/MOTIF widgets by Bill James.\n",
  948. X"--------------------------------------------------------------------------\n",
  949. X"\n",
  950. X"OBJECT:\n",
  951. X"\n",
  952. X"To have 4 pieces in a row, column, diagonal that are all of one player's \n",
  953. X"color, that player is to be considered the winner.\n",
  954. X"\n",
  955. X"\n",
  956. X"DESIGNATIONS:\n",
  957. X"\n",
  958. X" -  The center set of squares is know as the \"grid\".\n",
  959. X" -  The single columns to the right and left of the grid are\n",
  960. X"      called \"side-bars\", possible preceded by a \"left\" or \"right\".\n",
  961. X" -  The squares and circles are called \"pieces\", with the unfilled\n",
  962. X"      piece being \"white\", and the filled piece being \"black\".\n",
  963. X"\n",
  964. X"\n",
  965. X"CHARACTERISTICS OF THE BOARD:\n",
  966. X"\n",
  967. X"    Each piece is to be considered a magnet with one pole painted \n",
  968. X"white, and the other painted black.  A piece is considered to be\n",
  969. X"white if the white side is face up, else it is black.  On circular \n",
  970. X"pieces the positive side is painted white, while on the squares it \n",
  971. X"is the negative side.  The grid is also merely a set of magnetized \n",
  972. X"squares, with either the positive or negative side facing upwards.\n",
  973. X"The grid also contains spaces that are not magnets at all, but are \n",
  974. X"merely null spots, and do not affect the pieces at all.  \n",
  975. X"\n",
  976. X"Examples:\n",
  977. X"Sample Grid :\n",
  978. X"    \n",
  979. X"   + + - + O -     + = positive grid face up\n",
  980. X"   - - + - + -     - = negative grid face up\n",
  981. X"   O - + - - +     O = null grid space\n",
  982. X"   + + - + + -\n",
  983. X"   - + + O - -\n",
  984. X"   - - - - + +\n",
  985. X"\n",
  986. X"Every new game, the board shuffles it's magnets to form a new\n",
  987. X"grid.\n",
  988. X"\n",
  989. X"When a player moves a piece onto the grid, the magnetic interactions\n",
  990. X"cause the piece to show the color painted on the magnet side with\n",
  991. X"the same polarity as the grid place.  e.g. when a piece moves on\n",
  992. X"a positive grid place, the positive side of the magnet is repulsed, \n",
  993. X"and is therefore face up.\n",
  994. X"\n",
  995. X"  Before Move          After Move Piece is:\n",
  996. X"   Piece is:      When moved onto grid with magnet:\n",
  997. X"--------------------------------------------------\n",
  998. X"| Shape | Color ||| Positive | Negative |  Null  |\n",
  999. X"--------------------------------------------------\n",
  1000. X"|  SQU  |  Wh   |||    Bl    |    Wh    |   Wh   |   \n",
  1001. X"|  SQU  |  Bl   |||    Bl    |    Wh    |   Bl   |\n",
  1002. X"|  CIR  |  Wh   |||    Wh    |    Bl    |   Wh   |\n",
  1003. X"|  CIR  |  Bl   |||    Wh    |    Bl    |   Bl   |\n",
  1004. X"--------------------------------------------------\n",
  1005. X"\n",
  1006. X"RULES OF MOVEMENT:\n",
  1007. X"\n",
  1008. X"The arrows to either side of the message box designate whose turn it is.\n",
  1009. X"This player has the following options:\n",
  1010. X"\n",
  1011. X"1.  The player may take a piece from his side-bar and place it\n",
  1012. X"    on any space on the center grid where there is no other piece.\n",
  1013. X"\n",
  1014. X"2.  The player may move any piece that is currently on the grid\n",
  1015. X"    EXCEPT the last piece moved to another spot guided by these rules:\n",
  1016. X"    2a.  Piece cannot move to occupied place.\n",
  1017. X"    2b.  Piece may only move in one direction.\n",
  1018. X"    2c.  Piece cannot move more than 2 spaces in a single direction,\n",
  1019. X"           either Up, Down, Left, Right, or the Diagonals.\n",
  1020. X"    2d.  Piece may only be moved 2 spaces in a direction if the first\n",
  1021. X"           space in that direction is occupied (it jumps the first piece).\n",
  1022. X"    2e.  Piece may not be placed back onto side-bar.\n",
  1023. X"    \n",
  1024. X"\n",
  1025. X"STRATEGY HINTS:\n",
  1026. X"\n",
  1027. X" - Try to save a piece on your side-bar, being able to place it anywhere\n",
  1028. X"      on the grid may save your neck.\n",
  1029. X"\n",
  1030. X" - Try to keep track of what polarity the grid locations are as you find\n",
  1031. X"      them out, they won't change until the next game.\n",
  1032. X"\n",
  1033. X" - Don't forget about the null spaces.  If a piece keeps the same color\n",
  1034. X"      when it moves, a null space is always a possibility.\n",
  1035. X"\n",
  1036. X"----------------------------------------------------------------------------\n"
  1037. X};
  1038. END_OF_FILE
  1039. if test 4562 -ne `wc -c <'help.h'`; then
  1040.     echo shar: \"'help.h'\" unpacked with wrong size!
  1041. fi
  1042. # end of 'help.h'
  1043. fi
  1044. if test -f 'xboard.c' -a "${1}" != "-c" ; then 
  1045.   echo shar: Will not clobber existing file \"'xboard.c'\"
  1046. else
  1047. echo shar: Extracting \"'xboard.c'\" \(13185 characters\)
  1048. sed "s/^X//" >'xboard.c' <<'END_OF_FILE'
  1049. X/*********************************************************************
  1050. X                                Engarde
  1051. X                            File: xboard.c
  1052. X
  1053. X  This file contains functions to initialize board size data, display
  1054. X  board, and generally deal with all display changes during a game.
  1055. X
  1056. X  Version 1:  1/9/92  (Bill James)
  1057. X*********************************************************************/
  1058. X#include <X11/Intrinsic.h>
  1059. X#include <X11/StringDefs.h>
  1060. X#include <X11/Xutil.h>
  1061. X#include <Xm/Xm.h>
  1062. X#include <Xm/RowColumn.h>
  1063. X#include <Xm/Form.h>
  1064. X#include <Xm/DrawingA.h>
  1065. X#include <Xm/Text.h>
  1066. X#include "board.h"
  1067. X#include "xboard.h"
  1068. X
  1069. Xextern int H,W;
  1070. Xextern SideType s[2];
  1071. Xextern BoardType *b;
  1072. Xextern Widget help; 
  1073. Xextern Widget about; 
  1074. Xextern Widget draw; 
  1075. Xextern Widget mess;
  1076. Xextern Widget lt;
  1077. Xextern Widget rt;
  1078. Xextern Pixel fore, back;
  1079. Xextern Pixmap lturn, rturn, goveright, goverleft;
  1080. X
  1081. X/*  
  1082. X   s1bxx1,bxy1 to s1bxx2,bxy2 =  left side outline.
  1083. X   s2bxx1,bxy1 to s2bxx2,bxy2 =  right side outline.
  1084. X   bxx1,bxy1 to bxx2,bxy2 =  center outline.
  1085. X   delta = size of empty space in grid box.
  1086. X   oy,ox = offsets from left and top side of window to center grid.
  1087. X   wid, hgt = width and height of window.
  1088. X   selected = whether a box is selected or not.
  1089. X   selpt = grid location of selection.
  1090. X   hold = don't allow selections until game is reset.
  1091. X   turn = 0 for left side, 1 for right side.
  1092. X   Last = location of last piece moved
  1093. X*/
  1094. X   
  1095. Xstatic int s1bxx1, s1bxx2, s2bxx1, s2bxx2;  
  1096. Xstatic int bxx1, bxy1, bxx2, bxy2;
  1097. Xstatic int delta, oy, ox; 
  1098. Xstatic Dimension wid, hgt;
  1099. Xstatic int selected = 0;
  1100. Xstatic Pt selpt;
  1101. Xstatic int hold = 0;
  1102. Xstatic int turn = 0;
  1103. Xstatic Pt Last;
  1104. X
  1105. X
  1106. X/*
  1107. X   Draws rectangle from x1,y1 to x2,y2
  1108. X*/
  1109. Xvoid DrawRect(d, w, gc, x1, y1, x2, y2)
  1110. XDisplay *d;
  1111. XWindow w;
  1112. XGC gc;
  1113. Xint x1, y1, x2, y2;
  1114. X{
  1115. X   XDrawLine(d, w, gc, x1, y1, x1, y2);
  1116. X   XDrawLine(d, w, gc, x1, y2, x2, y2);
  1117. X   XDrawLine(d, w, gc, x2, y2, x2, y1);
  1118. X   XDrawLine(d, w, gc, x2, y1, x1, y1);
  1119. X}
  1120. X
  1121. X
  1122. X/*
  1123. X   Figures the scalings necessary to fit the new size of the
  1124. X   window.
  1125. X*/
  1126. Xvoid GetXVals() 
  1127. X{
  1128. XArg wargs[20];
  1129. Xint n, i;
  1130. Xint bx, by;
  1131. X
  1132. X  n = 0;
  1133. X  hgt = 0;
  1134. X  XtSetArg(wargs[n], XmNheight, &hgt); n++;
  1135. X  XtSetArg(wargs[n], XmNwidth, &wid); n++;
  1136. X  XtGetValues(draw, wargs, n); n = 0;
  1137. X
  1138. X  bx = (wid - 22) / 12;
  1139. X  by = (hgt - 14) / 8;
  1140. X  delta = MIN2(bx,by);
  1141. X  if (delta < 0) delta = 0;
  1142. X  ox = (wid - 22 - (delta *12)) / 2 ;
  1143. X  oy = (hgt - 14 - (delta *8)) / 2;
  1144. X
  1145. X  s1bxx1 = ox + delta + 1;
  1146. X  s1bxx2 = s1bxx1 + delta + 3;
  1147. X  s2bxx1 = ox + 10 * delta + 19;
  1148. X  s2bxx2 = s2bxx1 + delta + 3;
  1149. X  bxx1 = ox + 3 * delta + 5;
  1150. X  bxx2 = bxx1 + 6 * delta + 13;
  1151. X  bxy1 = oy + delta + 1;
  1152. X  bxy2 = bxy1 + 6 * delta + 13;
  1153. X
  1154. X
  1155. X}
  1156. X
  1157. X
  1158. X/*
  1159. X   Callback function for resize and expose callbacks.  Draws the
  1160. X   game based upon window size data.
  1161. X*/
  1162. Xvoid DrawGame(w, client_data, call_data)
  1163. XWidget w;
  1164. Xcaddr_t client_data;
  1165. XXmDrawingAreaCallbackStruct call_data;
  1166. X{
  1167. XWindow win;
  1168. XDisplay *display;
  1169. XGC gc;
  1170. XXGCValues gcvals;
  1171. XXtGCMask gc_mask;
  1172. Xint i,j;
  1173. X
  1174. X  GetXVals();
  1175. X  gc_mask = 0;
  1176. X  gc = XtGetGC(draw, gc_mask, &gcvals);
  1177. X  display = XtDisplay(draw);
  1178. X  win = XtWindow(draw);
  1179. X  if (!win) return;
  1180. X
  1181. X  XClearArea(display, win, 0, 0, wid, hgt, 0);
  1182. X
  1183. X  DrawRect(display, win, gc, s1bxx1, bxy1, s1bxx2, bxy2);
  1184. X  DrawRect(display, win, gc, s2bxx1, bxy1, s2bxx2, bxy2);
  1185. X  DrawRect(display, win, gc, bxx1, bxy1, bxx2, bxy2);
  1186. X  for (i = 0; i < H; i++) {
  1187. X     DrawSpace(display, win, gc, DRAWLEFTSIDE, i);
  1188. X     DrawSpace(display, win, gc, DRAWRIGHTSIDE, i);
  1189. X     for (j = 0; j < W; j++) 
  1190. X        DrawSpace(display, win, gc, j, i);
  1191. X  }
  1192. X  for (i = 0; i < H; i++) {
  1193. X     DrawPiece(display, win, gc, DRAWLEFTSIDE, i);
  1194. X     DrawPiece(display, win, gc, DRAWRIGHTSIDE, i);
  1195. X     for (j = 0; j < W; j++) 
  1196. X        DrawPiece(display, win, gc, j, i);
  1197. X  }
  1198. X  XtReleaseGC(draw, gc);
  1199. X}
  1200. X
  1201. X
  1202. X/*
  1203. X   returns the x,y pixel location of grid spot i,j
  1204. X*/
  1205. Xvoid GetSpace(i, j, xy1, xy2)
  1206. Xint i,j;
  1207. XPt *xy1, *xy2;
  1208. X{
  1209. Xint sx;
  1210. X   if (i == DRAWLEFTSIDE) {sx = s1bxx1; i = 0;}
  1211. X   else if (i == DRAWRIGHTSIDE) {sx = s2bxx1; i = 0;}
  1212. X   else sx = bxx1;
  1213. X     
  1214. X   xy1->x = sx + (i * (delta + 2)) + 1;
  1215. X   xy2->x = xy1->x + delta + 1;
  1216. X   xy1->y = bxy1 + (j * (delta + 2)) + 1;
  1217. X   xy2->y = xy1->y + delta + 1;
  1218. X}
  1219. X
  1220. X
  1221. X/*
  1222. X   Draws grid squard i,j
  1223. X*/
  1224. Xvoid DrawSpace(d, w, gc, i, j)
  1225. XDisplay * d;
  1226. XWindow w;
  1227. XGC gc;
  1228. Xint i,j;
  1229. X{
  1230. XPt one, two;
  1231. X   GetSpace(i, j, &one, &two);
  1232. X   DrawRect(d, w, gc, one.x, one.y, two.x, two.y);
  1233. X}
  1234. X
  1235. X
  1236. X/*
  1237. X   Selects grid square i,j
  1238. X*/
  1239. Xvoid SelectSpace(i,j)
  1240. Xint i,j;
  1241. X{
  1242. XPt one, two;
  1243. XDisplay * d;
  1244. XWindow w;
  1245. XGC gc;
  1246. XXGCValues gcvals;
  1247. XXtGCMask gc_mask;
  1248. X  gc_mask = GCForeground | GCBackground;
  1249. X  gcvals.foreground = fore;
  1250. X  gcvals.background = back;
  1251. X  gc = XtGetGC(draw, gc_mask, &gcvals);
  1252. X  d = XtDisplay(draw);
  1253. X  w = XtWindow(draw);
  1254. X  GetSpace(i, j, &one, &two);
  1255. X  DrawRect(d, w, gc, one.x+1, one.y+1, two.x-1, two.y-1);
  1256. X  selected = 1;
  1257. X  XtReleaseGC(draw,gc);
  1258. X  if (!hold) XmTextSetString(mess,"");
  1259. X}
  1260. X
  1261. X
  1262. X/*
  1263. X   Unselects grid square i,j
  1264. X*/
  1265. Xvoid UnselectSpace(i,j)
  1266. Xint i,j;
  1267. X{
  1268. XPt one, two;
  1269. XDisplay * d;
  1270. XWindow w;
  1271. XGC gc;
  1272. Xint l;
  1273. XXGCValues gcvals;
  1274. XXtGCMask gc_mask;
  1275. X  gc_mask = GCForeground | GCBackground;
  1276. X  gcvals.foreground = back;
  1277. X  gcvals.background = fore;
  1278. X  gc = XtGetGC(draw, gc_mask, &gcvals);
  1279. X  d = XtDisplay(draw);
  1280. X  w = XtWindow(draw);
  1281. X  GetSpace(i, j, &one, &two);
  1282. X  DrawRect(d, w, gc, one.x+1, one.y+1, two.x-1, two.y-1);
  1283. X  selected = 0;
  1284. X  XtReleaseGC(draw,gc);
  1285. X}
  1286. X
  1287. X
  1288. X/*
  1289. X   Draws piece depending on shape and color
  1290. X*/
  1291. Xvoid DrawPiece(d, w, gc, i, j) 
  1292. XDisplay * d;
  1293. XWindow w;
  1294. XGC gc;
  1295. Xint i;
  1296. Xint j;
  1297. X{
  1298. XPt one, two;
  1299. Xint x1, y1, x2, y2, ht, wd;
  1300. X  GetSpace(i, j, &one, &two);
  1301. X  x1 = one.x+5;
  1302. X  y1 = one.y+5;
  1303. X  x2 = two.x-5;
  1304. X  y2 = two.y-5;
  1305. X  ht =  y2 - y1+1;
  1306. X  wd =  x2 - x1+1;
  1307. X  if (i == DRAWLEFTSIDE) {
  1308. X     if (s[0].p[j]) {
  1309. X        if (s[0].p[j]->type == PIECE_SQUARE) {
  1310. X           DrawRect(d, w, gc, x1, y1, x2, y2);
  1311. X           if (s[0].p[j]->color == PIECE_BLACK) 
  1312. X              XFillRectangle(d, w, gc, x1, y1, wd, ht);
  1313. X        }
  1314. X        if (s[0].p[j]->type == PIECE_ROUND) {
  1315. X           XDrawArc(d, w, gc, x1, y1, wd, ht, 0, 64*360);
  1316. X           if (s[0].p[j]->color == PIECE_BLACK) 
  1317. X              XFillArc(d, w, gc, x1, y1, wd, ht, 0, 64*360);
  1318. X        }
  1319. X     }
  1320. X  }
  1321. X  else if (i == DRAWRIGHTSIDE) { 
  1322. X     if (s[1].p[j]) {
  1323. X        if (s[1].p[j]->type == PIECE_SQUARE) {
  1324. X           DrawRect(d, w, gc, x1, y1, x2, y2);
  1325. X           if (s[1].p[j]->color == PIECE_BLACK) 
  1326. X              XFillRectangle(d, w, gc, x1, y1, wd, ht);
  1327. X        }
  1328. X        if (s[1].p[j]->type == PIECE_ROUND) {
  1329. X           XDrawArc(d, w, gc, x1, y1, wd, ht, 0, 64*360);
  1330. X           if (s[1].p[j]->color == PIECE_BLACK) 
  1331. X              XFillArc(d, w, gc, x1, y1, wd, ht, 0, 64*360);
  1332. X        }
  1333. X     }
  1334. X  }
  1335. X  else {
  1336. X     if (b->pieces[i][j]) {
  1337. X        if (b->pieces[i][j]->type == PIECE_SQUARE) {
  1338. X           XDrawRectangle(d, w, gc, x1, y1, wd, ht);
  1339. X           if (b->pieces[i][j]->color == PIECE_BLACK) 
  1340. X              XFillRectangle(d, w, gc, x1, y1, wd, ht);
  1341. X        }
  1342. X        if (b->pieces[i][j]->type == PIECE_ROUND) {
  1343. X           XDrawArc(d, w, gc, x1, y1, wd, ht, 0, 64*360);
  1344. X           if (b->pieces[i][j]->color == PIECE_BLACK) 
  1345. X              XFillArc(d, w, gc, x1, y1, wd, ht, 0, 64*360);
  1346. X        }
  1347. X     }
  1348. X  }
  1349. X}
  1350. X
  1351. X
  1352. X/*
  1353. X   Button press callback.  Determines actions based upon location
  1354. X   of pointer when button is pressed, whether a square is already
  1355. X   selected, etc.
  1356. X*/
  1357. Xvoid ButtonPress1 (wg, event, params, num_params)
  1358. XWidget wg;                                       /*The draw widget.*/
  1359. XXButtonEvent *event;                            /*The button event.*/
  1360. XString *params;                                 /*Not used.*/
  1361. XCardinal num_params;                            /*Not used.*/
  1362. X{
  1363. Xint x,y,i,j,m,n;
  1364. XPt t;
  1365. XArg wargs[2];
  1366. X   if (hold) return;
  1367. X   x = event->x;
  1368. X   y = event->y;
  1369. X   if ((y > bxy1) && (y < bxy2)) {
  1370. X      if ((x > s1bxx1) && (x < s1bxx2)) 
  1371. X         i = DRAWLEFTSIDE;
  1372. X      else if ((x > s2bxx1) && (x < s2bxx2)) 
  1373. X         i = DRAWRIGHTSIDE;
  1374. X      else if ((x > bxx1) && (x < bxx2)) 
  1375. X         i = (x-bxx1) / (delta+2);
  1376. X      else return;
  1377. X      j = (y-bxy1) / (delta+2);
  1378. X   }
  1379. X   else return;
  1380. X   if (!selected) {
  1381. X        if (DGetPiece(i,j)) {
  1382. X       SelectSpace(i,j);
  1383. X           selected = 1;
  1384. X           selpt.x = i;
  1385. X           selpt.y = j;
  1386. X        }
  1387. X        else {
  1388. X          XmTextSetString(mess, STR_BAD_SELECT);
  1389. X        }
  1390. X   }
  1391. X   else {
  1392. X        if ((i == selpt.x) && (j == selpt.y)) {
  1393. X           UnselectSpace(selpt.x, selpt.y);
  1394. X           selected = 0;
  1395. X        }
  1396. X        else if (DGetPiece(i,j)) {
  1397. X           UnselectSpace(selpt.x, selpt.y);
  1398. X       SelectSpace(i,j);
  1399. X           selpt.x = i;
  1400. X           selpt.y = j;
  1401. X        }
  1402. X        else {
  1403. X          t.x = i; t.y = j;
  1404. X          if (CheckMove(selpt, t)) {
  1405. X             UnselectSpace(selpt.x, selpt.y);
  1406. X             MvPiece(selpt, t);
  1407. X             Last.x = i; Last.y = j;
  1408. X             selected = 0;
  1409. X             turn ^= 1;
  1410. X             ChangeTurn();
  1411. X          }
  1412. X        }
  1413. X        if (CheckWinner(&i, &j, &x, &y)) {
  1414. X           n = 0;
  1415. X           if (b->pieces[i][j]->color == PIECE_BLACK) {
  1416. X              XmTextSetString(mess,STR_RIGHT_WIN);
  1417. X              XtSetArg(wargs[n],XmNlabelPixmap, goveright); n++;
  1418. X           }
  1419. X           else {
  1420. X              XmTextSetString(mess,STR_LEFT_WIN);
  1421. X              XtSetArg(wargs[n],XmNlabelPixmap, goverleft); n++;
  1422. X           }
  1423. X           hold = 1;
  1424. X           for (m = 0; m < 4; m++) {
  1425. X              SelectSpace(i,j);
  1426. X              i+= x; j+=y;
  1427. X           }
  1428. X           XtSetValues(lt, wargs, n);
  1429. X           XtSetValues(rt, wargs, n);
  1430. X        }
  1431. X           
  1432. X   }
  1433. X}
  1434. X
  1435. X
  1436. X/*
  1437. X   Moves piece from src grid location to dest grid location, rewriting
  1438. X   piece on screen
  1439. X*/
  1440. Xvoid MvPiece(src, dst)
  1441. XPt src,dst;
  1442. X{
  1443. XPt sone, stwo;
  1444. XPt done, dtwo;
  1445. XDisplay * d;
  1446. XWindow w;
  1447. XGC gc;
  1448. Xint l;
  1449. XXGCValues gcvals;
  1450. XXtGCMask gc_mask;
  1451. X  gc_mask = GCForeground | GCBackground;
  1452. X  gcvals.foreground = fore;
  1453. X  gcvals.background = back;
  1454. X  gc = XtGetGC(draw, gc_mask, &gcvals);
  1455. X  d = XtDisplay(draw);
  1456. X  w = XtWindow(draw);
  1457. X  GetSpace(src.x, src.y, &sone, &stwo);
  1458. X  GetSpace(dst.x, dst.y, &done, &dtwo);
  1459. X  XClearArea(d, w, sone.x+1, sone.y+1, delta, delta, 0);
  1460. X  if (dst.x == DRAWLEFTSIDE)
  1461. X     s[0].p[dst.y] = DGetPiece(src.x,src.y);
  1462. X  else if (dst.x == DRAWRIGHTSIDE)
  1463. X     s[1].p[dst.y] = DGetPiece(src.x,src.y);
  1464. X  else 
  1465. X     b->pieces[dst.x][dst.y] = DGetPiece(src.x,src.y);
  1466. X  if (src.x == DRAWLEFTSIDE)
  1467. X     s[0].p[src.y] = NULL;
  1468. X  else if (src.x == DRAWRIGHTSIDE)
  1469. X     s[1].p[src.y] = NULL;
  1470. X  else 
  1471. X     b->pieces[src.x][src.y] = NULL;
  1472. X  if ((dst.x != DRAWLEFTSIDE) && (dst.x != DRAWRIGHTSIDE))
  1473. X     Magnetize(dst.x,dst.y);
  1474. X  DrawPiece(d, w, gc, dst.x, dst.y);
  1475. X  XtReleaseGC(draw, gc);
  1476. X}
  1477. X
  1478. X
  1479. X/*
  1480. X   returns piece at location i,j
  1481. X*/
  1482. XPieceType * DGetPiece(i,j)
  1483. Xint i,j;
  1484. X{
  1485. X  if (i == DRAWLEFTSIDE) 
  1486. X     return (s[0].p[j]);
  1487. X  else if (i == DRAWRIGHTSIDE) 
  1488. X     return (s[1].p[j]);
  1489. X  else 
  1490. X     return (b->pieces[i][j]);
  1491. X}
  1492. X
  1493. X
  1494. X/*
  1495. X    Checks a move against the rules of the games
  1496. X*/
  1497. Xint CheckMove(one, two)
  1498. XPt one, two;
  1499. X{
  1500. Xint i,j,l,m;
  1501. X   if ((one.x == Last.x) && (one.y == Last.y)) {
  1502. X      XmTextSetString(mess,STR_MOVE_LAST);
  1503. X      return(0);
  1504. X   }
  1505. X   if (two.x > W) {
  1506. X      XmTextSetString(mess,STR_SIDE_MOVE);
  1507. X      return(0);
  1508. X   }
  1509. X   if (one.x > W) {
  1510. X      if (turn != (one.x - DRAWLEFTSIDE)) {
  1511. X         XmTextSetString(mess,STR_WRONG_SIDE);
  1512. X         return(0);
  1513. X      }
  1514. X      return(1);
  1515. X   }
  1516. X   i = two.x - one.x;
  1517. X   j = SGN(i);
  1518. X   i = ABS(i);
  1519. X   l = two.y - one.y;
  1520. X   m = SGN(l);
  1521. X   l = ABS(l);
  1522. X   if ((i > 2) || (l > 2)) {
  1523. X      XmTextSetString(mess,STR_FAR_MOVE);
  1524. X      return(0);
  1525. X   }
  1526. X   if ((i == 2) || (l == 2)) {
  1527. X      if (!b->pieces[one.x+((i/2)*j)][one.y+((l/2)*m)]) {
  1528. X         XmTextSetString(mess,STR_MUST_JUMP);
  1529. X         return(0);
  1530. X      }
  1531. X      if ((i == 1) || (l == 1)) {
  1532. X         XmTextSetString(mess,STR_SAME_DIR);
  1533. X         return(0);
  1534. X      }
  1535. X   }
  1536. X   return(1);
  1537. X}
  1538. X
  1539. X
  1540. X/*
  1541. X   Resets the board to start state
  1542. X*/
  1543. Xvoid ResetBoard(w, client_data, call_data)
  1544. XWidget w;
  1545. Xcaddr_t client_data;
  1546. XXmAnyCallbackStruct *call_data;
  1547. X{
  1548. X  KillBoard(s);
  1549. X  InitBoard(s,H,W); 
  1550. X  BoardShuffle();
  1551. X  DrawGame(w,client_data, call_data);
  1552. X  hold = 0;
  1553. X  selected = 0;
  1554. X  Last.x = -1;
  1555. X  Last.y = -1;
  1556. X  turn = 0;
  1557. X  XmTextSetString(mess,"");
  1558. X  ChangeTurn();
  1559. X}
  1560. X
  1561. X
  1562. X/*
  1563. X   Changes the turn pixmaps
  1564. X*/
  1565. Xvoid ChangeTurn() 
  1566. X{
  1567. XArg wargs[10];
  1568. Xint n;
  1569. X  if (turn == 1) {
  1570. X     n = 0;
  1571. X     XtSetArg(wargs[n],XmNlabelPixmap, rturn); n++;
  1572. X     XtSetValues(lt, wargs, n);
  1573. X     XtSetValues(rt, wargs, n);
  1574. X  }
  1575. X  else {
  1576. X     n = 0;
  1577. X     XtSetArg(wargs[n],XmNlabelPixmap, lturn); n++;
  1578. X     XtSetValues(lt, wargs, n);
  1579. X     XtSetValues(rt, wargs, n);
  1580. X  }
  1581. X}
  1582. X
  1583. X
  1584. X/*
  1585. X    Brings up the help window
  1586. X*/
  1587. Xvoid ShowHelp(w, client_data, call_data)
  1588. XWidget w;
  1589. Xcaddr_t client_data;
  1590. XXmAnyCallbackStruct *call_data;
  1591. X{
  1592. X   XtManageChild(help);
  1593. X}
  1594. X
  1595. X
  1596. X/*
  1597. X    Closes the help window
  1598. X*/
  1599. Xvoid CloseHelp(w, client_data, call_data)
  1600. XWidget w;
  1601. Xcaddr_t client_data;
  1602. XXmAnyCallbackStruct *call_data;
  1603. X{
  1604. X   XtUnmanageChild(help);
  1605. X}
  1606. X
  1607. X
  1608. X
  1609. X/*
  1610. X    Brings up the about window
  1611. X*/
  1612. Xvoid ShowAbout(w, client_data, call_data)
  1613. XWidget w;
  1614. Xcaddr_t client_data;
  1615. XXmAnyCallbackStruct *call_data;
  1616. X{
  1617. X   XtManageChild(about);
  1618. X}
  1619. X
  1620. X
  1621. X/*
  1622. X    Closes the about window
  1623. X*/
  1624. Xvoid CloseAbout(w, client_data, call_data)
  1625. XWidget w;
  1626. Xcaddr_t client_data;
  1627. XXmAnyCallbackStruct *call_data;
  1628. X{
  1629. X   XtUnmanageChild(about);
  1630. X}
  1631. END_OF_FILE
  1632. if test 13185 -ne `wc -c <'xboard.c'`; then
  1633.     echo shar: \"'xboard.c'\" unpacked with wrong size!
  1634. fi
  1635. # end of 'xboard.c'
  1636. fi
  1637. if test -f 'xboard.h' -a "${1}" != "-c" ; then 
  1638.   echo shar: Will not clobber existing file \"'xboard.h'\"
  1639. else
  1640. echo shar: Extracting \"'xboard.h'\" \(1062 characters\)
  1641. sed "s/^X//" >'xboard.h' <<'END_OF_FILE'
  1642. X#define DRAWLEFTSIDE    10
  1643. X#define DRAWRIGHTSIDE    11
  1644. X#define STR_BAD_MOVE    "Cannot move there."
  1645. X#define STR_BAD_SELECT  "Space is Empty."
  1646. X#define STR_RIGHT_WIN    "The Right Side WINS!!"
  1647. X#define STR_LEFT_WIN    "The Left Side WINS!!"
  1648. X#define STR_MOVE_LAST    "Cannot move piece last moved by other player."
  1649. X#define STR_SIDE_MOVE   "Cannot move piece back on side bars."
  1650. X#define STR_WRONG_SIDE  "Cannot move piece from other player's side bar."
  1651. X#define STR_FAR_MOVE    "Cannot move piece that far."
  1652. X#define STR_MUST_JUMP   "Cannot move piece 2 spaces without a jump."
  1653. X#define STR_SAME_DIR    "Must move piece 1 or 2 in same direction."
  1654. X
  1655. X#define ABS(x)    (((x)<0)? (-1*(x)):(x))
  1656. X#define SGN(x)    (((x)<0)? -1:(((x) == 0)? 0:1))
  1657. X
  1658. Xstruct _Pt {
  1659. X  int x;
  1660. X  int y;
  1661. X};
  1662. Xtypedef struct _Pt Pt;
  1663. X
  1664. Xvoid DrawGame();
  1665. Xvoid DrawRect();
  1666. Xvoid DrawSpace();
  1667. Xvoid GetXVals();
  1668. Xvoid ResizeGame();
  1669. Xvoid DrawPiece();
  1670. Xvoid ButtonPress1();
  1671. Xvoid MvPiece();
  1672. XPieceType * DGetPiece();
  1673. Xint CheckMove();
  1674. Xvoid ResetBoard();
  1675. Xvoid ChangeTurn();
  1676. Xvoid ShowHelp();
  1677. Xvoid CloseHelp();
  1678. Xvoid ShowAbout();
  1679. Xvoid CloseAbout();
  1680. END_OF_FILE
  1681. if test 1062 -ne `wc -c <'xboard.h'`; then
  1682.     echo shar: \"'xboard.h'\" unpacked with wrong size!
  1683. fi
  1684. # end of 'xboard.h'
  1685. fi
  1686. echo shar: End of archive 1 \(of 2\).
  1687. cp /dev/null ark1isdone
  1688. MISSING=""
  1689. for I in 1 2 ; do
  1690.     if test ! -f ark${I}isdone ; then
  1691.     MISSING="${MISSING} ${I}"
  1692.     fi
  1693. done
  1694. if test "${MISSING}" = "" ; then
  1695.     echo You have unpacked both archives.
  1696.     rm -f ark[1-9]isdone
  1697. else
  1698.     echo You still need to unpack the following archives:
  1699.     echo "        " ${MISSING}
  1700. fi
  1701. ##  End of shell archive.
  1702. exit 0
  1703.