home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / gtetris / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  55.1 KB

  1. Path: uunet!ogicse!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v15i001:  gtetris -  Generic Tetris for X11, Part01/02
  5. Message-ID: <3645@master.CNA.TEK.COM>
  6. Date: 23 Sep 92 19:12:31 GMT
  7. Article-I.D.: master.3645
  8. Sender: news@master.CNA.TEK.COM
  9. Lines: 1818
  10. Approved: billr@saab.CNA.TEK.COM
  11.  
  12. Submitted-by: "Qiang Alex Zhao" <azhao@cs.arizona.edu>
  13. Posting-number: Volume 15, Issue 1
  14. Archive-name: gtetris/Part01
  15. Environment: X11R4/5, Xlib
  16.  
  17.     [I built and ran this, just changing the paths in the Makefile.  -br]
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 1 (of 2)."
  26. # Contents:  README MANIFEST COPYRIGHT data.h tetris.c tetris.h
  27. # Wrapped by billr@saab on Wed Sep 23 12:10:55 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'README' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'README'\"
  31. else
  32. echo shar: Extracting \"'README'\" \(2210 characters\)
  33. sed "s/^X//" >'README' <<'END_OF_FILE'
  34. X    GENERIC TETRIS
  35. X    ==============    Yet Another Tetris Game on X, V1.3
  36. X
  37. X
  38. XWHY ANOTHER?
  39. X
  40. X    Because this one is simple, easy to build, and portable -- actually
  41. X    the blocks are bigger, more comfortable for your eyes. It only uses
  42. X    Xlib -- no "toolkit" kind of thing. I have tested it without
  43. X    modification on the following platforms:
  44. X
  45. X    Sun4, SPARC-2        SunOS 4.1.1    X11R4, X11R5
  46. X    Iris 4D            IRIX 4.0.1    X11R4
  47. X    Sequent S81        DYNIX 3.2.0    X11R5
  48. X
  49. X    If your's is not in this list, please let me know -- thanks.
  50. X
  51. X
  52. XHOW TO BUILD?
  53. X
  54. X    "Make" it. If you want to put the score-file at a different
  55. X    location (I bet you would), edit the Makefile correspondingly.
  56. X
  57. X    "Tetris" is the game. It only lists the top 15 players at the end.
  58. X    "Tscores" will list all the players/scores for you.
  59. X
  60. X
  61. XANYTHING SPECIAL IN PLAYING?
  62. X
  63. X    Use "j" to move left; "l" to move right; "k" to rotate. Left-handed
  64. X    people may want to use "s", "d", "f" respectively. Use the space
  65. X    bar to drop a block quickly.
  66. X
  67. X    Use CTRL-L key combination to redraw -- in case it mess somthing up.
  68. X
  69. X    As usual, "+" and "-" will speed up or lower down the speed. Note
  70. X    that you don't need to press the SHIFT key -- "=" and "_" also
  71. X    work.
  72. X
  73. X    If you press CTRL-S or "p", the game will be paused, and the window
  74. X    will be iconified -- just in case your boss suddenly appears at
  75. X    your door. ;o)
  76. X
  77. X
  78. XFOUND A BUG?
  79. X
  80. X    Send bugs (or their reports, or fixes) to the author:
  81. X
  82. X    Qiang Alex Zhao,    azhao@cs.arizona.edu
  83. X    Computer Science Department
  84. X    University of Arizona
  85. X    Tucson, AZ 85721
  86. X
  87. X    Refter to the "COPYRIGHT" notice in the "COPYRIGHT" file (yeah, as
  88. X    its name implies).
  89. X
  90. X
  91. XHISTORY -- Oh no, not again: I failed in my history course!
  92. XWell ... ACKNOWLEDGEMENTS
  93. X
  94. X    I studied an old tetris game for X10, wrote by Wayne Christopher
  95. X    <faustus@cs.berkeley.edu> in 1988; then I adopted the ideas in
  96. X    representing those "blocks" and rotating them, and added X11
  97. X    stuff. Also I learned a lot from Nathan Sidwell's great game
  98. X    "xmris", e.g. the "iconifying pause".
  99. X
  100. XCHANGES
  101. X
  102. X  [Sep 23, 92]  V1.3: Scoring -- a line in a higher level worth more
  103. X        points; "tscores" program.
  104. X
  105. X  [Sep ??, 92]    First set of versions, 1.0 through 1.2.
  106. X
  107. END_OF_FILE
  108. if test 2210 -ne `wc -c <'README'`; then
  109.     echo shar: \"'README'\" unpacked with wrong size!
  110. fi
  111. # end of 'README'
  112. fi
  113. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  114.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  115. else
  116. echo shar: Extracting \"'MANIFEST'\" \(393 characters\)
  117. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  118. X   File Name        Archive #    Description
  119. X-----------------------------------------------------------
  120. X COPYRIGHT                  1    
  121. X MANIFEST                   1    This shipping list
  122. X Makefile                   2    
  123. X README                     1    
  124. X data.h                     1    
  125. X die.c                      2    
  126. X tetris.c                   1    
  127. X tetris.h                   1    
  128. X tscores.c                  2    
  129. END_OF_FILE
  130. if test 393 -ne `wc -c <'MANIFEST'`; then
  131.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  132. fi
  133. # end of 'MANIFEST'
  134. fi
  135. if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  136.   echo shar: Will not clobber existing file \"'COPYRIGHT'\"
  137. else
  138. echo shar: Extracting \"'COPYRIGHT'\" \(848 characters\)
  139. sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
  140. X# GENERIC X-WINDOW-BASED TETRIS
  141. X#
  142. X#  Copyright (C) 1992    Qiang Alex Zhao
  143. X#            Computer Science Dept, University of Arizona
  144. X#            azhao@cs.arizona.edu
  145. X#
  146. X#            All Rights Reserved
  147. X#
  148. X#  Permission to use, copy, modify, and distribute this software and
  149. X#  its documentation for any purpose and without fee is hereby granted,
  150. X#  provided that the above copyright notice appear in all copies and
  151. X#  that both that copyright notice and this permission notice appear in
  152. X#  supporting documentation, and that the name of the author not be
  153. X#  used in advertising or publicity pertaining to distribution of the
  154. X#  software without specific, written prior permission.
  155. X#
  156. X#  This program is distributed in the hope that it will be "playable",
  157. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  158. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  159. X#
  160. X
  161. END_OF_FILE
  162. if test 848 -ne `wc -c <'COPYRIGHT'`; then
  163.     echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
  164. fi
  165. # end of 'COPYRIGHT'
  166. fi
  167. if test -f 'data.h' -a "${1}" != "-c" ; then 
  168.   echo shar: Will not clobber existing file \"'data.h'\"
  169. else
  170. echo shar: Extracting \"'data.h'\" \(19903 characters\)
  171. sed "s/^X//" >'data.h' <<'END_OF_FILE'
  172. X/*
  173. X# GENERIC X-WINDOW-BASED TETRIS
  174. X#
  175. X#    data.h
  176. X#
  177. X###
  178. X#
  179. X#  Copyright (C) 1992    Qiang Alex Zhao
  180. X#            Computer Science Dept, University of Arizona
  181. X#            azhao@cs.arizona.edu
  182. X#
  183. X#            All Rights Reserved
  184. X#
  185. X#  Permission to use, copy, modify, and distribute this software and
  186. X#  its documentation for any purpose and without fee is hereby granted,
  187. X#  provided that the above copyright notice appear in all copies and
  188. X#  that both that copyright notice and this permission notice appear in
  189. X#  supporting documentation, and that the name of the author not be
  190. X#  used in advertising or publicity pertaining to distribution of the
  191. X#  software without specific, written prior permission.
  192. X#
  193. X#  This program is distributed in the hope that it will be "playable",
  194. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  195. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  196. X#
  197. X*/
  198. X
  199. X#define rot00_width 30
  200. X#define rot00_height 30
  201. Xstatic char rot00_bits[] = {
  202. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x03, 0xf8, 0xff, 0xff, 0x07,
  203. X   0x5c, 0x55, 0x55, 0x0f, 0xae, 0xaa, 0xaa, 0x1e, 0x56, 0x55, 0x55, 0x1d,
  204. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  205. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  206. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  207. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  208. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  209. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  210. X   0xae, 0xaa, 0xaa, 0x1a, 0x5e, 0x55, 0x55, 0x1d, 0xbc, 0xaa, 0xaa, 0x0e,
  211. X   0xf8, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  212. X
  213. X#define rot01_width 30
  214. X#define rot01_height 30
  215. Xstatic char rot01_bits[] = {
  216. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x07,
  217. X   0x55, 0x55, 0x55, 0x0f, 0xaa, 0xaa, 0xaa, 0x1e, 0x55, 0x55, 0x55, 0x1d,
  218. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  219. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  220. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  221. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  222. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  223. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  224. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x0e,
  225. X   0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  226. X
  227. X#define rot02_width 30
  228. X#define rot02_height 30
  229. Xstatic char rot02_bits[] = {
  230. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x03, 0xf8, 0xff, 0xff, 0x07,
  231. X   0x5c, 0x55, 0x55, 0x0f, 0xae, 0xaa, 0xaa, 0x1e, 0x56, 0x55, 0x55, 0x1d,
  232. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  233. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  234. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  235. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  236. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  237. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  238. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  239. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d};
  240. X
  241. X#define rot03_width 30
  242. X#define rot03_height 30
  243. Xstatic char rot03_bits[] = {
  244. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x07,
  245. X   0x55, 0x55, 0x55, 0x0f, 0xaa, 0xaa, 0xaa, 0x1e, 0x55, 0x55, 0x55, 0x1d,
  246. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  247. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  248. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  249. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  250. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  251. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  252. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  253. X   0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d};
  254. X
  255. X#define rot04_width 30
  256. X#define rot04_height 30
  257. Xstatic char rot04_bits[] = {
  258. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0x3f,
  259. X   0x5c, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  260. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  261. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  262. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  263. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  264. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  265. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  266. X   0xae, 0xaa, 0xaa, 0x2a, 0x5e, 0x55, 0x55, 0x15, 0xbc, 0xaa, 0xaa, 0x2a,
  267. X   0xf8, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  268. X
  269. X#define rot05_width 30
  270. X#define rot05_height 30
  271. Xstatic char rot05_bits[] = {
  272. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f,
  273. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  274. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  275. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  276. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0x6a, 0xaa, 0x2a,
  277. X   0x55, 0x95, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  278. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  279. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  280. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  281. X   0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  282. X
  283. X#define rot06_width 30
  284. X#define rot06_height 30
  285. Xstatic char rot06_bits[] = {
  286. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0x3f,
  287. X   0x5c, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  288. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  289. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  290. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  291. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  292. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  293. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  294. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  295. X   0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d};
  296. X
  297. X#define rot07_width 30
  298. X#define rot07_height 30
  299. Xstatic char rot07_bits[] = {
  300. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f,
  301. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  302. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  303. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  304. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0x6a, 0xaa, 0x2a,
  305. X   0x55, 0x95, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  306. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  307. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  308. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  309. X   0x57, 0x55, 0x55, 0x3d, 0xaf, 0xaa, 0xaa, 0x3a, 0x57, 0x55, 0x55, 0x3d};
  310. X
  311. X#define rot08_width 30
  312. X#define rot08_height 30
  313. Xstatic char rot08_bits[] = {
  314. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  315. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  316. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  317. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  318. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  319. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  320. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  321. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  322. X   0xae, 0xaa, 0xaa, 0x1a, 0x5e, 0x55, 0x55, 0x1d, 0xbc, 0xaa, 0xaa, 0x0e,
  323. X   0xf8, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  324. X
  325. X#define rot09_width 30
  326. X#define rot09_height 30
  327. Xstatic char rot09_bits[] = {
  328. X   0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a,
  329. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  330. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  331. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  332. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  333. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  334. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  335. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  336. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x0e,
  337. X   0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  338. X
  339. X#define rot10_width 30
  340. X#define rot10_height 30
  341. Xstatic char rot10_bits[] = {
  342. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  343. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  344. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  345. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  346. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  347. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  348. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  349. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  350. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  351. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d};
  352. X
  353. X#define rot11_width 30
  354. X#define rot11_height 30
  355. Xstatic char rot11_bits[] = {
  356. X   0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a,
  357. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  358. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  359. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  360. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  361. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  362. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  363. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  364. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  365. X   0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d};
  366. X
  367. X#define rot12_width 30
  368. X#define rot12_height 30
  369. Xstatic char rot12_bits[] = {
  370. X   0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a,
  371. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  372. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  373. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  374. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  375. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  376. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  377. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  378. X   0xae, 0xaa, 0xaa, 0x2a, 0x5e, 0x55, 0x55, 0x15, 0xbc, 0xaa, 0xaa, 0x2a,
  379. X   0xf8, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  380. X
  381. X#define rot13_width 30
  382. X#define rot13_height 30
  383. Xstatic char rot13_bits[] = {
  384. X   0xaf, 0xaa, 0xaa, 0x3a, 0x57, 0x55, 0x55, 0x3d, 0xaf, 0xaa, 0xaa, 0x3a,
  385. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  386. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  387. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  388. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0x6a, 0xaa, 0x2a,
  389. X   0x55, 0x95, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  390. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  391. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  392. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  393. X   0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  394. X
  395. X#define rot14_width 30
  396. X#define rot14_height 30
  397. Xstatic char rot14_bits[] = {
  398. X   0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a,
  399. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  400. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  401. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  402. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  403. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  404. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  405. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  406. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  407. X   0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d};
  408. X
  409. Xstruct bitmap_datum {
  410. X    char           *data;
  411. X    int             height, width;
  412. X}               bitmap_data[] = {
  413. X
  414. X    {
  415. X    rot00_bits, rot00_height, rot00_width
  416. X    },
  417. X    {
  418. X    rot01_bits, rot01_height, rot01_width
  419. X    },
  420. X    {
  421. X    rot02_bits, rot02_height, rot02_width
  422. X    },
  423. X    {
  424. X    rot03_bits, rot03_height, rot03_width
  425. X    },
  426. X    {
  427. X    rot04_bits, rot04_height, rot04_width
  428. X    },
  429. X    {
  430. X    rot05_bits, rot05_height, rot05_width
  431. X    },
  432. X    {
  433. X    rot06_bits, rot06_height, rot06_width
  434. X    },
  435. X    {
  436. X    rot07_bits, rot07_height, rot07_width
  437. X    },
  438. X    {
  439. X    rot08_bits, rot08_height, rot08_width
  440. X    },
  441. X    {
  442. X    rot09_bits, rot09_height, rot09_width
  443. X    },
  444. X    {
  445. X    rot10_bits, rot10_height, rot10_width
  446. X    },
  447. X    {
  448. X    rot11_bits, rot11_height, rot11_width
  449. X    },
  450. X    {
  451. X    rot12_bits, rot12_height, rot12_width
  452. X    },
  453. X    {
  454. X    rot13_bits, rot13_height, rot13_width
  455. X    },
  456. X    {
  457. X    rot14_bits, rot14_height, rot14_width
  458. X    }
  459. X};
  460. X
  461. Xpattern_t       patterns[] = {
  462. X    {0, "magenta", "white", 0, 0, 0},
  463. X    {1, "magenta", "white", 0, 0, 0},
  464. X    {2, "magenta", "white", 0, 0, 0},
  465. X    {3, "magenta", "white", 0, 0, 0},
  466. X    {4, "magenta", "white", 0, 0, 0},
  467. X    {5, "magenta", "white", 0, 0, 0},
  468. X    {6, "magenta", "white", 0, 0, 0},
  469. X    {7, "magenta", "white", 0, 0, 0},
  470. X    {8, "magenta", "white", 0, 0, 0},
  471. X    {9, "magenta", "white", 0, 0, 0},
  472. X    {10, "magenta", "white", 0, 0, 0},
  473. X    {11, "magenta", "white", 0, 0, 0},
  474. X    {12, "magenta", "white", 0, 0, 0},
  475. X    {13, "magenta", "white", 0, 0, 0},
  476. X    {14, "magenta", "white", 0, 0, 0},
  477. X    {0, "magenta", "white", 0, 0, 0},
  478. X    {0, "forest green", "white", 0, 0, 0},
  479. X    {1, "forest green", "white", 0, 0, 0},
  480. X    {2, "forest green", "white", 0, 0, 0},
  481. X    {3, "forest green", "white", 0, 0, 0},
  482. X    {4, "forest green", "white", 0, 0, 0},
  483. X    {5, "forest green", "white", 0, 0, 0},
  484. X    {6, "forest green", "white", 0, 0, 0},
  485. X    {7, "forest green", "white", 0, 0, 0},
  486. X    {8, "forest green", "white", 0, 0, 0},
  487. X    {9, "forest green", "white", 0, 0, 0},
  488. X    {10, "forest green", "white", 0, 0, 0},
  489. X    {11, "forest green", "white", 0, 0, 0},
  490. X    {12, "forest green", "white", 0, 0, 0},
  491. X    {13, "forest green", "white", 0, 0, 0},
  492. X    {14, "forest green", "white", 0, 0, 0},
  493. X    {0, "forest green", "white", 0, 0, 0},
  494. X    {0, "blue", "white", 0, 0, 0},
  495. X    {1, "blue", "white", 0, 0, 0},
  496. X    {2, "blue", "white", 0, 0, 0},
  497. X    {3, "blue", "white", 0, 0, 0},
  498. X    {4, "blue", "white", 0, 0, 0},
  499. X    {5, "blue", "white", 0, 0, 0},
  500. X    {6, "blue", "white", 0, 0, 0},
  501. X    {7, "blue", "white", 0, 0, 0},
  502. X    {8, "blue", "white", 0, 0, 0},
  503. X    {9, "blue", "white", 0, 0, 0},
  504. X    {10, "blue", "white", 0, 0, 0},
  505. X    {11, "blue", "white", 0, 0, 0},
  506. X    {12, "blue", "white", 0, 0, 0},
  507. X    {13, "blue", "white", 0, 0, 0},
  508. X    {14, "blue", "white", 0, 0, 0},
  509. X    {0, "blue", "white", 0, 0, 0},
  510. X    {0, "red", "white", 0, 0, 0},
  511. X    {1, "red", "white", 0, 0, 0},
  512. X    {2, "red", "white", 0, 0, 0},
  513. X    {3, "red", "white", 0, 0, 0},
  514. X    {4, "red", "white", 0, 0, 0},
  515. X    {5, "red", "white", 0, 0, 0},
  516. X    {6, "red", "white", 0, 0, 0},
  517. X    {7, "red", "white", 0, 0, 0},
  518. X    {8, "red", "white", 0, 0, 0},
  519. X    {9, "red", "white", 0, 0, 0},
  520. X    {10, "red", "white", 0, 0, 0},
  521. X    {11, "red", "white", 0, 0, 0},
  522. X    {12, "red", "white", 0, 0, 0},
  523. X    {13, "red", "white", 0, 0, 0},
  524. X    {14, "red", "white", 0, 0, 0},
  525. X    {0, "red", "white", 0, 0, 0},
  526. X    {0, "dark turquoise", "white", 0, 0, 0},
  527. X    {1, "dark turquoise", "white", 0, 0, 0},
  528. X    {2, "dark turquoise", "white", 0, 0, 0},
  529. X    {3, "dark turquoise", "white", 0, 0, 0},
  530. X    {4, "dark turquoise", "white", 0, 0, 0},
  531. X    {5, "dark turquoise", "white", 0, 0, 0},
  532. X    {6, "dark turquoise", "white", 0, 0, 0},
  533. X    {7, "dark turquoise", "white", 0, 0, 0},
  534. X    {8, "dark turquoise", "white", 0, 0, 0},
  535. X    {9, "dark turquoise", "white", 0, 0, 0},
  536. X    {10, "dark turquoise", "white", 0, 0, 0},
  537. X    {11, "dark turquoise", "white", 0, 0, 0},
  538. X    {12, "dark turquoise", "white", 0, 0, 0},
  539. X    {13, "dark turquoise", "white", 0, 0, 0},
  540. X    {14, "dark turquoise", "white", 0, 0, 0},
  541. X    {0, "dark turquoise", "white", 0, 0, 0},
  542. X    {0, "black", "white", 0, 0, 0},
  543. X    {1, "black", "white", 0, 0, 0},
  544. X    {2, "black", "white", 0, 0, 0},
  545. X    {3, "black", "white", 0, 0, 0},
  546. X    {4, "black", "white", 0, 0, 0},
  547. X    {5, "black", "white", 0, 0, 0},
  548. X    {6, "black", "white", 0, 0, 0},
  549. X    {7, "black", "white", 0, 0, 0},
  550. X    {8, "black", "white", 0, 0, 0},
  551. X    {9, "black", "white", 0, 0, 0},
  552. X    {10, "black", "white", 0, 0, 0},
  553. X    {11, "black", "white", 0, 0, 0},
  554. X    {12, "black", "white", 0, 0, 0},
  555. X    {13, "black", "white", 0, 0, 0},
  556. X    {14, "black", "white", 0, 0, 0},
  557. X    {0, "brown", "white", 0, 0, 0},
  558. X    {0, "brown", "white", 0, 0, 0},
  559. X    {1, "brown", "white", 0, 0, 0},
  560. X    {2, "brown", "white", 0, 0, 0},
  561. X    {3, "brown", "white", 0, 0, 0},
  562. X    {4, "brown", "white", 0, 0, 0},
  563. X    {5, "brown", "white", 0, 0, 0},
  564. X    {6, "brown", "white", 0, 0, 0},
  565. X    {7, "brown", "white", 0, 0, 0},
  566. X    {8, "brown", "white", 0, 0, 0},
  567. X    {9, "brown", "white", 0, 0, 0},
  568. X    {10, "brown", "white", 0, 0, 0},
  569. X    {11, "brown", "white", 0, 0, 0},
  570. X    {12, "brown", "white", 0, 0, 0},
  571. X    {13, "brown", "white", 0, 0, 0},
  572. X    {14, "brown", "white", 0, 0, 0},
  573. X    {0, "brown", "white", 0, 0, 0}
  574. X};
  575. X
  576. X#define NUM_PATTERNS    (sizeof (patterns) / sizeof (patterns[0]))
  577. X
  578. Xint             num_patterns = NUM_PATTERNS;
  579. X
  580. Xthing_t         possible[] = {
  581. X
  582. X    {{{0, 0, 0, 0},
  583. X    {1, 1, 1, 1},
  584. X    {0, 0, 0, 0},
  585. X    {0, 0, 0, 0}}, 0, 0, 4, 1},
  586. X
  587. X    {{{0, 1, 0, 0},
  588. X    {0, 1, 0, 0},
  589. X    {1, 1, 0, 0},
  590. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  591. X
  592. X    {{{1, 0, 0, 0},
  593. X    {1, 0, 0, 0},
  594. X    {1, 1, 0, 0},
  595. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  596. X
  597. X    {{{0, 1, 0, 0},
  598. X    {1, 1, 0, 0},
  599. X    {1, 0, 0, 0},
  600. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  601. X
  602. X    {{{1, 0, 0, 0},
  603. X    {1, 1, 0, 0},
  604. X    {0, 1, 0, 0},
  605. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  606. X
  607. X    {{{1, 1, 0, 0},
  608. X    {1, 1, 0, 0},
  609. X    {0, 0, 0, 0},
  610. X    {0, 0, 0, 0}}, 0, 0, 2, 1},
  611. X
  612. X    {{{0, 1, 0, 0},
  613. X    {1, 1, 1, 0},
  614. X    {0, 0, 0, 0},
  615. X    {0, 0, 0, 0}}, 0, 0, 3, 2},
  616. X};
  617. X
  618. X#define NUM_POSSIBLE    (sizeof (possible) / sizeof (possible[0]))
  619. X
  620. Xint             speeds[NUM_LEVELS] =
  621. X    {100, 80, 65, 50, 40, 33, 26, 20, 15, 10, 7, 5};
  622. X
  623. Xint             thresh[NUM_LEVELS] =
  624. X    {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, INF};
  625. X
  626. X/* variables used in tetris.c */
  627. X
  628. XXColor          bgcolor, bdcolor, titlecolor, textcolor;
  629. XColormap        cmap;
  630. X
  631. XDisplay        *disp;
  632. XGC              gc_t;
  633. XGC              gc_w;
  634. XGC              gc_w2;
  635. XGC              gc_ttx;
  636. XGC              gc_wtx;
  637. XGC              gc_pat[NUM_PATTERNS];
  638. XXGCValues       gcv;
  639. XXGCValues       color;
  640. XXGCValues       text;
  641. X
  642. END_OF_FILE
  643. if test 19903 -ne `wc -c <'data.h'`; then
  644.     echo shar: \"'data.h'\" unpacked with wrong size!
  645. fi
  646. # end of 'data.h'
  647. fi
  648. if test -f 'tetris.c' -a "${1}" != "-c" ; then 
  649.   echo shar: Will not clobber existing file \"'tetris.c'\"
  650. else
  651. echo shar: Extracting \"'tetris.c'\" \(23128 characters\)
  652. sed "s/^X//" >'tetris.c' <<'END_OF_FILE'
  653. X/*
  654. X# GENERIC X-WINDOW-BASED TETRIS
  655. X#
  656. X#    tetris.c
  657. X#
  658. X###
  659. X#
  660. X#  Copyright (C) 1992    Qiang Alex Zhao
  661. X#            Computer Science Dept, University of Arizona
  662. X#            azhao@cs.arizona.edu
  663. X#
  664. X#            All Rights Reserved
  665. X#
  666. X#  Permission to use, copy, modify, and distribute this software and
  667. X#  its documentation for any purpose and without fee is hereby granted,
  668. X#  provided that the above copyright notice appear in all copies and
  669. X#  that both that copyright notice and this permission notice appear in
  670. X#  supporting documentation, and that the name of the author not be
  671. X#  used in advertising or publicity pertaining to distribution of the
  672. X#  software without specific, written prior permission.
  673. X#
  674. X#  This program is distributed in the hope that it will be "playable",
  675. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  676. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  677. X#
  678. X*/
  679. X
  680. X/* first tetris.h, then data.h */
  681. X#include "tetris.h"
  682. X#include "data.h"
  683. X
  684. Xvoid
  685. Xmain(argc, argv)
  686. X    int             argc;
  687. X    char          **argv;
  688. X{
  689. X    int             start_level = 0, lines_full = 0;
  690. X    field_t        *field;
  691. X    thing_t        *thing = NULL;
  692. X    int             readfds, writefds, exceptfds;
  693. X    struct timeval  nextfall, now, delay;
  694. X    struct timezone tzone;
  695. X    Bool            reset_time = True;
  696. X    char            buf[100];
  697. X
  698. X
  699. X    fprintf(stderr, "\t\tGENERIC TETRIS V1.3\n");
  700. X    fprintf(stderr, "\tCopyright (C) 1992    Qiang Alex Zhao\n\n");
  701. X    fprintf(stderr, "GENERIC TETRIS comes with ABSOLUTELY NO WARRANTY.\n");
  702. X    fprintf(stderr, "Send bug-reports/fixes/comments to:\n");
  703. X    fprintf(stderr, "\tQiang Alex Zhao,    azhao@cs.arizona.edu\n");
  704. X    fprintf(stderr, "\tComputer Science Dept, University of Arizona, Tucson\n\n");
  705. X
  706. X    /* initialization */
  707. X
  708. X    start_level = 3;
  709. X    lines_full = 0;
  710. X
  711. X    if (argc > 3) {
  712. X    Usage(argv);
  713. X    }
  714. X    if (argc > 1) {
  715. X    if (sscanf(argv[1], "%d", &start_level) < 1) {
  716. X        Usage(argv);
  717. X    }
  718. X    }
  719. X    if (argc > 2) {
  720. X    if (sscanf(argv[2], "%d", &lines_full) < 1) {
  721. X        Usage(argv);
  722. X    }
  723. X    }
  724. X
  725. X    if (start_level < 0) start_level = 0;
  726. X    if (start_level >= NUM_LEVELS) start_level = NUM_LEVELS - 1;
  727. X    if (lines_full < 0) lines_full = 0;
  728. X    if (lines_full >= DEF_HEIGHT - 2) lines_full = DEF_HEIGHT - 3;
  729. X
  730. X    srandom((int) time(NULL));
  731. X
  732. X    if ((disp = XOpenDisplay(NULL)) == NULL) {
  733. X    fprintf(stderr, "Error: can't open display \"%s\".\n\n",
  734. X        XDisplayName(NULL));
  735. X    showHighScores(SHOWNSCORES/2);
  736. X    exit(1);
  737. X    }
  738. X
  739. X    /* rebinding keypad */
  740. X    XRebindKeysym(disp, XK_R7,    NULL, 0, "j", sizeof(char));
  741. X    XRebindKeysym(disp, XK_R10,   NULL, 0, "j", sizeof(char));
  742. X    XRebindKeysym(disp, XK_R13,   NULL, 0, "j", sizeof(char));
  743. X    XRebindKeysym(disp, XK_Left,  NULL, 0, "j", sizeof(char));
  744. X    XRebindKeysym(disp, XK_R8,    NULL, 0, "k", sizeof(char));
  745. X    XRebindKeysym(disp, XK_R11,   NULL, 0, "k", sizeof(char));
  746. X    XRebindKeysym(disp, XK_R14,   NULL, 0, "k", sizeof(char));
  747. X    XRebindKeysym(disp, XK_Up,    NULL, 0, "k", sizeof(char));
  748. X    XRebindKeysym(disp, XK_Down,  NULL, 0, "k", sizeof(char));
  749. X    XRebindKeysym(disp, XK_R9,    NULL, 0, "l", sizeof(char));
  750. X    XRebindKeysym(disp, XK_R12,   NULL, 0, "l", sizeof(char));
  751. X    XRebindKeysym(disp, XK_R15,   NULL, 0, "l", sizeof(char));
  752. X    XRebindKeysym(disp, XK_Right, NULL, 0, "l", sizeof(char));
  753. X
  754. X    /* setting color */
  755. X    if (XDisplayPlanes(disp, DefaultScreen(disp)) == 1) {
  756. X    bgcolor.pixel = WhitePixel(disp, DefaultScreen(disp));
  757. X    bdcolor.pixel = BlackPixel(disp, DefaultScreen(disp));
  758. X    titlecolor.pixel = BlackPixel(disp, DefaultScreen(disp));
  759. X    textcolor.pixel = BlackPixel(disp, DefaultScreen(disp));
  760. X    } else {
  761. X    cmap = XDefaultColormap(disp, DefaultScreen(disp));
  762. X    XParseColor(disp, cmap, BG_COLOR, &bgcolor);
  763. X    XAllocColor(disp, cmap, &bgcolor);
  764. X    XParseColor(disp, cmap, BD_COLOR, &bdcolor);
  765. X    XAllocColor(disp, cmap, &bdcolor);
  766. X    XParseColor(disp, cmap, TITLE_COLOR, &titlecolor);
  767. X    XAllocColor(disp, cmap, &titlecolor);
  768. X    XParseColor(disp, cmap, TEXT_COLOR, &textcolor);
  769. X    XAllocColor(disp, cmap, &textcolor);
  770. X    }
  771. X
  772. X    /* initialize the playground */
  773. X
  774. X    field = initField(DEF_WIDTH, DEF_HEIGHT, lines_full);
  775. X    XSelectInput(disp, field->title, ExposureMask);
  776. X
  777. X    initPixmaps(field);
  778. X
  779. X    field->level = start_level;
  780. X
  781. X    drawField(field);
  782. X
  783. X    sleep(1);
  784. X    XSelectInput(disp, field->frame, KeyPressMask | ExposureMask | 
  785. X    StructureNotifyMask);
  786. X
  787. X    while (True) {
  788. X    if (reset_time) {
  789. X        gettimeofday(&nextfall, &tzone);
  790. X        nextfall.tv_usec += 10000 * speeds[field->level];
  791. X        normTimeVal(&nextfall);
  792. X    }
  793. X    if (XPending(disp))
  794. X        handleEvents(field, &thing, False);
  795. X    gettimeofday(&now, &tzone);
  796. X    delay.tv_sec = nextfall.tv_sec - now.tv_sec;
  797. X    delay.tv_usec = nextfall.tv_usec - now.tv_usec;
  798. X    normTimeVal(&delay);
  799. X    if (delay.tv_sec >= 0) {
  800. X        writefds = exceptfds = 0;
  801. X        readfds = 1 << ConnectionNumber(disp);
  802. X        (void) select(sizeof(int) * 8, (fd_set *) &readfds, (fd_set *)
  803. X        &writefds, (fd_set *) &exceptfds, &delay);
  804. X    }
  805. X    gettimeofday(&now, &tzone);
  806. X    if ((now.tv_sec > nextfall.tv_sec) ||
  807. X        ((now.tv_sec == nextfall.tv_sec) &&
  808. X         (now.tv_usec > nextfall.tv_usec))) {
  809. X        handleEvents(field, &thing, True);
  810. X        reset_time = True;
  811. X    } else {
  812. X        handleEvents(field, &thing, False);
  813. X        reset_time = False;
  814. X    }
  815. X    }
  816. X    /* never come to here */
  817. X}
  818. X
  819. Xvoid
  820. XnormTimeVal(tv)
  821. X    struct timeval *tv;
  822. X{
  823. X    while (tv->tv_usec < 0) {
  824. X    tv->tv_sec--;
  825. X    tv->tv_usec += MILLION;
  826. X    }
  827. X    while (tv->tv_usec >= MILLION) {
  828. X    tv->tv_sec++;
  829. X    tv->tv_usec -= MILLION;
  830. X    }
  831. X
  832. X    return;
  833. X}
  834. X
  835. Xvoid
  836. XfallDown(field, thingp, eat)
  837. X    field_t        *field;
  838. X    thing_t       **thingp;
  839. X    Bool            eat;
  840. X{
  841. X    int             lines;
  842. X    XEvent          event;
  843. X
  844. X    putBoxes(field, *thingp);
  845. X
  846. X    lines = checkLine(field);
  847. X    field->score += 5 + 5 * field->level * field->level * lines;
  848. X    field->lines += lines;
  849. X    if (field->lines >= thresh[field->level])
  850. X        field->level++;
  851. X    updateScore(field);
  852. X
  853. X    free((char *) *thingp);
  854. X    if (eat) {
  855. X    *thingp = NULL;
  856. X    while (XPending(disp)) XNextEvent(disp, &event);
  857. X    }
  858. X    *thingp = makeNewThing(field);
  859. X    if (overlapping(field, *thingp)) die(field);
  860. X    drawThing(field, *thingp);
  861. X}
  862. X
  863. Xvoid
  864. XhandleEvents(field, thingp, fall_down)
  865. X    field_t        *field;
  866. X    thing_t       **thingp;
  867. X    Bool            fall_down;
  868. X{
  869. X    static Bool     frozen = False;
  870. X    XEvent          event;
  871. X    int             highest;
  872. X    char            s[4];
  873. X    int             n;
  874. X
  875. X    if (frozen) fall_down = False;
  876. X
  877. X    if (!*thingp) {
  878. X    *thingp = makeNewThing(field);
  879. X    if (overlapping(field, *thingp))
  880. X        die(field);
  881. X    drawThing(field, *thingp);
  882. X    XSync(disp, 0);
  883. X    }
  884. X    if (fall_down && atBottom(field, *thingp)) {
  885. X    fallDown(field, thingp, False);
  886. X    fall_down = False;
  887. X    }
  888. X    if (!XPending(disp) && !frozen)
  889. X    moveOne(field, *thingp, NONE, fall_down);
  890. X
  891. X    while (XPending(disp)) {
  892. X    if (overlapping(field, *thingp))
  893. X        die(field);
  894. X
  895. X    XNextEvent(disp, &event);
  896. X    switch (event.type) {
  897. X    case KeyPress:
  898. X        n = XLookupString(&event, s, 4, NULL, NULL);
  899. X        if (!n)
  900. X        break;
  901. X        switch (*s) {
  902. X        case 'j':        /* Move left. */
  903. X        case 'J':
  904. X        case 's':
  905. X        case 'S':
  906. X        if (!frozen)
  907. X            moveOne(field, *thingp, LEFT,
  908. X                fall_down);
  909. X        break;
  910. X
  911. X        case 'k':        /* Rotate. */
  912. X        case 'K':
  913. X        case 'd':
  914. X        case 'D':
  915. X        if (!frozen)
  916. X            moveOne(field, *thingp, ROTATE,
  917. X                fall_down);
  918. X        break;
  919. X
  920. X        case 'l':        /* Move right. */
  921. X        case 'L':
  922. X        case 'f':
  923. X        case 'F':
  924. X        if (!frozen)
  925. X            moveOne(field, *thingp, RIGHT,
  926. X                fall_down);
  927. X        break;
  928. X
  929. X        case ' ':        /* Drop. */
  930. X        case '\n':
  931. X        if (!frozen) {
  932. X            moveOne(field, *thingp, DROP, fall_down);
  933. X            fallDown(field, thingp, True);
  934. X        }
  935. X        return;
  936. X        break;
  937. X
  938. X        case 'q':        /* Quit. */
  939. X        case 'Q':
  940. X        die(field);
  941. X        break;
  942. X
  943. X        case '+':        /* Speed up. */
  944. X        case '=':
  945. X        if (field->level < NUM_LEVELS - 1) {
  946. X            field->level++;
  947. X            updateScore(field);
  948. X        }
  949. X        break;
  950. X
  951. X        case '-':        /* Slow down. */
  952. X        case '_':
  953. X        if (field->level > 0) {
  954. X            field->level--;
  955. X            updateScore(field);
  956. X        }
  957. X        break;
  958. X
  959. X        case '\023':    /* Freeze / continue. */
  960. X        case 'p':
  961. X        case 'P':
  962. X        frozen = (frozen ? False : True);
  963. X        /* flow to next */
  964. X
  965. X        case '\014':        /* Redraw. */
  966. X        /* "... Hi Boss, I'm working hard as usual ..." */
  967. X        XClearWindow(disp, field->win);
  968. X        drawField(field);
  969. X        if (*thingp)
  970. X            drawThing(field, *thingp);
  971. X        if (frozen) {
  972. X            banner(field, PAUSED_MESG);
  973. X            XIconifyWindow(disp, field->frame, DefaultScreen(disp));
  974. X        }
  975. X        /* flow to next */
  976. X
  977. X        default:
  978. X        XBell(disp, -25);
  979. X        XFlush(disp);
  980. X        break;
  981. X        }
  982. X        break;        /* processing key press */
  983. X
  984. X    case UnmapNotify:
  985. X        frozen = True;
  986. X        break;
  987. X
  988. X    case Expose:
  989. X        drawField(field);
  990. X        if (*thingp)
  991. X        drawThing(field, *thingp);
  992. X        if (frozen) {
  993. X        banner(field, PAUSED_MESG);
  994. X        }
  995. X        XFlush(disp);
  996. X        break;
  997. X
  998. X    }
  999. X
  1000. X    fall_down = False;
  1001. X    }
  1002. X
  1003. X    return;
  1004. X}
  1005. X
  1006. Xvoid
  1007. XmoveOne(field, thing, what, fall_down)
  1008. X    field_t        *field;
  1009. X    thing_t        *thing;
  1010. X    command_t       what;
  1011. X    Bool            fall_down;
  1012. X{
  1013. X    thing_t         old;
  1014. X
  1015. X    old = *thing;
  1016. X
  1017. X    if (tryMove(field, thing, what, fall_down))
  1018. X    drawThingDiff(field, thing, &old);
  1019. X
  1020. X    XSync(disp, 0);
  1021. X    return;
  1022. X}
  1023. X
  1024. XBool
  1025. XtryMove(field, thing, what, fall_down)
  1026. X    field_t        *field;
  1027. X    thing_t        *thing;
  1028. X    command_t       what;
  1029. X    Bool            fall_down;
  1030. X{
  1031. X    int             x, y;
  1032. X    thing_t         temp;
  1033. X    Bool            ok = True;
  1034. X
  1035. X    temp = *thing;
  1036. X
  1037. X    if (fall_down)
  1038. X    temp.ypos--;
  1039. X    switch (what) {
  1040. X    case LEFT:
  1041. X    temp.xpos--;
  1042. X    break;
  1043. X
  1044. X    case RIGHT:
  1045. X    temp.xpos++;
  1046. X    break;
  1047. X
  1048. X    case ROTATE:
  1049. X    rotateThing(&temp);
  1050. X    break;
  1051. X
  1052. X    case DROP:
  1053. X    while (!overlapping(field, &temp)) {
  1054. X        field->score += field->level;
  1055. X        temp.ypos--;
  1056. X    }
  1057. X    temp.ypos++;
  1058. X    break;
  1059. X
  1060. X    case NONE:
  1061. X    break;
  1062. X    }
  1063. X
  1064. X    for (x = 0; x < temp.size; x++)
  1065. X    for (y = 0; y < temp.size; y++) {
  1066. X        if (temp.map[x][y]) {
  1067. X        if ((temp.xpos + x < 0) ||
  1068. X            (temp.xpos + x >= field->width) ||
  1069. X            (temp.ypos + y < 0) ||
  1070. X            (temp.ypos + y >= field->height) ||
  1071. X            (field->full[temp.xpos + x]
  1072. X             [temp.ypos + y]))
  1073. X            ok = False;
  1074. X        }
  1075. X    }
  1076. X
  1077. X    if (ok)
  1078. X    *thing = temp;
  1079. X
  1080. X    if (overlapping(field, thing)) {
  1081. X    return (False);
  1082. X    } else {
  1083. X    return (True);
  1084. X    }
  1085. X}
  1086. X
  1087. XBool
  1088. XatBottom(field, thing)
  1089. X    field_t        *field;
  1090. X    thing_t        *thing;
  1091. X{
  1092. X    int             x, y;
  1093. X
  1094. X    for (x = 0; x < thing->size; x++)
  1095. X    for (y = 0; y < thing->size; y++)
  1096. X        if (thing->map[x][y]) {
  1097. X        if (thing->ypos + y <= 0)
  1098. X            return (True);
  1099. X        if (field->full[thing->xpos + x]
  1100. X            [thing->ypos + y - 1])
  1101. X            return (True);
  1102. X        }
  1103. X    return (False);
  1104. X}
  1105. X
  1106. Xvoid
  1107. XdrawThing(field, thing)
  1108. X    field_t        *field;
  1109. X    thing_t        *thing;
  1110. X{
  1111. X    int             x, y;
  1112. X
  1113. X    for (x = 0; x < thing->size; x++)
  1114. X    for (y = 0; y < thing->size; y++)
  1115. X        if (thing->map[x][y])
  1116. X        doBox(field, thing->xpos + x, thing->ypos + y,
  1117. X              thing->map[x][y]);
  1118. X    return;
  1119. X}
  1120. X
  1121. Xvoid
  1122. XdrawThingDiff(field, thing, oldthing)
  1123. X    field_t        *field;
  1124. X    thing_t        *thing, *oldthing;
  1125. X{
  1126. X    int             x, y;
  1127. X    int             ox, oy;
  1128. X
  1129. X    for (x = 0; x < thing->size; x++)
  1130. X    for (y = 0; y < thing->size; y++) {
  1131. X        ox = x - oldthing->xpos + thing->xpos;
  1132. X        oy = y - oldthing->ypos + thing->ypos;
  1133. X        if (thing->map[x][y])
  1134. X        doBox(field, thing->xpos + x, thing->ypos + y,
  1135. X              thing->map[x][y]);
  1136. X    }
  1137. X    for (x = 0; x < thing->size; x++)
  1138. X    for (y = 0; y < thing->size; y++) {
  1139. X        ox = x - thing->xpos + oldthing->xpos;
  1140. X        oy = y - thing->ypos + oldthing->ypos;
  1141. X        if (oldthing->map[x][y] &&
  1142. X            ((ox < 0) || (ox >= thing->size) ||
  1143. X             (oy < 0) || (oy >= thing->size) ||
  1144. X             !thing->map[ox][oy]))
  1145. X        doBox(field, oldthing->xpos + x,
  1146. X              oldthing->ypos + y,
  1147. X              0);
  1148. X    }
  1149. X    return;
  1150. X}
  1151. X
  1152. Xvoid
  1153. XdoBox(field, x, y, pat)
  1154. X    field_t        *field;
  1155. X    int             x, y;
  1156. X    int             pat;
  1157. X{
  1158. X    if ((x < 0) || (x >= field->width) || (y < 0) || (y >= field->height))
  1159. X    abort();
  1160. X    if (pat == 0)
  1161. X    XFillRectangle(disp, field->win, gc_w2,
  1162. X               x * BOX_WIDTH + X_MARGIN,
  1163. X               ytr((y + 1) * BOX_HEIGHT + Y_MARGIN) - 1,
  1164. X               BOX_WIDTH + 1, BOX_HEIGHT + 1);
  1165. X    else {
  1166. X    if (XDisplayPlanes(disp, DefaultScreen(disp)) == 1) {
  1167. X        pat = pat % 16 - 1;
  1168. X        XCopyPlane(disp, patterns[pat].pixmap, field->win, gc_w,
  1169. X               0, 0,
  1170. X               BOX_WIDTH, BOX_HEIGHT,
  1171. X               x * BOX_WIDTH + X_MARGIN,
  1172. X               ytr((y + 1) * BOX_HEIGHT + Y_MARGIN), 1);
  1173. X    } else {
  1174. X        pat -= 1;
  1175. X        XCopyPlane(disp, patterns[pat].pixmap, field->win,
  1176. X               gc_pat[pat],
  1177. X               0, 0,
  1178. X               BOX_WIDTH, BOX_HEIGHT,
  1179. X               x * BOX_WIDTH + X_MARGIN,
  1180. X               ytr((y + 1) * BOX_HEIGHT + Y_MARGIN), 1);
  1181. X    }
  1182. X    }
  1183. X    return;
  1184. X}
  1185. X
  1186. XBool
  1187. Xoverlapping(field, thing)
  1188. X    field_t        *field;
  1189. X    thing_t        *thing;
  1190. X{
  1191. X    int             x, y;
  1192. X
  1193. X    for (x = 0; x < thing->size; x++)
  1194. X    for (y = 0; y < thing->size; y++) {
  1195. X        if (thing->map[x][y] && (thing->ypos + y < 0))
  1196. X        return (True);
  1197. X        if (thing->map[x][y] && field->full[thing->xpos + x]
  1198. X            [thing->ypos + y])
  1199. X        return (True);
  1200. X    }
  1201. X    return (False);
  1202. X}
  1203. X
  1204. Xint
  1205. XputBoxes(field, thing)
  1206. X    field_t        *field;
  1207. X    thing_t        *thing;
  1208. X{
  1209. X    int             x, y;
  1210. X    int             highest = 0;
  1211. X
  1212. X    for (x = 0; x < thing->size; x++)
  1213. X    for (y = 0; y < thing->size; y++)
  1214. X        if (thing->map[x][y]) {
  1215. X        if ((thing->xpos + x < 0) ||
  1216. X            (thing->xpos + x >= field->width) ||
  1217. X            (thing->ypos + y < 0) ||
  1218. X            (thing->ypos + y >= field->height))
  1219. X            abort();
  1220. X        field->full[thing->xpos + x][thing->ypos + y]
  1221. X            = thing->map[x][y];
  1222. X        if (thing->ypos + y > highest)
  1223. X            highest = thing->ypos + y;
  1224. X        }
  1225. X    return (highest);
  1226. X}
  1227. X
  1228. Xfield_t        *
  1229. XinitField(width, height, lines_full)
  1230. X    int             width, height;
  1231. X    int             lines_full;
  1232. X{
  1233. X    Cursor          cursor;
  1234. X    XSizeHints      sh;
  1235. X    field_t        *field = (field_t *) malloc(sizeof(field_t));
  1236. X    int             x, y, w, h;;
  1237. X
  1238. X    w = width * BOX_WIDTH + 2 * X_MARGIN;
  1239. X    h = height * BOX_HEIGHT + 2 * Y_MARGIN + TITLE_HEIGHT;
  1240. X
  1241. X    field->width = width;
  1242. X    field->height = height;
  1243. X    field->score = 0;
  1244. X    field->level = 1;
  1245. X    field->lines = 0;
  1246. X
  1247. X    field->frame = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
  1248. X    BASE_XPOS, BASE_YPOS, w, h, BORDER_WIDTH, bdcolor.pixel, bgcolor.pixel);
  1249. X
  1250. X    cursor = XCreateFontCursor(disp, XC_exchange);
  1251. X    XDefineCursor(disp, field->frame, cursor);
  1252. X    XSetStandardProperties(disp, field->frame, "GENERIC TETRIS",
  1253. X    "GENERIC TETRIS", None, NULL, 0, NULL);
  1254. X
  1255. X    sh.flags = PSize | PMinSize | PMaxSize;
  1256. X    sh.width = (sh.min_width = (sh.max_width = w));
  1257. X    sh.height = (sh.min_height = (sh.max_height = h));
  1258. X    XSetWMNormalHints(disp, field->frame, &sh);
  1259. X
  1260. X    field->title = XCreateSimpleWindow(disp, field->frame,
  1261. X    -BORDER_WIDTH, -BORDER_WIDTH, w, TITLE_HEIGHT, BORDER_WIDTH,
  1262. X    bdcolor.pixel, bgcolor.pixel);
  1263. X
  1264. X    field->win = XCreateSimpleWindow(disp, field->frame,
  1265. X    -BORDER_WIDTH, TITLE_HEIGHT - BORDER_WIDTH, w, h - TITLE_HEIGHT,
  1266. X    BORDER_WIDTH, bdcolor.pixel, bgcolor.pixel);
  1267. X
  1268. X    if (XDisplayPlanes(disp, DefaultScreen(disp)) == 1)
  1269. X    num_patterns = NUM_BITMAPS;
  1270. X
  1271. X    field->full = (int **) malloc(sizeof(int *) * width);
  1272. X    for (x = 0; x < width; x++) {
  1273. X    field->full[x] = (int *) malloc(sizeof(int) * height);
  1274. X    for (y = 0; y < height; y++)
  1275. X        if ((y < lines_full) && nrandom(2))
  1276. X        field->full[x][y] = nrandom(num_patterns);
  1277. X        else
  1278. X        field->full[x][y] = 0;
  1279. X    }
  1280. X
  1281. X    /* loading fonts */
  1282. X    field->tfont = XLoadQueryFont(disp, TITLE_FONT);
  1283. X    field->sfont = XLoadQueryFont(disp, SCORE_FONT);
  1284. X    if (field->tfont == NULL) {
  1285. X    field->tfont = XLoadQueryFont(disp, "-*-fixed-*-r-*-*-24-*-*-*-*-*-*-*");
  1286. X    assert(field->tfont);
  1287. X    }
  1288. X    if (field->sfont == NULL) {
  1289. X    field->sfont = XLoadQueryFont(disp, "-*-fixed-*-r-*-*-12-*-*-*-*-*-*-*");
  1290. X    assert(field->sfont);
  1291. X    }
  1292. X
  1293. X    field->winheight = field->height * BOX_HEIGHT + 2 * Y_MARGIN;
  1294. X    field->winwidth = field->width * BOX_WIDTH + 2 * X_MARGIN;
  1295. X
  1296. X    XMapWindow(disp, field->title);
  1297. X    XMapWindow(disp, field->win);
  1298. X    XMapRaised(disp, field->frame);
  1299. X
  1300. X    gcv.function = GXcopy;
  1301. X    gcv.foreground = bdcolor.pixel;
  1302. X    gcv.background = bgcolor.pixel;
  1303. X
  1304. X    gc_t = XCreateGC(disp, field->title, (GCForeground | GCBackground |
  1305. X                      GCFunction), &gcv);
  1306. X    gc_w = XCreateGC(disp, field->win, (GCForeground | GCBackground |
  1307. X                    GCFunction), &gcv);
  1308. X
  1309. X    gcv.background = bdcolor.pixel;
  1310. X    gcv.foreground = bgcolor.pixel;
  1311. X
  1312. X    gc_w2 = XCreateGC(disp, field->win, (GCForeground | GCBackground |
  1313. X                     GCFunction), &gcv);
  1314. X
  1315. X    text.function = GXcopy;
  1316. X    text.font = field->tfont->fid;
  1317. X    text.foreground = bdcolor.pixel;
  1318. X    text.background = bgcolor.pixel;
  1319. X    gc_ttx = XCreateGC(disp, field->title, (GCFunction | GCFont |
  1320. X                       GCForeground | GCBackground), &text);
  1321. X    text.font = field->sfont->fid;
  1322. X    gc_wtx = XCreateGC(disp, field->title, (GCFunction | GCFont |
  1323. X                       GCForeground | GCBackground), &text);
  1324. X
  1325. X    XFlush(disp);
  1326. X    return (field);
  1327. X}
  1328. X
  1329. Xvoid
  1330. XdrawField(field)
  1331. X    field_t        *field;
  1332. X{
  1333. X    int             x, y;
  1334. X
  1335. X    for (x = 0; x < field->width; x++)
  1336. X    for (y = 0; y < field->height; y++)
  1337. X        doBox(field, x, y, field->full[x][y]);
  1338. X
  1339. X    XDrawImageString(disp, field->title, gc_ttx, 3, 30, "TETRIS", 6);
  1340. X
  1341. X    updateScore(field);
  1342. X
  1343. X    XFlush(disp);
  1344. X    return;
  1345. X}
  1346. X
  1347. Xvoid
  1348. XupdateScore(field)
  1349. X    field_t        *field;
  1350. X{
  1351. X    char            buf[100];
  1352. X
  1353. X    (void) sprintf(buf, "Score: %-7d", field->score);
  1354. X    XDrawImageString(disp, field->title, gc_wtx,
  1355. X             SCORE_XPOS1, SCORE_YPOS1, buf, strlen(buf));
  1356. X
  1357. X    (void) sprintf(buf, "Level: %-7d", field->level);
  1358. X    XDrawImageString(disp, field->title, gc_wtx,
  1359. X             SCORE_XPOS1, SCORE_YPOS2, buf, strlen(buf));
  1360. X
  1361. X    (void) sprintf(buf, "Lines: %-7d", field->lines);
  1362. X    XDrawImageString(disp, field->title, gc_wtx,
  1363. X             SCORE_XPOS2, SCORE_YPOS2, buf, strlen(buf));
  1364. X
  1365. X    XFlush(disp);
  1366. X    return;
  1367. X}
  1368. X
  1369. Xthing_t        *
  1370. XmakeNewThing(field)
  1371. X    field_t        *field;
  1372. X{
  1373. X    int             i, j, k;
  1374. X    int             pat;
  1375. X    int             whichone;
  1376. X    thing_t        *thing = (thing_t *) malloc(sizeof(thing_t));
  1377. X
  1378. X    i = 0;
  1379. X    for (j = 0; j < NUM_POSSIBLE; j++)
  1380. X    i += possible[j].probability;
  1381. X
  1382. X    k = nrandom(i);
  1383. X
  1384. X    for (j = 0; j < NUM_POSSIBLE; j++) {
  1385. X    k -= possible[j].probability;
  1386. X    if (k < 0)
  1387. X        break;
  1388. X    }
  1389. X
  1390. X    *thing = possible[j];
  1391. X    whichone = j;
  1392. X    for (i = 0; i < thing->size; i++)
  1393. X    for (j = 0; j < thing->size; j++)
  1394. X        if (thing->map[i][j]) {
  1395. X        pat = 1;
  1396. X        if (i != 0 && thing->map[i - 1][j])
  1397. X            pat += 1;
  1398. X        if (j != 0 && thing->map[i][j - 1])
  1399. X            pat += 2;
  1400. X        if (i < thing->size - 1 && thing->map[i + 1][j])
  1401. X            pat += 4;
  1402. X        if (j < thing->size - 1 && thing->map[i][j + 1])
  1403. X            pat += 8;
  1404. X        thing->map[i][j] = pat + whichone * 16;
  1405. X        }
  1406. X    for (i = nrandom(4); i > 0; i--)
  1407. X    rotateThing(thing);
  1408. X
  1409. X    thing->ypos = field->height - thing->size;
  1410. X    thing->xpos = nrandom((field->width - 2 * thing->size) + thing->size);
  1411. X
  1412. X    return (thing);
  1413. X}
  1414. X
  1415. Xvoid
  1416. XrotateThing(thing)
  1417. X    thing_t        *thing;
  1418. X{
  1419. X    thing_t         temp;
  1420. X    int             lpoint = thing->size;
  1421. X    int             nlpoint = thing->size;
  1422. X    int             x, y;
  1423. X    int             pattype;
  1424. X
  1425. X    temp = *thing;
  1426. X    for (x = 0; x < thing->size; x++)
  1427. X    for (y = 0; y < thing->size; y++)
  1428. X        if (thing->map[x][y] && (lpoint < y))
  1429. X        lpoint = y;
  1430. X
  1431. X    for (x = 0; x < thing->size; x++)
  1432. X    for (y = 0; y < thing->size; y++) {
  1433. X        pattype = (temp.map[y][thing->size - x - 1] - 1) / 16;
  1434. X        thing->map[x][y] =
  1435. X        ((((temp.map[y][thing->size - x - 1] & 15) - 1) * 2) % 15 + 1)
  1436. X        + pattype * 16;
  1437. X        if (thing->map[x][y] < 0)
  1438. X        thing->map[x][y] = 0;
  1439. X    }
  1440. X
  1441. X    for (x = 0; x < thing->size; x++)
  1442. X    for (y = 0; y < thing->size; y++)
  1443. X        if (thing->map[x][y] && (nlpoint < y))
  1444. X        nlpoint = y;
  1445. X
  1446. X    thing->ypos += lpoint - nlpoint;
  1447. X
  1448. X    return;
  1449. X}
  1450. X
  1451. Xint
  1452. XcheckLine(field)
  1453. X    field_t        *field;
  1454. X{
  1455. X    int            *set = (int *) malloc(sizeof(int) * field->height);
  1456. X    int             i, x, y, nset = 0, h;
  1457. X
  1458. X    for (y = 0; y < field->height; y++) {
  1459. X    for (x = 0; x < field->width; x++)
  1460. X        if (!field->full[x][y])
  1461. X        break;
  1462. X    if (x == field->width) {
  1463. X        set[y] = 1;
  1464. X        nset++;
  1465. X    } else
  1466. X        set[y] = 0;
  1467. X    }
  1468. X
  1469. X    if (nset) {
  1470. X    for (i = 0; i < NUM_FLASHES / nset; i++) {
  1471. X        for (y = 0; y < field->height; y++)
  1472. X        if (set[y]) {
  1473. X            XFillRectangle(disp, field->win, gc_w,
  1474. X                   X_MARGIN,
  1475. X                   ytr((y + 1) * BOX_HEIGHT +
  1476. X                       Y_MARGIN),
  1477. X                   field->width * BOX_WIDTH,
  1478. X                   BOX_HEIGHT);
  1479. X            XFlush(disp);
  1480. X        }
  1481. X    }
  1482. X    for (y = 0; y < field->height; y++)
  1483. X        if (set[y]) {
  1484. X        for (i = y; i < field->height - 1; i++)
  1485. X            for (x = 0; x < field->width; x++)
  1486. X            field->full[x][i] =
  1487. X                field->full[x][i + 1];
  1488. X        for (x = 0; x < field->width; x++)
  1489. X            field->full[x][field->height - 1] = 0;
  1490. X
  1491. X        h = (field->height - y - 1) * BOX_HEIGHT;
  1492. X        if (h > field->winheight - BOX_HEIGHT -
  1493. X            Y_MARGIN)
  1494. X            h = field->winheight - BOX_HEIGHT -
  1495. X            Y_MARGIN;
  1496. X        XCopyArea(disp, field->win, field->win, gc_w,
  1497. X              X_MARGIN, Y_MARGIN,
  1498. X              field->winwidth, h,
  1499. X              X_MARGIN, BOX_HEIGHT + Y_MARGIN);
  1500. X
  1501. X        for (i = y; i < field->height - 1; i++)
  1502. X            set[i] = set[i + 1];
  1503. X        set[field->height - 1] = 0;
  1504. X        y--;
  1505. X        }
  1506. X    XBell(disp, -60);
  1507. X    XSync(disp, 0);
  1508. X    }
  1509. X    free((char *) set);
  1510. X
  1511. X    return (nset);
  1512. X}
  1513. X
  1514. Xvoid
  1515. XinitPixmaps(field)
  1516. X    field_t        *field;
  1517. X{
  1518. X    Pixmap          bms[NUM_BITMAPS];
  1519. X    int             i, j;
  1520. X    char           *lastFg = "", *lastBg = "";
  1521. X    XColor          lastFgC, lastBgC;
  1522. X
  1523. X    for (i = 0; i < NUM_BITMAPS; i++) {
  1524. X    bms[i] = XCreateBitmapFromData(disp, field->win,
  1525. X                       bitmap_data[i].data,
  1526. X                       bitmap_data[i].width,
  1527. X                       bitmap_data[i].height);
  1528. X    assert(bms[i]);
  1529. X    }
  1530. X    if (XDisplayPlanes(disp, DefaultScreen(disp)) == 1) {
  1531. X    for (i = 0; i < NUM_BITMAPS; i++) {
  1532. X        patterns[i].pixmap = bms[i];
  1533. X    }
  1534. X    return;
  1535. X    }
  1536. X    for (i = 0; i < NUM_PATTERNS; i++) {
  1537. X    j = 0;
  1538. X    if (strcmp(patterns[i].fgname, lastFg) != 0) {
  1539. X        assert(XParseColor(disp, cmap,
  1540. X                   patterns[i].fgname, &patterns[i].fg));
  1541. X        assert(XAllocColor(disp, cmap, &patterns[i].fg));
  1542. X        lastFg = patterns[i].fgname;
  1543. X        lastFgC = patterns[i].fg;
  1544. X        j = 1;
  1545. X    } else {
  1546. X        patterns[i].fg = lastFgC;
  1547. X    }
  1548. X    if (strcmp(patterns[i].bgname, lastBg) != 0) {
  1549. X        assert(XParseColor(disp, cmap,
  1550. X                   patterns[i].bgname, &patterns[i].bg));
  1551. X        assert(XAllocColor(disp, cmap, &patterns[i].bg));
  1552. X        lastBg = patterns[i].bgname;
  1553. X        lastBgC = patterns[i].bg;
  1554. X        j = 1;
  1555. X    } else {
  1556. X        patterns[i].bg = lastBgC;
  1557. X    }
  1558. X
  1559. X    if (j) {
  1560. X        color.function = GXcopy;
  1561. X        color.foreground = patterns[i].fg.pixel;
  1562. X        color.background = patterns[i].bg.pixel;
  1563. X
  1564. X        gc_pat[i] = XCreateGC(disp, field->win, (GCForeground |
  1565. X                    GCBackground | GCFunction), &color);
  1566. X    } else
  1567. X        gc_pat[i] = gc_pat[i - 1];
  1568. X
  1569. X    patterns[i].pixmap = bms[patterns[i].whichbitmap];
  1570. X    assert(patterns[i].pixmap);
  1571. X    }
  1572. X    return;
  1573. X}
  1574. X
  1575. Xint
  1576. Xnrandom(n)
  1577. X    int             n;
  1578. X{
  1579. X    return ((((double) random()) / ((double) 0x7fffffff)) * n);
  1580. X}
  1581. X
  1582. Xvoid
  1583. XUsage(argv)
  1584. X    char          **argv;
  1585. X{
  1586. X    fprintf(stderr, "Usage:\t%s [ starting_level [ raws_pre-filled ] ]\n\n",
  1587. X    argv[0]);
  1588. X    showHighScores(SHOWNSCORES/2);
  1589. X    exit(255);
  1590. X}
  1591. X
  1592. END_OF_FILE
  1593. if test 23128 -ne `wc -c <'tetris.c'`; then
  1594.     echo shar: \"'tetris.c'\" unpacked with wrong size!
  1595. fi
  1596. # end of 'tetris.c'
  1597. fi
  1598. if test -f 'tetris.h' -a "${1}" != "-c" ; then 
  1599.   echo shar: Will not clobber existing file \"'tetris.h'\"
  1600. else
  1601. echo shar: Extracting \"'tetris.h'\" \(4639 characters\)
  1602. sed "s/^X//" >'tetris.h' <<'END_OF_FILE'
  1603. X/*
  1604. X# GENERIC X-WINDOW-BASED TETRIS
  1605. X#
  1606. X#    tetris.h
  1607. X#
  1608. X###
  1609. X#
  1610. X#  Copyright (C) 1992    Qiang Alex Zhao
  1611. X#            Computer Science Dept, University of Arizona
  1612. X#            azhao@cs.arizona.edu
  1613. X#
  1614. X#            All Rights Reserved
  1615. X#
  1616. X#  Permission to use, copy, modify, and distribute this software and
  1617. X#  its documentation for any purpose and without fee is hereby granted,
  1618. X#  provided that the above copyright notice appear in all copies and
  1619. X#  that both that copyright notice and this permission notice appear in
  1620. X#  supporting documentation, and that the name of the author not be
  1621. X#  used in advertising or publicity pertaining to distribution of the
  1622. X#  software without specific, written prior permission.
  1623. X#
  1624. X#  This program is distributed in the hope that it will be "playable",
  1625. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  1626. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1627. X#
  1628. X*/
  1629. X
  1630. X/*
  1631. X * Common defs
  1632. X */
  1633. X
  1634. X#include    <stdio.h>
  1635. X#include    <sys/types.h>
  1636. X#include    <sys/errno.h>
  1637. X#include    <sys/file.h>
  1638. X#include    <string.h>
  1639. X#include    <pwd.h>
  1640. X
  1641. X#ifdef    HPUX
  1642. X#include    <time.h>
  1643. X#define    random()    lrand48()
  1644. X#define    srandom(x)    srand48(x)
  1645. X#else
  1646. X#include    <sys/time.h>
  1647. X#endif
  1648. X
  1649. X#include    <X11/Xlib.h>
  1650. X#include    <X11/Xutil.h>
  1651. X#include    <X11/cursorfont.h>
  1652. X#include    <X11/keysym.h>
  1653. X
  1654. X#define    assert(E)    if (E); else fprintf(stderr,"Assertion failed, line %d, fill %s\n", __LINE__, __FILE__),exit(0)
  1655. X
  1656. X/*
  1657. X * Tetris defs
  1658. X */
  1659. X
  1660. X/* score file */
  1661. X#ifndef    SCOREFILE
  1662. X#define SCOREFILE    "/usr/games/.tetris.scores"
  1663. X#endif
  1664. X
  1665. X/* Maximum # of scores allowed per person */
  1666. X#ifndef    MAXSCORES
  1667. X#define MAXSCORES 3
  1668. X#endif
  1669. X
  1670. X/* number of scores shown */
  1671. X#ifndef    SHOWNSCORES
  1672. X#define    SHOWNSCORES    15
  1673. X#endif
  1674. X
  1675. X/* fonts */
  1676. X#define TITLE_FONT      "-*-new century schoolbook-bold-r-*-*-24-*-*-*-*-*-*-*"
  1677. X#define SCORE_FONT      "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*"
  1678. X
  1679. X/****************************/
  1680. X
  1681. X#define    NAMELEN        12
  1682. X
  1683. X#define NUM_BITMAPS    (sizeof (bitmap_data) / sizeof (bitmap_data[0]))
  1684. X
  1685. X#define eq(a, b)    (!strcmp((a), (b)))
  1686. X
  1687. X#define DEF_WIDTH    10
  1688. X#define DEF_HEIGHT    20
  1689. X
  1690. X#define BOX_HEIGHT    30
  1691. X#define BOX_WIDTH    30
  1692. X
  1693. X#define BOX_SPACE    1
  1694. X
  1695. X#define X_MARGIN    1
  1696. X#define Y_MARGIN    1
  1697. X
  1698. X#define THING_SIZE    4
  1699. X
  1700. X#define BASE_XPOS    100
  1701. X#define BASE_YPOS    100
  1702. X
  1703. X#define BORDER_WIDTH    3
  1704. X
  1705. X#define TITLE_HEIGHT    40
  1706. X
  1707. X#define NUM_FLASHES    15
  1708. X
  1709. X#define SCORE_XPOS1    130
  1710. X#define SCORE_XPOS2    230
  1711. X#define SCORE_YPOS1    18
  1712. X#define SCORE_YPOS2    32
  1713. X
  1714. X#define BG_COLOR    "lightyellow"
  1715. X#define BD_COLOR    "darkgreen"
  1716. X#define TITLE_COLOR    "blue"
  1717. X#define TEXT_COLOR    "red"
  1718. X
  1719. Xtypedef struct score_s {
  1720. X    char            myname[NAMELEN], myhost[NAMELEN], mytime[27];
  1721. X    char            score[10];
  1722. X    char            level[4];
  1723. X    char            lines[5];
  1724. X}               score_t;
  1725. X#define SCORELEN    sizeof(score_t)
  1726. X
  1727. Xtypedef struct pattern_s {
  1728. X    int             whichbitmap;
  1729. X    char           *fgname, *bgname;
  1730. X    XColor          fg, bg;
  1731. X    Pixmap          pixmap;
  1732. X}               pattern_t;
  1733. X
  1734. Xtypedef enum {
  1735. X    NONE, LEFT, RIGHT, ROTATE, DROP
  1736. X}               command_t;
  1737. X
  1738. Xtypedef struct field_s {
  1739. X    Window          frame;
  1740. X    Window          title;
  1741. X    Window          win;
  1742. X    XFontStruct    *tfont;
  1743. X    XFontStruct    *sfont;
  1744. X    int           **full;
  1745. X    int             height, width;
  1746. X    int             winheight, winwidth;
  1747. X    long            score;
  1748. X    int             level;
  1749. X    int             lines;
  1750. X}               field_t;
  1751. X
  1752. Xtypedef struct thing_s {
  1753. X    int             map[THING_SIZE][THING_SIZE];
  1754. X    int             xpos, ypos;
  1755. X    int             size;
  1756. X    int             probability;
  1757. X}               thing_t;
  1758. X
  1759. X#define    DIE_MESG    "GAME OVER"
  1760. X#define    PAUSED_MESG    "PAUSED"
  1761. X
  1762. X#define ytr(y)        (field->winheight - (y))
  1763. X
  1764. X#define NUM_LEVELS    12
  1765. X
  1766. X#define INF        10000000
  1767. X
  1768. X#define MILLION        1000000
  1769. X
  1770. Xextern XColor   bgcolor, bdcolor, titlecolor, textcolor;
  1771. X
  1772. Xextern Bool     atBottom();
  1773. Xextern Bool     overlapping();
  1774. Xextern Bool     tryMove();
  1775. Xextern field_t *initField();
  1776. Xextern int      checkLine();
  1777. Xextern int      putBoxes();
  1778. Xextern long     time();
  1779. Xextern thing_t *makeNewThing();
  1780. Xextern void    Usage();
  1781. Xextern void     addHighScore();
  1782. Xextern void     banner();
  1783. Xextern void     die();
  1784. Xextern void     doBox();
  1785. Xextern void     drawField();
  1786. Xextern void     drawThing();
  1787. Xextern void     drawThingDiff();
  1788. Xextern void     fallDown();
  1789. Xextern void     handleEvents();
  1790. Xextern void     initPixmaps();
  1791. Xextern void     moveOne();
  1792. Xextern void     normTimeVal();
  1793. Xextern void     rotateThing();
  1794. Xextern void     showHighScores();
  1795. Xextern void     updateScore();
  1796. X
  1797. Xextern Display *disp;
  1798. Xextern Window   win;
  1799. Xextern XGCValues gcv;
  1800. Xextern XGCValues text;
  1801. Xextern GC       gc_w;
  1802. Xextern GC       gc_w2;
  1803. Xextern GC       gc_t;
  1804. Xextern GC       gc_wtx;
  1805. Xextern GC       gc_ttx;
  1806. X
  1807. END_OF_FILE
  1808. if test 4639 -ne `wc -c <'tetris.h'`; then
  1809.     echo shar: \"'tetris.h'\" unpacked with wrong size!
  1810. fi
  1811. # end of 'tetris.h'
  1812. fi
  1813. echo shar: End of archive 1 \(of 2\).
  1814. cp /dev/null ark1isdone
  1815. MISSING=""
  1816. for I in 1 2 ; do
  1817.     if test ! -f ark${I}isdone ; then
  1818.     MISSING="${MISSING} ${I}"
  1819.     fi
  1820. done
  1821. if test "${MISSING}" = "" ; then
  1822.     echo You have unpacked both archives.
  1823.     rm -f ark[1-9]isdone
  1824. else
  1825.     echo You still need to unpack the following archives:
  1826.     echo "        " ${MISSING}
  1827. fi
  1828. ##  End of shell archive.
  1829. exit 0
  1830.