home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume15 / gtetris2 / part01 / tetris.h < prev    next >
C/C++ Source or Header  |  1993-01-27  |  6KB  |  257 lines

  1. /*
  2. # GENERIC X-WINDOW-BASED TETRIS
  3. #
  4. #    tetris.h
  5. #
  6. ###
  7. #
  8. #  Copyright (C) 1992    Qiang Alex Zhao
  9. #            Computer Science Dept, University of Arizona
  10. #            azhao@cs.arizona.edu
  11. #
  12. #            All Rights Reserved
  13. #
  14. #  Permission to use, copy, modify, and distribute this software and
  15. #  its documentation for any purpose and without fee is hereby granted,
  16. #  provided that the above copyright notice appear in all copies and
  17. #  that both that copyright notice and this permission notice appear in
  18. #  supporting documentation, and that the name of the author not be
  19. #  used in advertising or publicity pertaining to distribution of the
  20. #  software without specific, written prior permission.
  21. #
  22. #  This program is distributed in the hope that it will be "playable",
  23. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. #
  26. */
  27.  
  28. /*
  29.  * Common defs
  30.  */
  31.  
  32. #include    <stdio.h>
  33. #include    <sys/types.h>
  34. #include    <sys/errno.h>
  35. #include    <sys/file.h>
  36. #include    <pwd.h>
  37.  
  38. #ifdef    SYSV    /* for Imake */
  39. #include    <string.h>
  40. #else
  41. #include    <strings.h>
  42. #endif
  43.  
  44. #ifdef    HPUX
  45. #include    <unistd.h>
  46. #include    <time.h>
  47. #define    random()    lrand48()
  48. #define    srandom(x)    srand48(x)
  49. #define    LOCK(X)        lockf((X), F_LOCK, 0)
  50. #define    ULOCK(X)    lockf((X), F_ULOCK, 0)
  51. #else
  52. #include    <sys/time.h>
  53. #define    LOCK(X)        flock((X), LOCK_EX)
  54. #define    ULOCK(X)    flock((X), LOCK_UN)
  55. #endif
  56.  
  57. #ifdef    AIX
  58. #include    <sys/select.h>
  59. #endif
  60.  
  61. /*
  62.  * X related
  63.  */
  64.  
  65. #include    <X11/Xlib.h>
  66. #include    <X11/Xutil.h>
  67. #include    <X11/cursorfont.h>
  68. #include    <X11/keysym.h>
  69.  
  70. /*
  71.  * Assertion
  72.  */
  73.  
  74. #define    assert(E, X)    if ((E)==0) \
  75.             { fprintf(stderr, \
  76.              "Assertion failed, line %d, fill %s: %s\n", \
  77.              __LINE__, __FILE__, (X)); \
  78.              exit(-1); }
  79.  
  80. /*
  81.  * Tetris defs
  82.  */
  83.  
  84. /* score file */
  85. #ifndef    SCOREFILE
  86. #define SCOREFILE    "/usr/games/.tetris.scores"
  87. #endif
  88.  
  89. /* Maximum # of scores allowed per person */
  90. #ifndef    MAXSCORES
  91. #define MAXSCORES 3
  92. #endif
  93.  
  94. /* number of scores shown */
  95. #ifndef    SHOWNSCORES
  96. #define    SHOWNSCORES    15
  97. #endif
  98.  
  99. /* fonts */
  100. #define TITLE_FONT      "-*-new century schoolbook-bold-r-*-*-24-*-*-*-*-*-*-*"
  101. #define SCORE_FONT      "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*"
  102.  
  103. /* if the above fonts cannot be allocated, try the following */
  104. #define    TITLE_FONT2    "-*-*-bold-r-*-*-24-*-*-*-*-*-*-*"
  105. #define SCORE_FONT2    "-*-*-bold-r-*-*-12-*-*-*-*-*-*-*"
  106.  
  107. /****************************/
  108.  
  109. #define    NAMELEN        12
  110.  
  111. #define NUM_BITMAPS    (sizeof (bitmap_data) / sizeof (bitmap_data[0]))
  112.  
  113. #define DEF_WIDTH    10
  114. #define DEF_HEIGHT    20
  115.  
  116. #define BOX_HEIGHT    30
  117. #define BOX_WIDTH    30
  118.  
  119. #define BOX_SPACE    1
  120.  
  121. #define X_MARGIN    1
  122. #define Y_MARGIN    1
  123.  
  124. #define THING_SIZE    4
  125.  
  126. #define BASE_XPOS    100
  127. #define BASE_YPOS    100
  128.  
  129. #define BORDER_WIDTH    3
  130.  
  131. #define TITLE_HEIGHT    40
  132.  
  133. #define NUM_FLASHES    15
  134.  
  135. #define SCORE_XPOS1    150
  136. #define SCORE_XPOS2    230
  137. #define SCORE_YPOS1    18
  138. #define SCORE_YPOS2    32
  139.  
  140. #define BG_COLOR    "lightyellow"
  141. #define BD_COLOR    "darkgreen"
  142. #define TITLE_COLOR    "blue"
  143. #define TEXT_COLOR    "red"
  144.  
  145. typedef struct score_s {
  146.     char            myname[NAMELEN], myhost[NAMELEN], mytime[27];
  147.     char            score[10];
  148.     char            level[4];
  149.     char            lines[5];
  150. }               score_t;
  151. #define SCORELEN    sizeof(score_t)
  152.  
  153. #define    DUMC    {0, 0, 0, 0, '\0', '\0'}
  154. #define    DUMP    ((Pixmap) 0)
  155. typedef struct pattern_s {
  156.     int             whichbitmap;
  157.     char           *fgname, *bgname;
  158.     XColor          fg, bg;
  159.     Pixmap          pixmap;
  160. }               pattern_t;
  161.  
  162. typedef enum {
  163.     NONE, LEFT, RIGHT, ROTATE, DROP
  164. }               command_t;
  165.  
  166. typedef struct field_s {
  167.     Window          frame;
  168.     Window          title;
  169.     Window          win;
  170.     Atom            delw;
  171.     XFontStruct    *tfont;
  172.     XFontStruct    *sfont;
  173.     int           **full;
  174.     int             height, width;
  175.     int             winheight, winwidth;
  176.     long int        score;
  177.     int             level;
  178.     int             lines;
  179. }               field_t;
  180.  
  181. typedef struct thing_s {
  182.     int             map[THING_SIZE][THING_SIZE];
  183.     int             xpos, ypos;
  184.     int             size;
  185.     int             probability;
  186. }               thing_t;
  187.  
  188. typedef struct bitmap_datum {
  189.     char           *data;
  190.     int             height, width;
  191. }               bitmap_t;
  192.  
  193. #define    DIE_MESG    "GAME OVER"
  194. #define    PAUSED_MESG    "PAUSED"
  195.  
  196. #define ytr(y)        (field->winheight - (y))
  197.  
  198. #define NUM_LEVELS    17
  199.  
  200. #define INF        10000000
  201.  
  202. #define MILLION        1000000
  203.  
  204. extern XColor   bgcolor, bdcolor, titlecolor, textcolor;
  205.  
  206. extern Bool     atBottom();
  207. extern Bool     overlapping();
  208. extern Bool     tryMove();
  209. extern field_t *initField();
  210. extern int      checkLine();
  211. extern int      putBoxes();
  212. extern thing_t *makeNewThing();
  213. extern void    Usage();
  214. extern void     addHighScore();
  215. extern void     banner();
  216. extern void     die();
  217. extern void     doBox();
  218. extern void     drawField();
  219. extern void     drawThing();
  220. extern void     drawThingDiff();
  221. extern void     fallDown();
  222. extern void     handleEvents();
  223. extern void     initPixmaps();
  224. extern void     moveOne();
  225. extern void     normTimeVal();
  226. extern void     rotateThing();
  227. extern void     showHighScores();
  228. extern void     updateScore();
  229.  
  230. extern Display *disp;
  231. extern Window   win;
  232. extern GC       gc_t;
  233. extern GC       gc_w;
  234. extern GC       gc_w2;
  235. extern GC       gc_wtx;
  236. extern GC       gc_ttx;
  237. extern GC       gc_pat[];
  238. extern XGCValues gcv;
  239. extern XGCValues text;
  240. extern XGCValues color;
  241.  
  242. extern pattern_t patterns[];
  243. extern bitmap_t bitmap_data[];
  244. extern int      num_patterns;
  245. extern thing_t  possible[];
  246. extern int      speeds[];
  247. extern int      thresh[];
  248. extern XColor   bgcolor, bdcolor, titlecolor, textcolor;
  249. extern Colormap cmap;
  250. extern int      rootDepth;
  251. extern int      rootScreen;
  252.  
  253. extern Bool     beep;
  254. extern char    *winName;
  255. extern char    *iconName;
  256.  
  257.