/* Tetrix by quentin */ #ifndef ATARIST #include #include #endif #include #include #include "curses.h" #include "tet.h" /********** Some global variable declarations ************/ int Type; /* type specifies rotation, shape and color of blocks */ int Row; /* Row of pivot point of block */ int Column; /* Column of pivot point of block */ int Pause; /* Time between movements this block */ int CurrentPause; /* Time between movements per level */ int FallingDown; /* True when space bar is pressed */ int Beep; char Key; /* holds last key polled */ #ifdef ATARIST #define SCORE_FILE "c:\\etc\\scores.tet" cuserid(name) char *name; { register i, c; while (Cconis()) Crawcin(); mvaddstr(23,0,"Name? "); Cconws("\033e"); while (1) { for (i=0; (c=Crawcin()) != '\r';) if (c == 8) { if (i > 0) { Cconws("\010 \010"); --i; } } else if (i < 9 && c >= ' ' && c <= '~') Cconout(name[i++] = c); if (i) break; mvaddstr(23,6, "?\010"); } name[i] = 0; Cconws("\033f"); mvaddstr(23,0," "); } mrand48() { return Random(); } #else #define SCORE_FILE "/usr/tmp/.TetScores" #endif char ScoreString[10]; struct ScoreStruct { char Name[10]; long Score; /* Grrr.... */ } High[10]; long ThisScore; int HighsChanged; #ifndef ATARIST char *ttyname(); char combuf[2]; struct termio origtty, tty; #endif 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,"%-ld",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 '!' #define PAUSE_KEY '\033' #define PLAY_KEY 'p' #define SCORE_KEY 'h' #define MENU_KEY 'm' /**************************************************MAIN*****/ main() { Init(); for ( ; ; ) { NewGame(); Play(); ScoreIt(); DrawScore(); } } /*************************************************************/ Init() { register char *ttnam, *p; register int x, y, i, fd; #ifndef ATARIST 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); #endif Beep=0; HighsChanged = 0; /* ScoreIt(); */ initscr(); /* initilialize board to spaces */ for (x=0; x= 0) { read(fd,High,sizeof(High)); close(fd); } #else oldmask = umask(0); if ((fd=open(SCORE_FILE,O_CREAT|O_RDONLY,0666)) != -1) { read(fd,High,sizeof(High)); close(fd); } #endif else { for(i=0; i<10; i++) High[i].Score = 0; for(i=0; i<10; i++) strncpy(" ",High[i].Name,10); } #ifndef ATARIST umask(oldmask); #endif for (i=0; i<10; i++) /* place this guy */ if (High[i].Score <= ThisScore) break; if (i < 10 ) { /* insert this score */ HighsChanged = 1; for (j=9; j>i; j--) { /* move down others */ if (High[j-1].Score) { High[j].Score = High[j-1].Score; strncpy(High[j].Name,High[j-1].Name,10); } } cuserid((char *) High[i].Name); High[i].Score = ThisScore; } if (HighsChanged) { #ifdef ATARIST if ((fd = open(SCORE_FILE, 2)) < 0) fd = creat(SCORE_FILE, 0); if (fd >= 0) { write(fd,High,sizeof(High)); close(fd); } #else if ((fd=open(SCORE_FILE,O_RDWR)) != -1) { write(fd,High,sizeof(High)); close(fd); } #endif else mvaddstr(22,0,"Couldn't open high score file."); } } /***********************************************************************/ DrawScore() { register int j; char lbuf[80]; mvaddstr( 5,35,"| Hit 'm' for menu |"); mvaddstr( 6,35,"| |"); mvaddstr( 7,35,"| HIGH SCORES |"); mvaddstr( 8,35,"| 1. |"); mvaddstr( 9,35,"| 2. |"); mvaddstr(10,35,"| 3. |"); mvaddstr(11,35,"| 4. |"); mvaddstr(12,35,"| 5. |"); mvaddstr(13,35,"| 6. |"); mvaddstr(14,35,"| 7. |"); mvaddstr(15,35,"| 8. |"); mvaddstr(16,35,"| 9. |"); mvaddstr(17,35,"|10. |"); mvaddstr(18,35,"| |"); mvaddstr(19,35,"| |"); mvaddstr(20,35,"| |"); for (j=0; j<10; j++) { if (High[j].Score) { sprintf(lbuf,"%-s",(char *)High[j].Name); mvaddstr(j+8,41,lbuf); sprintf(lbuf,"%ld",High[j].Score); mvaddstr(j+8,54,lbuf); } } refresh(); } /*********************************************************************/ Boss() { register int x,y; #ifdef ATARIST erase(); system("tsh"); /* fork off a shell... */ initscr(); #else clear(); refresh(); ioctl (0, TCSETA, &origtty); system("sh /dev/tty"); ioctl (1, TCSETAW, &tty); clear(); #endif DrawMenu(); /* restore board */ for (x=0; x= BOARD_HIGH) || (x < 0) || (x >= BOARD_WIDE)) return(0); if (Board[x][y] != NO_CHAR) return(0); else return(1); } /*********************************************************************/ TestRows() { register int x,y,tempy,fullrow; int marked[BOARD_HIGH]; for (y=0; y=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