home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / gtetrs2 / part02 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  20.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: v15i006:  gtetris2 -  Generic Tetris for X11, V1.8, Part02/02
  5. Message-ID: <3734@master.CNA.TEK.COM>
  6. Date: 9 Oct 92 00:50:13 GMT
  7. Article-I.D.: master.3734
  8. Sender: news@master.CNA.TEK.COM
  9. Lines: 689
  10. Approved: billr@saab.CNA.TEK.COM
  11.  
  12. Submitted-by: "Qiang Alex Zhao" <azhao@cs.arizona.edu>
  13. Posting-number: Volume 15, Issue 6
  14. Archive-name: gtetris2/Part02
  15. Supersedes: gtetris: Volume 15, Issue 1-2
  16. Environment: X11R4/5, Xlib
  17.  
  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 2 (of 2)."
  26. # Contents:  COPYRIGHT Imakefile Makefile.std die.c tetris.c tetris.man
  27. # Wrapped by billr@saab on Thu Oct  8 17:46:30 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'COPYRIGHT'\"
  31. else
  32. echo shar: Extracting \"'COPYRIGHT'\" \(848 characters\)
  33. sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
  34. X# GENERIC X-WINDOW-BASED TETRIS
  35. X#
  36. X#  Copyright (C) 1992    Qiang Alex Zhao
  37. X#            Computer Science Dept, University of Arizona
  38. X#            azhao@cs.arizona.edu
  39. X#
  40. X#            All Rights Reserved
  41. X#
  42. X#  Permission to use, copy, modify, and distribute this software and
  43. X#  its documentation for any purpose and without fee is hereby granted,
  44. X#  provided that the above copyright notice appear in all copies and
  45. X#  that both that copyright notice and this permission notice appear in
  46. X#  supporting documentation, and that the name of the author not be
  47. X#  used in advertising or publicity pertaining to distribution of the
  48. X#  software without specific, written prior permission.
  49. X#
  50. X#  This program is distributed in the hope that it will be "playable",
  51. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  52. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  53. X#
  54. X
  55. END_OF_FILE
  56. if test 848 -ne `wc -c <'COPYRIGHT'`; then
  57.     echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
  58. fi
  59. # end of 'COPYRIGHT'
  60. fi
  61. if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  62.   echo shar: Will not clobber existing file \"'Imakefile'\"
  63. else
  64. echo shar: Extracting \"'Imakefile'\" \(1496 characters\)
  65. sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
  66. X/*
  67. X+ GENERIC X-WINDOW-BASED TETRIS
  68. X+
  69. X+    Imakefile
  70. X+
  71. X+++
  72. X+
  73. X+  Copyright (C) 1992    Qiang Alex Zhao
  74. X+            Computer Science Dept, University of Arizona
  75. X+            azhao@cs.arizona.edu
  76. X+
  77. X+            All Rights Reserved
  78. X+
  79. X+  Permission to use, copy, modify, and distribute this software and
  80. X+  its documentation for any purpose and without fee is hereby granted,
  81. X+  provided that the above copyright notice appear in all copies and
  82. X+  that both that copyright notice and this permission notice appear in
  83. X+  supporting documentation, and that the name of the author not be
  84. X+  used in advertising or publicity pertaining to distribution of the
  85. X+  software without specific, written prior permission.
  86. X+
  87. X+  This program is distributed in the hope that it will be "playable",
  88. X+  but WITHOUT ANY WARRANTY; without even the implied warranty of
  89. X+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  90. X+
  91. X*/
  92. X
  93. X/* set OS to empty or HPUX or AIX, if you know what system you are using ;o) */
  94. X             OS =
  95. X           DEST = /r/cas/usr/azhao/pub
  96. X      SCOREFILE = $(DEST)/.tetris.scores
  97. X
  98. X        DEFINES = -DSCOREFILE=\"$(SCOREFILE)\" $(OsNameDefines)
  99. XLOCAL_LIBRARIES = $(XLIB)
  100. X  SYS_LIBRARIES = -lm
  101. X           SRCS = tetris.c die.c utils.c
  102. X           OBJS = tetris.o die.o utils.o
  103. X       PROGRAMS = tetris tscores
  104. X
  105. XComplexProgramTarget(tetris)
  106. X
  107. Xall :: tetris tscores
  108. X
  109. Xtscores: tetris
  110. X    ln -s tetris tscores
  111. X
  112. Xtetris.o: tetris.c tetris.h
  113. Xdie.o: die.c tetris.h
  114. Xutils.o: utils.c tetris.h data.h
  115. X
  116. XInstallMultiple($(PROGRAMS), $(DEST))
  117. X
  118. END_OF_FILE
  119. if test 1496 -ne `wc -c <'Imakefile'`; then
  120.     echo shar: \"'Imakefile'\" unpacked with wrong size!
  121. fi
  122. # end of 'Imakefile'
  123. fi
  124. if test -f 'Makefile.std' -a "${1}" != "-c" ; then 
  125.   echo shar: Will not clobber existing file \"'Makefile.std'\"
  126. else
  127. echo shar: Extracting \"'Makefile.std'\" \(2497 characters\)
  128. sed "s/^X//" >'Makefile.std' <<'END_OF_FILE'
  129. X# GENERIC X-WINDOW-BASED TETRIS
  130. X#
  131. X#    Makefile
  132. X#
  133. X###
  134. X#
  135. X#  Copyright (C) 1992    Qiang Alex Zhao
  136. X#            Computer Science Dept, University of Arizona
  137. X#            azhao@cs.arizona.edu
  138. X#
  139. X#            All Rights Reserved
  140. X#
  141. X#  Permission to use, copy, modify, and distribute this software and
  142. X#  its documentation for any purpose and without fee is hereby granted,
  143. X#  provided that the above copyright notice appear in all copies and
  144. X#  that both that copyright notice and this permission notice appear in
  145. X#  supporting documentation, and that the name of the author not be
  146. X#  used in advertising or publicity pertaining to distribution of the
  147. X#  software without specific, written prior permission.
  148. X#
  149. X#  This program is distributed in the hope that it will be "playable",
  150. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  151. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  152. X#
  153. X
  154. X
  155. X###########################################################################
  156. X### Configurable Settings
  157. X
  158. X# destination directory
  159. XDEST        = /r/cas/usr/azhao/pub
  160. X
  161. X# score file
  162. XSCOREFILE    = $(DEST)/.tetris.scores
  163. X
  164. X# path to X header files
  165. XXINCLUDE    = /usr/include/X11
  166. X
  167. X# path to X library files
  168. XXLIBS        = /usr/lib/X11
  169. X
  170. X# the C compiler, used as linker ;o)
  171. XCC        = cc
  172. X
  173. X# local settings (blank means no change)
  174. X#    System:        LOCAL_DEFS    LOCAL_LIBS    LINK_LIBS
  175. X#--------------------------------------------------------------------------
  176. X#
  177. X#    HP-UX        -DHPUX                -L $(XLIBS)
  178. X#
  179. X#    AIX        -DAIX        -lbsd
  180. X#
  181. X
  182. XLOCAL_DEFS    =
  183. XLOCAL_LIBS    =
  184. XLINK_LIBS    = -L$(XLIBS)
  185. X
  186. X###########################################################################
  187. X### Fixed settings
  188. X
  189. XMAKEFILE    = Makefile
  190. X
  191. XPROGT        = tetris
  192. XPROGS        = tscores
  193. X
  194. XHDRS        = tetris.h \
  195. X          data.h
  196. X
  197. XCFLAGS        = -O -I$(XINCLUDE) -DSCOREFILE='"$(SCOREFILE)"' $(LOCAL_DEFS)
  198. XLDFLAGS        = -O $(LINK_LIBS) $(LOCAL_LIBS)
  199. X
  200. XLDLIBS        = -lX11 -lm
  201. X
  202. XSRCS        = tetris.c \
  203. X          die.c \
  204. X          utils.c
  205. X
  206. XOBJT        = tetris.o \
  207. X          utils.o \
  208. X          die.o
  209. X
  210. XPRINT        = enscript -2rG
  211. X
  212. X
  213. X### Dependencies/Actions
  214. X
  215. Xall:        $(PROGT) $(PROGS)
  216. X
  217. X$(PROGT):    $(OBJT)
  218. X    @echo -n "Linking $(PROGT) ... "
  219. X    @$(CC) $(LDFLAGS) $(OBJT) $(LDLIBS) -o $(PROGT)
  220. X    @echo "Done."
  221. X
  222. X$(PROGS):    $(OBJS)
  223. X    @echo -n "Linking $(PROGS) ... "
  224. X    ln -s $(PROGT) $(PROGS)
  225. X    @echo "Done."
  226. X
  227. Xclean:
  228. X    rm -rf *.o $(PROGT) $(PROGS)
  229. X
  230. Xinstall:    $(PROGT) $(PROGS)
  231. X    @echo Installing $(PROGT) and $(PROGS) in $(DEST)
  232. X    install -s $(PROGT) $(PROGS) $(DEST)
  233. X
  234. Xprint:
  235. X    $(PRINT) $(HDRS) $(SRCS)
  236. X
  237. X### dependencies for each object
  238. Xtetris.o:    tetris.c tetris.h
  239. Xutils.o:    utils.c tetris.h data.h
  240. Xdie.o:        die.c tetris.h
  241. X
  242. END_OF_FILE
  243. if test 2497 -ne `wc -c <'Makefile.std'`; then
  244.     echo shar: \"'Makefile.std'\" unpacked with wrong size!
  245. fi
  246. # end of 'Makefile.std'
  247. fi
  248. if test -f 'die.c' -a "${1}" != "-c" ; then 
  249.   echo shar: Will not clobber existing file \"'die.c'\"
  250. else
  251. echo shar: Extracting \"'die.c'\" \(4442 characters\)
  252. sed "s/^X//" >'die.c' <<'END_OF_FILE'
  253. X/*
  254. X# GENERIC X-WINDOW-BASED TETRIS
  255. X#
  256. X#    die.c
  257. X#
  258. X###
  259. X#
  260. X#  Copyright (C) 1992    Qiang Alex Zhao
  261. X#            Computer Science Dept, University of Arizona
  262. X#            azhao@cs.arizona.edu
  263. X#
  264. X#            All Rights Reserved
  265. X#
  266. X#  Permission to use, copy, modify, and distribute this software and
  267. X#  its documentation for any purpose and without fee is hereby granted,
  268. X#  provided that the above copyright notice appear in all copies and
  269. X#  that both that copyright notice and this permission notice appear in
  270. X#  supporting documentation, and that the name of the author not be
  271. X#  used in advertising or publicity pertaining to distribution of the
  272. X#  software without specific, written prior permission.
  273. X#
  274. X#  This program is distributed in the hope that it will be "playable",
  275. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  276. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  277. X#
  278. X*/
  279. X
  280. X#include "tetris.h"
  281. X
  282. Xvoid
  283. Xbanner(field, str)
  284. X    field_t        *field;
  285. X    char           *str;
  286. X{
  287. X    int             mlen = strlen(str);
  288. X    int             x, y, w, ascent, descent;
  289. X
  290. X    ascent = field->tfont->ascent;
  291. X    descent = field->tfont->descent;
  292. X    w = XTextWidth(field->tfont, str, mlen);
  293. X    x = (field->winwidth - w) / 2;
  294. X    y = (field->winheight - ascent - descent) / 2;
  295. X
  296. X    XFillRectangle(disp, field->win, gc_w2, x - 5, y - ascent - 5,
  297. X    w + 10, ascent + descent + 10);
  298. X    XDrawString(disp, field->win, gc_ttx, x, y, str, mlen);
  299. X}
  300. X
  301. Xvoid
  302. Xdie(field)
  303. X    field_t        *field;
  304. X{
  305. X    time_t          tloc;
  306. X    score_t         myscore;
  307. X    struct passwd  *tmp;
  308. X
  309. X    time(&tloc);
  310. X
  311. X    banner(field, DIE_MESG);
  312. X    XFlush(disp);
  313. X    sleep(1);
  314. X
  315. X    gethostname(myscore.myhost, NAMELEN);
  316. X    myscore.myhost[NAMELEN-1] = '\0';
  317. X    setpwent();
  318. X    tmp = getpwuid(getuid());
  319. X    if (tmp == NULL)        /* should not occur */
  320. X    sprintf(myscore.myname, "%d", getuid());
  321. X    else
  322. X    strncpy(myscore.myname, tmp->pw_name, NAMELEN);
  323. X    endpwent();
  324. X    myscore.myname[NAMELEN-1] = '\0';
  325. X
  326. X    sprintf(myscore.score, "%9d", field->score);
  327. X    sprintf(myscore.level, "%3d", field->level);
  328. X    sprintf(myscore.lines, "%4d", field->lines);
  329. X    strcpy(myscore.mytime, asctime(localtime(&tloc)));
  330. X    fprintf(stderr, "\t%s", myscore.mytime);
  331. X    fprintf(stderr, "Your final score is %d, at level %d with %d rows.\n\n",
  332. X       field->score, field->level, field->lines);
  333. X
  334. X    addHighScore(&myscore, field->score);
  335. X    showHighScores(SHOWNSCORES);
  336. X
  337. X    XCloseDisplay(disp);
  338. X    exit(0);
  339. X}
  340. X
  341. Xvoid 
  342. XaddHighScore(myscore, snum)
  343. X    score_t        *myscore;
  344. X    long int        snum;
  345. X{
  346. X    char            buff[2][SCORELEN];
  347. X    int             fd;
  348. X    int             tmp, ptmp, s1;
  349. X    int             mycount = 0;
  350. X    Bool            saved = False, trickle = False;
  351. X
  352. X    fd = open(SCOREFILE, O_CREAT | O_RDWR, 0644);
  353. X    if (fd == -1) {
  354. X    fprintf(stderr, "Cannot write the score-file!\n");
  355. X    return;
  356. X    }
  357. X    LOCK(fd);
  358. X
  359. X    tmp = 0;
  360. X    ptmp = 1;
  361. X    bcopy((char *) myscore, buff[1], SCORELEN);
  362. X
  363. X    while (read(fd, buff[tmp], SCORELEN) == SCORELEN) {
  364. X    sscanf(((score_t *)buff[tmp])->score, " %d", &s1);
  365. X    if (!saved && (s1 <= snum)) {
  366. X        trickle = True;
  367. X        saved = True;
  368. X        mycount++;
  369. X    }
  370. X    if (!strncmp(myscore->myname,
  371. X        ((score_t *)buff[tmp])->myname, NAMELEN)) {
  372. X        mycount++;
  373. X    }
  374. X    /* Then check if we should trickle the score */
  375. X    if (trickle) {
  376. X        lseek(fd, (off_t) -SCORELEN, L_INCR);
  377. X        write(fd, buff[ptmp], SCORELEN);
  378. X        ptmp = tmp;
  379. X        tmp = (tmp + 1) % 2;
  380. X    }
  381. X    /*
  382. X     * As we trickle, we add up records owned by me. Once we hit max,
  383. X     * we throw it away, and stop trickling.
  384. X     */
  385. X    if ((mycount > MAXSCORES) || ((mycount == MAXSCORES) && !trickle)) {
  386. X        trickle = False;
  387. X        break;
  388. X    }
  389. X    }    /* while */
  390. X
  391. X    if (trickle) {
  392. X    write(fd, buff[ptmp], SCORELEN);
  393. X    }
  394. X    if (!saved && (mycount < MAXSCORES)) {
  395. X    write(fd, (char *) myscore, SCORELEN);
  396. X    }
  397. X
  398. X    ULOCK(fd);
  399. X    close(fd);
  400. X}
  401. X
  402. Xvoid 
  403. XshowHighScores(ub)
  404. X    int             ub;
  405. X{
  406. X    int             fd, i;
  407. X    score_t         curs;
  408. X
  409. X    fd = open(SCOREFILE, O_RDONLY, 0644);
  410. X    if (fd == -1)
  411. X    return;
  412. X
  413. X    i = 0;
  414. X    fprintf(stderr, "   # USER            SCORE   L    R  HOST         DATE\n");
  415. X
  416. X    while (read(fd, (char *) &curs, SCORELEN) == SCORELEN) {
  417. X    i++;
  418. X    if ((ub == 0) || (i<= ub))
  419. X        fprintf(stderr, "%4d %-12s%9s %3s %4s  %-12s %-s",
  420. X        i, curs.myname, curs.score, curs.level, curs.lines,
  421. X        curs.myhost, curs.mytime);
  422. X    }
  423. X    close(fd);
  424. X    fprintf(stderr, "There are %d scores to date\n", i);
  425. X}
  426. X
  427. END_OF_FILE
  428. if test 4442 -ne `wc -c <'die.c'`; then
  429.     echo shar: \"'die.c'\" unpacked with wrong size!
  430. fi
  431. # end of 'die.c'
  432. fi
  433. if test -f 'tetris.c' -a "${1}" != "-c" ; then 
  434.   echo shar: Will not clobber existing file \"'tetris.c'\"
  435. else
  436. echo shar: Extracting \"'tetris.c'\" \(5240 characters\)
  437. sed "s/^X//" >'tetris.c' <<'END_OF_FILE'
  438. X/*
  439. X# GENERIC X-WINDOW-BASED TETRIS
  440. X#
  441. X#    tetris.c
  442. X#
  443. X###
  444. X#
  445. X#  Copyright (C) 1992    Qiang Alex Zhao
  446. X#            Computer Science Dept, University of Arizona
  447. X#            azhao@cs.arizona.edu
  448. X#
  449. X#            All Rights Reserved
  450. X#
  451. X#  Permission to use, copy, modify, and distribute this software and
  452. X#  its documentation for any purpose and without fee is hereby granted,
  453. X#  provided that the above copyright notice appear in all copies and
  454. X#  that both that copyright notice and this permission notice appear in
  455. X#  supporting documentation, and that the name of the author not be
  456. X#  used in advertising or publicity pertaining to distribution of the
  457. X#  software without specific, written prior permission.
  458. X#
  459. X#  This program is distributed in the hope that it will be "playable",
  460. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  461. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  462. X#
  463. X*/
  464. X
  465. X#include "tetris.h"
  466. X
  467. Xvoid
  468. Xmain(argc, argv)
  469. X    int             argc;
  470. X    char           *argv[];
  471. X{
  472. X    int             start_level = 0, lines_full = 0;
  473. X    field_t        *field;
  474. X    thing_t        *thing = NULL;
  475. X    int             readfds, writefds, exceptfds;
  476. X    struct timeval  nextfall, now, delay;
  477. X    struct timezone tzone;
  478. X    Bool            reset_time = True;
  479. X    XEvent          ev;
  480. X
  481. X    if (!strcmp(argv[0], "tscores")) {
  482. X    fprintf(stderr, "       GENERIC TETRIS  HALL OF FAME\n\n");
  483. X    showHighScores(0);
  484. X    exit(0);
  485. X    }
  486. X
  487. X    fprintf(stderr, "\t\tGENERIC TETRIS V1.8\n");
  488. X    fprintf(stderr, "\tCopyright (C) 1992    Qiang Alex Zhao\n\n");
  489. X    fprintf(stderr, "GENERIC TETRIS comes with ABSOLUTELY NO WARRANTY.\n");
  490. X    fprintf(stderr, "Send bug-reports/fixes/comments to:\n");
  491. X    fprintf(stderr, "\tQiang Alex Zhao,    azhao@cs.arizona.edu\n");
  492. X    fprintf(stderr, "\tComputer Science Dept, University of Arizona, Tucson\n\n");
  493. X
  494. X    /* initialization */
  495. X
  496. X    start_level = 3;
  497. X    lines_full = 0;
  498. X
  499. X    if (argc > 3) {
  500. X    Usage(argv);
  501. X    }
  502. X
  503. X    if (argc > 1) {
  504. X    if (sscanf(argv[1], "%d", &start_level) < 1) {
  505. X        Usage(argv);
  506. X    }
  507. X    }
  508. X    if (argc > 2) {
  509. X    if (sscanf(argv[2], "%d", &lines_full) < 1) {
  510. X        Usage(argv);
  511. X    }
  512. X    }
  513. X
  514. X    if (start_level < 0) start_level = 0;
  515. X    if (start_level >= NUM_LEVELS) start_level = NUM_LEVELS - 1;
  516. X    if (lines_full < 0) lines_full = 0;
  517. X    if (lines_full >= DEF_HEIGHT - 2) lines_full = DEF_HEIGHT - 3;
  518. X
  519. X    srandom((int) time(NULL));
  520. X
  521. X    if ((disp = XOpenDisplay(NULL)) == NULL) {
  522. X    fprintf(stderr, "Error: can't open display \"%s\".\n\n",
  523. X        XDisplayName(NULL));
  524. X    exit(1);
  525. X    }
  526. X    rootScreen = DefaultScreen(disp);
  527. X    rootDepth = DefaultDepth(disp, rootScreen);
  528. X
  529. X    /* rebinding keypad */
  530. X    XRebindKeysym(disp, XK_R7,    NULL, 0, "j", sizeof(char));
  531. X    XRebindKeysym(disp, XK_R10,   NULL, 0, "j", sizeof(char));
  532. X    XRebindKeysym(disp, XK_R13,   NULL, 0, "j", sizeof(char));
  533. X    XRebindKeysym(disp, XK_Left,  NULL, 0, "j", sizeof(char));
  534. X    XRebindKeysym(disp, XK_R8,    NULL, 0, "k", sizeof(char));
  535. X    XRebindKeysym(disp, XK_R11,   NULL, 0, "k", sizeof(char));
  536. X    XRebindKeysym(disp, XK_R14,   NULL, 0, "k", sizeof(char));
  537. X    XRebindKeysym(disp, XK_Up,    NULL, 0, "k", sizeof(char));
  538. X    XRebindKeysym(disp, XK_Down,  NULL, 0, "k", sizeof(char));
  539. X    XRebindKeysym(disp, XK_R9,    NULL, 0, "l", sizeof(char));
  540. X    XRebindKeysym(disp, XK_R12,   NULL, 0, "l", sizeof(char));
  541. X    XRebindKeysym(disp, XK_R15,   NULL, 0, "l", sizeof(char));
  542. X    XRebindKeysym(disp, XK_Right, NULL, 0, "l", sizeof(char));
  543. X
  544. X    /* setting color */
  545. X    if (rootDepth == 1) {
  546. X    bgcolor.pixel = WhitePixel(disp, rootScreen);
  547. X    bdcolor.pixel = BlackPixel(disp, rootScreen);
  548. X    titlecolor.pixel = BlackPixel(disp, rootScreen);
  549. X    textcolor.pixel = BlackPixel(disp, rootScreen);
  550. X    } else {
  551. X    cmap = DefaultColormap(disp, rootScreen);
  552. X    XParseColor(disp, cmap, BG_COLOR, &bgcolor);
  553. X    XAllocColor(disp, cmap, &bgcolor);
  554. X    XParseColor(disp, cmap, BD_COLOR, &bdcolor);
  555. X    XAllocColor(disp, cmap, &bdcolor);
  556. X    XParseColor(disp, cmap, TITLE_COLOR, &titlecolor);
  557. X    XAllocColor(disp, cmap, &titlecolor);
  558. X    XParseColor(disp, cmap, TEXT_COLOR, &textcolor);
  559. X    XAllocColor(disp, cmap, &textcolor);
  560. X    }
  561. X
  562. X    /* initialize the playground */
  563. X
  564. X    field = initField(DEF_WIDTH, DEF_HEIGHT, lines_full, argc, argv);
  565. X    field->level = start_level;
  566. X
  567. X    /* wait till mapped */
  568. X    XNextEvent(disp, &ev);
  569. X
  570. X    initPixmaps(field);
  571. X
  572. X    drawField(field);
  573. X
  574. X    while (True) {
  575. X    if (reset_time) {
  576. X        gettimeofday(&nextfall, &tzone);
  577. X        nextfall.tv_usec += 10000 * speeds[field->level];
  578. X        normTimeVal(&nextfall);
  579. X    }
  580. X    if (XPending(disp))
  581. X        handleEvents(field, &thing, False);
  582. X    gettimeofday(&now, &tzone);
  583. X    delay.tv_sec = nextfall.tv_sec - now.tv_sec;
  584. X    delay.tv_usec = nextfall.tv_usec - now.tv_usec;
  585. X    normTimeVal(&delay);
  586. X    if (delay.tv_sec >= 0) {
  587. X        writefds = exceptfds = 0;
  588. X        readfds = 1 << ConnectionNumber(disp);
  589. X        (void) select(sizeof(int) * 8, (fd_set *) &readfds, (fd_set *)
  590. X        &writefds, (fd_set *) &exceptfds, &delay);
  591. X    }
  592. X    gettimeofday(&now, &tzone);
  593. X    if ((now.tv_sec > nextfall.tv_sec) ||
  594. X        ((now.tv_sec == nextfall.tv_sec) &&
  595. X         (now.tv_usec > nextfall.tv_usec))) {
  596. X        handleEvents(field, &thing, True);
  597. X        reset_time = True;
  598. X    } else {
  599. X        handleEvents(field, &thing, False);
  600. X        reset_time = False;
  601. X    }
  602. X    }
  603. X    /* never come to here */
  604. X}
  605. X
  606. END_OF_FILE
  607. if test 5240 -ne `wc -c <'tetris.c'`; then
  608.     echo shar: \"'tetris.c'\" unpacked with wrong size!
  609. fi
  610. # end of 'tetris.c'
  611. fi
  612. if test -f 'tetris.man' -a "${1}" != "-c" ; then 
  613.   echo shar: Will not clobber existing file \"'tetris.man'\"
  614. else
  615. echo shar: Extracting \"'tetris.man'\" \(1881 characters\)
  616. sed "s/^X//" >'tetris.man' <<'END_OF_FILE'
  617. X.TH TETRIS 1 "04 Oct 1992, V1.8" "University of Arizona"
  618. X.SH NAME
  619. XGENERIC TETRIS \- Yet Another Tetris Game on X
  620. X.SH SYNOPSIS
  621. X.B tetris
  622. X[ \fIstarting_level\fP [ \fIrows_pre-filled\fP ] ]
  623. X.br
  624. X.B tscores
  625. X.SH DESCRIPTION
  626. X.LP
  627. X"Tetris" is the game. It only lists the top 15 players at the end,
  628. Xeach player may has at most three scores. "Tscores" lists all
  629. Xthe players/scores.
  630. X.LP
  631. XKey "\fIj\fP" moves the block left; "\fIl\fP" moves right;
  632. X"\fIk\fP" rotates. Left-handed
  633. Xpeople may want to use "\fIs\fP", "\fId\fP", "\fIf\fP"
  634. Xrespectively. The space bar drops a block quickly.
  635. X.LP
  636. XUse \fICTRL-L\fP key combination to redraw \- in case it mess somthing up.
  637. X.LP
  638. XAs usual, "\fI+\fP" and "\fI\-\fP" speed up or lower down the speed. Note
  639. Xthat you don't need to press the \fISHIFT\fP key \- "\fI=\fP" and "\fI_\fP" also
  640. Xwork. The "\fIb\fP" toggles the "beep".
  641. X.LP
  642. XIf you press \fICTRL-S\fP or "\fIp\fP", the game will be paused, and the window
  643. Xwill be iconified \- just in case your boss suddenly appears at
  644. Xyour door. ;o)
  645. X.SH SEE ALSO
  646. X.LP
  647. Xxtetris(1), xmris(1)
  648. X.SH BUG REPORTS
  649. X.LP
  650. XSend bugs (or their reports, or fixes) to the author:
  651. X.RS
  652. XQiang Alex Zhao,    <\fIazhao@cs.arizona.edu\fP>
  653. X.br
  654. XComputer Science Department
  655. X.br
  656. XUniversity of Arizona
  657. X.br
  658. XTucson, AZ 85721
  659. X.RE
  660. X.LP
  661. XAnd note: my first name is NOT spelled as "Quiang".
  662. X.SH UPDATES
  663. XThe most updated source could be found on \fIexport.lcs.mit.edu\fP under
  664. X\fI/contrib\fP.
  665. X.SH ACKNOWLEDGEMENTS
  666. X.LP
  667. XI studied an old tetris game for X10, wrote by Wayne Christopher
  668. X<\fIfaustus@cs.berkeley.edu\fP> in 1988; then I adopted the ideas in
  669. Xrepresenting those "blocks" and rotating them, and added X11
  670. Xstuff. Also I learned a lot from Nathan Sidwell's great game
  671. X"\fIxmris\fP", e.g. the "iconifying pause".
  672. X.LP
  673. XThanks go to people who helped me in improving the program.
  674. X.SH COPYRIGHTS
  675. X.LP
  676. X\*R Copyright 1992, Qiang A. Zhao, University of Arizona.
  677. X
  678. END_OF_FILE
  679. if test 1881 -ne `wc -c <'tetris.man'`; then
  680.     echo shar: \"'tetris.man'\" unpacked with wrong size!
  681. fi
  682. # end of 'tetris.man'
  683. fi
  684. echo shar: End of archive 2 \(of 2\).
  685. cp /dev/null ark2isdone
  686. MISSING=""
  687. for I in 1 2 ; do
  688.     if test ! -f ark${I}isdone ; then
  689.     MISSING="${MISSING} ${I}"
  690.     fi
  691. done
  692. if test "${MISSING}" = "" ; then
  693.     echo You have unpacked both archives.
  694.     rm -f ark[1-9]isdone
  695. else
  696.     echo You still need to unpack the following archives:
  697.     echo "        " ${MISSING}
  698. fi
  699. ##  End of shell archive.
  700. exit 0
  701.