home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / engarde / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-02-04  |  55.6 KB

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