home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume15
/
gtetris
/
part01
/
tetris.h
< prev
Wrap
C/C++ Source or Header
|
1993-01-27
|
5KB
|
205 lines
/*
# GENERIC X-WINDOW-BASED TETRIS
#
# tetris.h
#
###
#
# Copyright (C) 1992 Qiang Alex Zhao
# Computer Science Dept, University of Arizona
# azhao@cs.arizona.edu
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of the author not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# This program is distributed in the hope that it will be "playable",
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
*/
/*
* Common defs
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/file.h>
#include <string.h>
#include <pwd.h>
#ifdef HPUX
#include <time.h>
#define random() lrand48()
#define srandom(x) srand48(x)
#else
#include <sys/time.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#define assert(E) if (E); else fprintf(stderr,"Assertion failed, line %d, fill %s\n", __LINE__, __FILE__),exit(0)
/*
* Tetris defs
*/
/* score file */
#ifndef SCOREFILE
#define SCOREFILE "/usr/games/.tetris.scores"
#endif
/* Maximum # of scores allowed per person */
#ifndef MAXSCORES
#define MAXSCORES 3
#endif
/* number of scores shown */
#ifndef SHOWNSCORES
#define SHOWNSCORES 15
#endif
/* fonts */
#define TITLE_FONT "-*-new century schoolbook-bold-r-*-*-24-*-*-*-*-*-*-*"
#define SCORE_FONT "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*"
/****************************/
#define NAMELEN 12
#define NUM_BITMAPS (sizeof (bitmap_data) / sizeof (bitmap_data[0]))
#define eq(a, b) (!strcmp((a), (b)))
#define DEF_WIDTH 10
#define DEF_HEIGHT 20
#define BOX_HEIGHT 30
#define BOX_WIDTH 30
#define BOX_SPACE 1
#define X_MARGIN 1
#define Y_MARGIN 1
#define THING_SIZE 4
#define BASE_XPOS 100
#define BASE_YPOS 100
#define BORDER_WIDTH 3
#define TITLE_HEIGHT 40
#define NUM_FLASHES 15
#define SCORE_XPOS1 130
#define SCORE_XPOS2 230
#define SCORE_YPOS1 18
#define SCORE_YPOS2 32
#define BG_COLOR "lightyellow"
#define BD_COLOR "darkgreen"
#define TITLE_COLOR "blue"
#define TEXT_COLOR "red"
typedef struct score_s {
char myname[NAMELEN], myhost[NAMELEN], mytime[27];
char score[10];
char level[4];
char lines[5];
} score_t;
#define SCORELEN sizeof(score_t)
typedef struct pattern_s {
int whichbitmap;
char *fgname, *bgname;
XColor fg, bg;
Pixmap pixmap;
} pattern_t;
typedef enum {
NONE, LEFT, RIGHT, ROTATE, DROP
} command_t;
typedef struct field_s {
Window frame;
Window title;
Window win;
XFontStruct *tfont;
XFontStruct *sfont;
int **full;
int height, width;
int winheight, winwidth;
long score;
int level;
int lines;
} field_t;
typedef struct thing_s {
int map[THING_SIZE][THING_SIZE];
int xpos, ypos;
int size;
int probability;
} thing_t;
#define DIE_MESG "GAME OVER"
#define PAUSED_MESG "PAUSED"
#define ytr(y) (field->winheight - (y))
#define NUM_LEVELS 12
#define INF 10000000
#define MILLION 1000000
extern XColor bgcolor, bdcolor, titlecolor, textcolor;
extern Bool atBottom();
extern Bool overlapping();
extern Bool tryMove();
extern field_t *initField();
extern int checkLine();
extern int putBoxes();
extern long time();
extern thing_t *makeNewThing();
extern void Usage();
extern void addHighScore();
extern void banner();
extern void die();
extern void doBox();
extern void drawField();
extern void drawThing();
extern void drawThingDiff();
extern void fallDown();
extern void handleEvents();
extern void initPixmaps();
extern void moveOne();
extern void normTimeVal();
extern void rotateThing();
extern void showHighScores();
extern void updateScore();
extern Display *disp;
extern Window win;
extern XGCValues gcv;
extern XGCValues text;
extern GC gc_w;
extern GC gc_w2;
extern GC gc_t;
extern GC gc_wtx;
extern GC gc_ttx;