From 1680dfd41d8a60812b0495271b73e54d2ae80f3f Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 29 Nov 1994 03:19:50 +0000 Subject: [PATCH] Initial revision --- tet.c | 502 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 502 insertions(+) create mode 100644 tet.c diff --git a/tet.c b/tet.c new file mode 100644 index 0000000..6575a10 --- /dev/null +++ b/tet.c @@ -0,0 +1,502 @@ +/* Tetrix by quentin */ + +#include +#include +#include +#include +#include +#include "tet.h" + +#define HIGHCOUNT 10 /* count of high scorers to show */ +#define SCORELEN 10 /* max length of score string */ +#define NAMELEN 10 /* max length of user name string */ + +/********** Some global variable declarations ************/ +static int Pause; /* Time between movements this block */ +static int InitPause; /* Initial value of CurrentPause */ +static int CurrentPause; /* Time between movements per level */ +static int FallingDown; /* True when space bar is pressed */ +static int Beep; /* Beep on invalid move? */ +static char Key; /* holds last key polled */ + +int dispchars[6] +# ifdef IBMASCIZ + = {0263,0304,0332,0277,0300,0331}; +#else + = {'|', '-', '.', '.', '`', '\''}; +# endif /* IBMASCIZ */ +# define VERT dispchars[0] /* vertical wall */ +# define HORIZ dispchars[1] /* horizontal wall */ +# define ULC dispchars[2] /* upper left corner */ +# define URC dispchars[3] /* upper right corner */ +# define LLC dispchars[4] /* lower left corner */ +# define LRC dispchars[5] /* lower right corner */ + +#define SCORE_FILE "/usr/tmp/.TetScores" +char ScoreString[SCORELEN]; +struct ScoreStruct { + char Name[NAMELEN]; + int Score; +} High[HIGHCOUNT]; +int ThisScore,HighsChanged; + +char *ttyname(); +char combuf[2]; +struct termio origtty, tty; +char Board[BOARD_WIDE][BOARD_HIGH]; +char Temp[BOARD_WIDE][BOARD_HIGH]; /* temp storage for TestRows */ + +/* debug flash to screen */ +#define FLASHMSG(x) +/* +#define FLASHMSG(x) { mvaddstr(23,0," "); \ + mvaddstr(23,0,x); \ + refresh(); } +*/ +#define UPSCORE(x) { ThisScore += x; \ + sprintf((char *)ScoreString,"%-06d",ThisScore); \ + mvaddstr(1,46,ScoreString); } + +#define NULL_KEY '\0' +#define FALL_KEY ' ' +#define RIGHT_KEY 'l' +#define LEFT_KEY 'j' +#define ROTATE_KEY 'k' +#define L_RIGHT_KEY 'f' /* for south paws */ +#define L_LEFT_KEY 's' +#define L_ROTATE_KEY 'd' +#define QUIT_KEY 'q' +#define BEEP_KEY 'b' +#define BOSS_KEY '\033' +#define PLAY_KEY 'p' +#define SCORE_KEY 'h' +#define MENU_KEY 'm' + +/**************************************************MAIN*****/ +main(argc, argv) +int argc; +char **argv; +{ + if (argc >= 2) + InitPause = atoi(argv[1]); + else + InitPause = 150; + Init(); + for ( ; ; ) { + NewGame(); + Play(); + DrawScore(ScoreIt()); + } +} + +/*************************************************************/ +Init() +{ + register char *ttnam, *p; + register int x,y,i,fd; + int timein; + + time(&timein); /* get start time */ + srand48(timein); /* start rand randomly */ + + ttnam = ttyname (0); + close (0); + open (ttnam, O_NDELAY); + /* + * setup raw mode, no echo + */ + ioctl (0, TCGETA, &origtty); + ioctl (0, TCGETA, &tty); + tty.c_iflag &= 077; + tty.c_oflag &= 077700; + tty.c_lflag = 0201; + tty.c_cc[4] = 1; + ioctl (1, TCSETAW, &tty); + signal(SIGINT, SIG_IGN); + + Beep=0; + HighsChanged = 0; + ScoreIt(); + initscr(); + +#ifdef TERMINFO + /* good, we can use the defined forms-drawing characters */ + VERT = ACS_VLINE; + HORIZ = ACS_HLINE; + ULC = ACS_ULCORNER; + URC = ACS_URCORNER; + LLC = ACS_LLCORNER; + LRC = ACS_LRCORNER; +#endif /* TERMINFO */ + +#ifdef COLOR + init_colors(); +#endif /* COLOR */ + /* initialize board to spaces */ + for (x=0; xi; j--) /* move down others */ + if (High[j-1].Score) + { + High[j].Score = High[j-1].Score; + strncpy(High[j].Name,High[j-1].Name,NAMELEN); + } + cuserid((char *) High[i].Name); + High[i].Score = ThisScore; + } + + if (HighsChanged) + { + if ((fd=open(SCORE_FILE,O_RDWR)) != -1) { + write(fd,High,sizeof(High)); + close(fd); + } + else mvaddstr(22,0,"Couldn't open high score file."); + } + + return(i < HIGHCOUNT ? i : -1); +} + +/***********************************************************************/ +DrawScore(highindex) +int highindex; +{ + register int j; + + mvaddstr( 5,36," Hit 'm' for menu "); + mvaddstr( 6,36," "); + mvaddstr( 7,36," HIGH SCORES "); + + for (j=0; j/dev/tty"); + ioctl (1, TCSETAW, &tty); + clear(); + DrawMenu(); + /* restore board */ + for (x=0; x=0; y--) { + fullrow = 1; + for (x=0; x=0; y--) + if (marked[y]) { + UPSCORE(30-y); + for (x=0; x=0; y--) { + for (x=0; x