home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xtetris / part01 next >
Encoding:
Internet Message Format  |  1989-06-15  |  24.7 KB

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i027: xtetris - X version of tetris, Part01/03
  5. Message-ID: <823@island.uu.net>
  6. Date: 14 Jun 89 12:14:54 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 684
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: Didier Tallot <Tallot@bdblues.altair.fr>
  12. Posting-number: Volume 4, Issue 27
  13. Archive-name: xtetris/part01
  14.  
  15. [ This version of the game of tetris requires the HP widgets -- which I
  16.   don't have.  So, I couldn't test it.  There is no Imakefile, but the
  17.   makefile is rather simple. --argv ]
  18.  
  19. #!/bin/sh
  20. # shar:    Shell Archiver  (v1.22)
  21. #
  22. # This is part 1 of a multipart archive                                    
  23. # do not concatenate these parts, unpack them in order with /bin/sh        
  24. #
  25. #    Run the following text with /bin/sh to create:
  26. #      COPYRIGHT
  27. #      MANIFEST
  28. #      Makefile
  29. #      README
  30. #      defs.h
  31. #      draw.c
  32. #      event.c
  33. #      init.c
  34. #      main.c
  35. #      notify.c
  36. #      score.c
  37. #      shape.c
  38. #      support.c
  39. #      tetris.xicon
  40. #      window.c
  41. #      xtetris.6
  42. #
  43. if test -r s2_seq_.tmp
  44. then echo "Must unpack archives in sequence!"
  45.      next=`cat s2_seq_.tmp`; echo "Please unpack part $next next"
  46.      exit 1; fi
  47. echo "x - extracting COPYRIGHT (Text)"
  48. sed 's/^X//' << 'SHAR_EOF' > COPYRIGHT &&
  49. XCopyright 1989 Phill Everson & Martyn Shortley
  50. X
  51. XThis notice and any statement of authorship must be reproduced
  52. Xon all copies.  The authors do not make any warranty expressed
  53. Xor implied, or assume any liability or responsiblity for the
  54. Xuse of this software.
  55. X
  56. XAny distributor of copies of this software shall grant the
  57. Xrecipient permission for further redistribution as permitted
  58. Xby this notice.  Any distributor must distribute this software
  59. Xwithout any fee or other monetary gains, unless expressed written
  60. Xpermission is granted by the authors.
  61. X
  62. XThis software or its use shall not be: sold, rented, leased,
  63. Xtraded, or otherwise marketed without the expressed written
  64. Xpermission of the authors.
  65. X
  66. XIf the software is modified in a manner creating derivative
  67. Xcopyrights, appropriate legends may be placed on derivative
  68. Xwork in addition to that set forth above.
  69. X
  70. XPermission is hereby granted to copy, reproduce, redistribute or
  71. Xotherwise use this software as long as the conditions above
  72. Xare met.
  73. X
  74. XAll rights not granted by this notice are reserved.
  75. X
  76. XAuthors: Phill Everson <everson@cs.bris.ac.uk>
  77. X         Martyn Shortley <shortley@cs.bris.ac.uk>
  78. X
  79. XModifications for X : Didier Tallot <tallot@bdblues.altair.fr>
  80. X                      Copyright 1989 Didier Tallot 
  81. SHAR_EOF
  82. chmod 0644 COPYRIGHT || echo "restore of COPYRIGHT fails"
  83. echo "x - extracting MANIFEST (Text)"
  84. sed 's/^X//' << 'SHAR_EOF' > MANIFEST &&
  85. X   File Name        Archive #    Description
  86. X-----------------------------------------------------------
  87. X COPYRIGHT                  1    
  88. X MANIFEST                   1    This shipping list
  89. X Makefile                   1    
  90. X README                     1    
  91. X defs.h                     1    
  92. X draw.c                     1    
  93. X event.c                    1    
  94. X init.c                     1    
  95. X main.c                     1    
  96. X notify.c                   1    
  97. X score.c                    1    
  98. X shape.c                    1    
  99. X support.c                  1    
  100. X tetris.6                   1    
  101. X tetris.icon                1    
  102. X window.c                   1    
  103. SHAR_EOF
  104. chmod 0644 MANIFEST || echo "restore of MANIFEST fails"
  105. echo "x - extracting Makefile (Text)"
  106. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  107. XBINDIR=/usr/games/
  108. XCC=cc
  109. XCFLAGS=-O
  110. X
  111. XINCLUDES = -I.
  112. X
  113. XLIBS = -lXw -lXt -lX11
  114. X
  115. XPROG=xtetris
  116. XCFILES=main.c event.c init.c shape.c support.c notify.c window.c \
  117. X        score.c draw.c
  118. XOFILES=main.o event.o init.o shape.o support.o notify.o window.o \
  119. X        score.o draw.o
  120. X
  121. X.c.o:
  122. X    $(CC) -c $(CFLAGS) $(INCLUDES) $*.c
  123. X
  124. X$(PROG):    $(OFILES)
  125. X    $(CC) $(CFLAGS) -o $(PROG) $(OFILES) $(LIBS)
  126. X
  127. X$(OFILES): defs.h
  128. X
  129. X# tetris needs to be setuid so that the high scores file can be updated.
  130. X# if you don't like setuid programs on your system then just make sure
  131. X# that the high score file is globally read/writable.
  132. Xinstall: $(PROG)
  133. X    install -s $(PROG) $(BINDIR)
  134. X    chmod u+s $(BINDIR)/$(PROG)
  135. X
  136. Xclean:
  137. X    rm *.o core 
  138. SHAR_EOF
  139. chmod 0644 Makefile || echo "restore of Makefile fails"
  140. echo "x - extracting README (Text)"
  141. sed 's/^X//' << 'SHAR_EOF' > README &&
  142. XX Based Tetris
  143. X
  144. XThis version of xtetris is based on the version posted to
  145. Xcomp.sources.games byll Everson & Martyn Shortley  in early
  146. XMarch, 1989. 
  147. X
  148. XThis was developed under SunOS4.0 running on a Sun3.
  149. X
  150. XTo install:
  151. X
  152. X    Set HIGH_SCORE_TABLE in defs.h to the pathname of your high
  153. X    scores table.  (If you do not want tetris to be installed setuid
  154. X    (the default) this file will have to be globally
  155. X    read/writable). The high score file will be created the first
  156. X    time tetris is executed.
  157. X
  158. X    Set BINDIR in Makefile to be the desired location of the
  159. X    compiled binary.
  160. X
  161. X    type "make install"
  162. X
  163. XDidier Tallot <tallot@bdblues.altair.fr>
  164. XGIP Altair, INRIA, Rocquencourt, France
  165. X
  166. X29 May, 1989
  167. SHAR_EOF
  168. chmod 0644 README || echo "restore of README fails"
  169. echo "x - extracting defs.h (Text)"
  170. sed 's/^X//' << 'SHAR_EOF' > defs.h &&
  171. X#include <stdio.h>
  172. X
  173. X#include <X11/Xlib.h>
  174. X#include <X11/Intrinsic.h>
  175. X#include <X11/StringDefs.h>
  176. X#include <X11/Shell.h>
  177. X
  178. X#include <Xw/Xw.h>
  179. X
  180. X#define UWIDTH          10      /* canvas size in units */
  181. X#define UHEIGHT         30
  182. X
  183. X#define UNIT            19      /* pixels in a unit */
  184. X#define SHADOW_OFFSET   UNIT
  185. X#define SHADOW_HEIGHT   (UNIT+SHADOW_OFFSET)    /* shadow area height in
  186. X                                                 * pixels */
  187. X#define NEXT_HEIGHT        (UNIT*5)    /* Height for next block */
  188. X
  189. X#define HIGH_TABLE_SIZE 10      /* size of high score table */
  190. X#ifndef HIGH_SCORE_TABLE
  191. X#define HIGH_SCORE_TABLE    "/usr/games/lib/tetris_scores"
  192. X#endif
  193. X
  194. X#define       NO_COLS 16
  195. X
  196. X#define       WHITE   0
  197. X#define       RED     1
  198. X#define       ORANGE  2
  199. X#define       YELLOW  3
  200. X#define       GREEN   4
  201. X#define       BLUE    5
  202. X#define       CYAN    6
  203. X#define       VIOLET  7
  204. X#define       BLACK   8
  205. X
  206. Xstatic Arg args[20];
  207. X
  208. XWidget     toplevel;
  209. XWidget   frame, score_frame;
  210. XWidget   panel, score_panel;
  211. XWidget     sub1_panel, sub2_panel;
  212. XWidget   canvas;
  213. XWidget   high_score_item[HIGH_TABLE_SIZE+1], score_item, level_item, rows_item, game_over;
  214. XWidget   tbar, start_bt, pause_bt, newgame_bt, scores_bt, quit_bt, done_bt;
  215. XGC       gc;
  216. XPixmap     tetris_icon;
  217. X
  218. Xint    end_of_game, score_position;
  219. Xint     shape_no, xpos, ypos, rot, score, rows;
  220. Xint    next_no, next_rot;
  221. Xchar   *name;
  222. Xunsigned char grid[UWIDTH][UHEIGHT];
  223. X
  224. Xstruct score_table {
  225. X        char    name[BUFSIZ];
  226. X        int     score;
  227. X        int     rows;
  228. X        int     level;
  229. X        char hostname[BUFSIZ];
  230. X        char    date[BUFSIZ];
  231. X}       high_scores[HIGH_TABLE_SIZE];
  232. X
  233. Xstruct shape_table {
  234. X        int     table[4][4];
  235. X        int     width;
  236. X        int     height;
  237. X        int     offset;
  238. X        int     pointv[4];
  239. X        char    color;
  240. X}       shape[7];
  241. X
  242. Xstruct shape {
  243. X        int     shape;
  244. X        int     rot;
  245. X        int     width;
  246. X        int     height;
  247. X        int     offset;
  248. X        int     pointv;
  249. X        char    color;
  250. X        int     was_shown;
  251. X        int     was_shadowed;
  252. X}      *current, *next;
  253. X
  254. Xvoid    print_high_scores(), done_proc(), quit_proc(), start_proc(), pause_proc(), restart_proc();
  255. Xvoid    canvas_event_proc();
  256. Xvoid     drop_block();
  257. Xvoid    restore_canvas();
  258. SHAR_EOF
  259. chmod 0644 defs.h || echo "restore of defs.h fails"
  260. echo "x - extracting draw.c (Text)"
  261. sed 's/^X//' << 'SHAR_EOF' > draw.c &&
  262. X#include "defs.h"
  263. X
  264. Xdraw_shadow(shape_no, xpos, ypos, rot, col)
  265. X        int     shape_no, xpos, ypos, rot, col;
  266. X{
  267. X        int     y1;
  268. X        int     x1, x2, x3, x4;
  269. X        int     t0, t1, t2, t3;
  270. X        int     xsize;
  271. X
  272. X        t0 = shape[shape_no].table[0][rot];     /* Bit map of 1st Row */
  273. X        t1 = shape[shape_no].table[1][rot];     /* Bit map of 2nd Row */
  274. X        t2 = shape[shape_no].table[2][rot];     /* Bit map of 3rd Row */
  275. X        t3 = shape[shape_no].table[3][rot];     /* Bit map of 4th Row */
  276. X
  277. X        x1 = xpos * UNIT;       /* Position of 1st column of block grid */
  278. X        x2 = x1 + UNIT;         /* Position of 2nd column of block grid */
  279. X        x3 = x2 + UNIT;         /* Position of 3rd column of block grid */
  280. X        x4 = x3 + UNIT;         /* Position of 4th column of block grid */
  281. X
  282. X        y1 = UHEIGHT * UNIT + SHADOW_OFFSET / 2;
  283. X        xsize = UWIDTH * UNIT;
  284. X
  285. X    XSetFunction(XtDisplay(toplevel), gc, GXclear);
  286. X    XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  287. X                       0, y1, xsize, UNIT);
  288. X        XFlush(XtDisplay(toplevel));
  289. X    if (col == WHITE) XSetFunction(XtDisplay(toplevel), gc, GXclear);
  290. X    else XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  291. X        if (t0 & 8 || t1 & 8 || t2 & 8 || t3 & 8)
  292. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  293. X                               x1, y1, UNIT, UNIT);
  294. X        if (t0 & 4 || t1 & 4 || t2 & 4 || t3 & 4)
  295. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  296. X                               x2, y1, UNIT, UNIT);
  297. X        if (t0 & 2 || t1 & 2 || t2 & 2 || t3 & 2)
  298. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  299. X                               x3, y1, UNIT, UNIT);
  300. X        if (t0 & 1 || t1 & 1 || t2 & 1 || t3 & 1)
  301. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  302. X                               x4, y1, UNIT, UNIT);
  303. X        XFlush(XtDisplay(toplevel));
  304. X}
  305. X
  306. Xshow_next()
  307. X{
  308. X        int     y, y1, xsize;
  309. X
  310. X        y = UHEIGHT * UNIT + SHADOW_HEIGHT;
  311. X        xsize = UNIT * UWIDTH;
  312. X
  313. X    XSetFunction(XtDisplay(toplevel), gc, GXclear);
  314. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  315. X                       0, y + UNIT, xsize, NEXT_HEIGHT - UNIT);
  316. X
  317. X    XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  318. X        XDrawString(XtDisplay(toplevel), XtWindow(canvas), gc,
  319. X                       5, y + UNIT, "Next block", 10);
  320. X
  321. X        y1 = y / UNIT + 1;
  322. X        print_shape(next_no, 5, y1, next_rot, shape[next_no].color);
  323. X        XFlush(XtDisplay(toplevel));
  324. X}
  325. X
  326. Xprint_shape(shape_no, x, y, rot, col)
  327. X        int     shape_no, x, y, rot, col;
  328. X{
  329. X        int     x1, x2, x3, x4, y1;
  330. X        int     t0, t1, t2, t3;
  331. X
  332. X        t0 = shape[shape_no].table[0][rot];     /* Bit map of 1st Row */
  333. X        t1 = shape[shape_no].table[1][rot];     /* Bit map of 2nd Row */
  334. X        t2 = shape[shape_no].table[2][rot];     /* Bit map of 3rd Row */
  335. X        t3 = shape[shape_no].table[3][rot];     /* Bit map of 4th Row */
  336. X
  337. X        x1 = x * UNIT;          /* Position of 1st column of block grid */
  338. X        x2 = x1 + UNIT;         /* Position of 2nd column of block grid */
  339. X        x3 = x2 + UNIT;         /* Position of 3rd column of block grid */
  340. X        x4 = x3 + UNIT;         /* Position of 4th column of block grid */
  341. X        y1 = y * UNIT;          /* Position of 1st row of block grid    */
  342. X
  343. X    if (col == WHITE) XSetFunction(XtDisplay(toplevel), gc, GXclear);
  344. X    else XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  345. X        if (y > -1) {
  346. X                if (t0 & 8)
  347. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  348. X                                     x1, y1, UNIT, UNIT);
  349. X                if (t0 & 4)
  350. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  351. X                                     x2, y1, UNIT, UNIT);
  352. X                if (t0 & 2)
  353. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  354. X                                     x3, y1, UNIT, UNIT);
  355. X                if (t0 & 1)
  356. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  357. X                                     x4, y1, UNIT, UNIT);
  358. X        }
  359. X        y1 += UNIT;             /* Position of next row */
  360. X        if (y > -2) {
  361. X                if (t1 & 8)
  362. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  363. X                                     x1, y1, UNIT, UNIT);
  364. X                if (t1 & 4)
  365. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  366. X                                     x2, y1, UNIT, UNIT);
  367. X                if (t1 & 2)
  368. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  369. X                                     x3, y1, UNIT, UNIT);
  370. X                if (t1 & 1)
  371. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  372. X                                     x4, y1, UNIT, UNIT);
  373. X        }
  374. X        y1 += UNIT;             /* Position of next row */
  375. X        if (y > -3) {
  376. X                if (t2 & 8)
  377. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  378. X                                     x1, y1, UNIT, UNIT);
  379. X                if (t2 & 4)
  380. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  381. X                                     x2, y1, UNIT, UNIT);
  382. X                if (t2 & 2)
  383. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  384. X                                     x3, y1, UNIT, UNIT);
  385. X                if (t2 & 1)
  386. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  387. X                                     x4, y1, UNIT, UNIT);
  388. X        }
  389. X        y1 += UNIT;             /* Position of next row */
  390. X        if (y > -4) {
  391. X                if (t3 & 8)
  392. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  393. X                                     x1, y1, UNIT, UNIT);
  394. X                if (t3 & 4)
  395. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  396. X                                     x2, y1, UNIT, UNIT);
  397. X                if (t3 & 2)
  398. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  399. X                                     x3, y1, UNIT, UNIT);
  400. X                if (t3 & 1)
  401. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  402. X                                     x4, y1, UNIT, UNIT);
  403. X        }
  404. X
  405. X    XSetFillStyle(XtDisplay(toplevel), gc, FillTiled);
  406. X        y1 = y * UNIT;          /* Position of 1st row of block grid    */
  407. X        if (y > -1) {
  408. X                if (t0 & 8)
  409. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  410. X                                     x1 +1, y1 +1, UNIT -2, UNIT -2);
  411. X                if (t0 & 4)
  412. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  413. X                                     x2 +1, y1 +1, UNIT -2, UNIT -2);
  414. X                if (t0 & 2)
  415. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  416. X                                     x3 +1, y1 +1, UNIT -2, UNIT -2);
  417. X                if (t0 & 1)
  418. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  419. X                                     x4 +1, y1 +1, UNIT -2, UNIT -2);
  420. X        }
  421. X        y1 += UNIT;             /* Position of next row */
  422. X        if (y > -2) {
  423. X                if (t1 & 8)
  424. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  425. X                                     x1 +1, y1 +1, UNIT -2, UNIT -2);
  426. X                if (t1 & 4)
  427. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  428. X                                     x2 +1, y1 +1, UNIT -2, UNIT -2);
  429. X                if (t1 & 2)
  430. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  431. X                                     x3 +1, y1 +1, UNIT -2, UNIT -2);
  432. X                if (t1 & 1)
  433. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  434. X                                     x4 +1, y1 +1, UNIT -2, UNIT -2);
  435. X        }
  436. X        y1 += UNIT;             /* Position of next row */
  437. X        if (y > -3) {
  438. X                if (t2 & 8)
  439. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  440. X                                     x1 +1, y1 +1, UNIT -2, UNIT -2);
  441. X                if (t2 & 4)
  442. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  443. X                                     x2 +1, y1 +1, UNIT -2, UNIT -2);
  444. X                if (t2 & 2)
  445. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  446. X                                     x3 +1, y1 +1, UNIT -2, UNIT -2);
  447. X                if (t2 & 1)
  448. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  449. X                                     x4 +1, y1 +1, UNIT -2, UNIT -2);
  450. X        }
  451. X        y1 += UNIT;             /* Position of next row */
  452. X        if (y > -4) {
  453. X                if (t3 & 8)
  454. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  455. X                                     x1 +1, y1 +1, UNIT -2, UNIT -2);
  456. X                if (t3 & 4)
  457. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  458. X                                     x2 +1, y1 +1, UNIT -2, UNIT -2);
  459. X                if (t3 & 2)
  460. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  461. X                                     x3 +1, y1 +1, UNIT -2, UNIT -2);
  462. X                if (t3 & 1)
  463. X                      XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  464. X                                     x4 +1, y1 +1, UNIT -2, UNIT -2);
  465. X        }
  466. X    XSetFillStyle(XtDisplay(toplevel), gc, FillSolid);
  467. X        XFlush(XtDisplay(toplevel));
  468. X}
  469. SHAR_EOF
  470. chmod 0644 draw.c || echo "restore of draw.c fails"
  471. echo "x - extracting event.c (Text)"
  472. sed 's/^X//' << 'SHAR_EOF' > event.c &&
  473. X#include "defs.h"
  474. X#define BUFSIZE 100
  475. X
  476. Xvoid
  477. Xcanvas_event_proc(w, client_data, event)
  478. X    Widget w;
  479. X    caddr_t client_data;
  480. X    XEvent *event;
  481. X{
  482. X    char buf[BUFSIZE];
  483. X    int length;
  484. X
  485. X        if (event->type == ButtonRelease)
  486. X                return;
  487. X    if (event->type == ButtonPress) {
  488. X            switch (event->xbutton.button) {
  489. X            case Button1:
  490. X                    if (event->xbutton.state == (Button1Mask || ShiftMask))
  491. X                            anti_proc();
  492. X                    else
  493. X                            left_proc();
  494. X                    break;
  495. X            case Button3:
  496. X                    if (event->xbutton.state == (Button3Mask || ShiftMask))
  497. X                            clock_proc();
  498. X                    else
  499. X                            right_proc();
  500. X                    break;
  501. X    
  502. X            case Button2:
  503. X                    if (event->xbutton.state != (Button2Mask || ShiftMask))
  504. X                            fast_proc();
  505. X                    break;
  506. X            }
  507. X        return;
  508. X    }
  509. X    if (event->type == KeyRelease)
  510. X        return;
  511. X    if (event->type == KeyPress) {
  512. X        length = XLookupString (event, buf, BUFSIZE, NULL, NULL);
  513. X        switch (buf[0]) {
  514. X        case 'j':
  515. X            left_proc();
  516. X            break;
  517. X        case 'k':
  518. X            anti_proc();
  519. X            break;
  520. X        case 'l':
  521. X            right_proc();
  522. X            break;
  523. X        case ' ':
  524. X            fast_proc();
  525. X            break;
  526. X        }
  527. X        return;
  528. X    }
  529. X}
  530. SHAR_EOF
  531. chmod 0644 event.c || echo "restore of event.c fails"
  532. echo "x - extracting init.c (Text)"
  533. sed 's/^X//' << 'SHAR_EOF' > init.c &&
  534. X#include "defs.h"
  535. X#include "tetris.xicon"
  536. X#include <sys/types.h>
  537. X#include <sys/timeb.h>
  538. X#include <pwd.h>
  539. X
  540. Xinitialise()
  541. X{
  542. X        struct passwd *who;
  543. X        char   *getenv();
  544. X    int i;
  545. X
  546. X        srand((int) time((time_t *) 0));
  547. X        define_shapes();
  548. X        if ((name = getenv("TETRIS")) == NULL) {
  549. X                who = getpwuid(getuid());
  550. X                name = who->pw_name;
  551. X        }
  552. X    print_authors();
  553. X        tetris_icon = XCreateBitmapFromData(XtDisplay(frame),
  554. X                                            XtWindow(frame),
  555. X                                      tetris_bits, tetris_width, tetris_height);
  556. X        i=0;
  557. X        XtSetArg(args[i], XtNiconPixmap, tetris_icon); i++;
  558. X        XtSetValues(toplevel, args, i);
  559. X        init_all();
  560. X        read_high_scores();
  561. X}
  562. X
  563. Xinit_all()
  564. X{
  565. X        int     i, j;
  566. X
  567. X    score_position = -1;
  568. X        end_of_game = 0;
  569. X        rows = score = shape_no = rot = xpos = ypos = 0;
  570. X        for (i = 0; i < UWIDTH; i++)
  571. X                for (j = 0; j < UHEIGHT; j++)
  572. X                        grid[i][j] = 0;
  573. X        create_shape();         /* Set up 1st shape */
  574. X        create_shape();         /* Set up next shape */
  575. X    XSetFunction(XtDisplay(toplevel), gc, GXclear);
  576. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  577. X                       0, 0, UNIT * UWIDTH, UNIT * UHEIGHT);
  578. X    XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  579. X    XSetLineAttributes(XtDisplay(toplevel), gc,
  580. X                           1, LineSolid, CapButt, JoinMiter);
  581. X    XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
  582. X                  0, UHEIGHT * UNIT, UWIDTH * UNIT, UHEIGHT * UNIT);
  583. X    XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
  584. X                  0, UHEIGHT * UNIT + SHADOW_HEIGHT, 
  585. X                  UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT);
  586. X    XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
  587. X                  UWIDTH * UNIT, 0, 
  588. X                  UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT + NEXT_HEIGHT);
  589. X        XFlush(XtDisplay(toplevel));
  590. X    i=0;
  591. X    XtSetArg(args[i], XtNstring, "         "); i++;
  592. X    XtSetValues(game_over, args, i);
  593. X        show_score();
  594. X        show_next();
  595. X        draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color);
  596. X}
  597. SHAR_EOF
  598. chmod 0644 init.c || echo "restore of init.c fails"
  599. echo "x - extracting main.c (Text)"
  600. sed 's/^X//' << 'SHAR_EOF' > main.c &&
  601. X#include "defs.h"
  602. X
  603. X#include <Xw/Panel.h>
  604. X#include <Xw/TitleBar.h>
  605. X#include <Xw/PButton.h>
  606. X#include <Xw/RCManager.h>
  607. X#include <Xw/SText.h>
  608. X#include <Xw/WorkSpace.h>
  609. X
  610. X
  611. X
  612. X
  613. Xmain(argc, argv)
  614. X        int     argc;
  615. X        char  **argv;
  616. X{
  617. X        int     i, j;
  618. X    XFontStruct *cyril;
  619. X
  620. X    toplevel = XtInitialize(argv[0], "TEtris", NULL, 0, &argc, argv);
  621. X        frame = XtCreateManagedWidget("Frame",
  622. X                      XwpanelWidgetClass,
  623. X                                      toplevel,
  624. X                                      NULL,0);
  625. X    i=0;
  626. X    XtSetArg(args[i], XtNwidgetType, XwTITLE); i++;
  627. X    XtSetArg(args[i], XtNstring, "tetris"); i++;
  628. X    cyril = XLoadQueryFont(XtDisplay(toplevel),"cyr-s25");
  629. X    if (cyril) XtSetArg(args[i], XtNfont, cyril); i++;
  630. X    tbar = XtCreateManagedWidget("TitleBar",
  631. X                                     XwtitlebarWidgetClass,
  632. X                                     frame,
  633. X                                     args, i);
  634. X    i=0;
  635. X    XtSetArg(args[i], XtNwidgetType, XwPULLDOWN); i++;
  636. X    XtSetArg(args[i], XtNwidth, UWIDTH * UNIT); i++;
  637. X    XtSetArg(args[i], XtNlayoutType, XwREQUESTED_COLUMNS); i++;
  638. X    XtSetArg(args[i], XtNlayout, XwMAXIMIZE); i++;
  639. X    XtSetArg(args[i], XtNcolumns, 2); i++;
  640. X        panel = XtCreateManagedWidget("Panel",
  641. X                                      XwrowColWidgetClass,
  642. X                                      frame,
  643. X                                      args, i);
  644. X    i=0;
  645. X    XtSetArg(args[i], XtNlayoutType, XwREQUESTED_COLUMNS); i++;
  646. X    XtSetArg(args[i], XtNcolumns, 1); i++;
  647. X    XtSetArg(args[i], XtNborderWidth, 0); i++;
  648. X        sub1_panel = XtCreateManagedWidget("Panel",
  649. X                                      XwrowColWidgetClass,
  650. X                                      panel,
  651. X                                      args, i);
  652. X    i=0;
  653. X    XtSetArg(args[i], XtNlayoutType, XwREQUESTED_COLUMNS); i++;
  654. X    XtSetArg(args[i], XtNcolumns, 1); i++;
  655. X    XtSetArg(args[i], XtNborderWidth, 0); i++;
  656. X        sub2_panel = XtCreateManagedWidget("Panel",
  657. X                                      XwrowColWidgetClass,
  658. X                                      panel,
  659. X                                      args, i);
  660. X    i=0;
  661. X    XtSetArg(args[i], XtNstring, "Score: 0 "); i++;
  662. X    XtSetArg(args[i], XtNborderWidth, 0); i++;
  663. X    XtSetArg(args[i], XtNstrip, FALSE); i++;
  664. X        score_item = XtCreateManagedWidget("Score",
  665. X                                           XwstatictextWidgetClass,
  666. X                                           sub1_panel,
  667. X                                           args, i);
  668. X    i=0;
  669. X    XtSetArg(args[i], XtNstring, "Level: 0 "); i++;
  670. X    XtSetArg(args[i], XtNborderWidth, 0); i++;
  671. X    XtSetArg(args[i], XtNstrip, FALSE); i++;
  672. X        level_item = XtCreateManagedWidget("Level",
  673. X                                           XwstatictextWidgetClass,
  674. X                                           sub1_panel,
  675. X                                           args, i);
  676. X    i=0;
  677. X    XtSetArg(args[i], XtNstring, "Rows: 0 "); i++;
  678. X    XtSetArg(args[i], XtNborderWidth, 0); i++;
  679. X    XtSetArg(args[i], XtNstrip, FALSE); i++;
  680. X        rows_item = XtCreateManagedWidget("Rows",
  681. X                                           XwstatictextWidgetClass,
  682. X                                           sub1_panel,
  683. X                                           args, i);
  684. X    i=0;
  685. X    XtSetArg(args[i], XtNstring, "          "); i++;
  686. X    XtSetArg(args[i], XtNborderWidth, 0); i++;
  687. X    XtSetArg(args[i], XtNstrip, FALSE); i++;
  688. X        game_over = XtCreateManagedWidget("Game",
  689. X                                           XwstatictextWidgetClass,
  690. SHAR_EOF
  691. echo "End of part 1"
  692. echo "File main.c is continued in part 2"
  693. echo "2" > s2_seq_.tmp
  694. exit 0
  695.