/* Tetrix by quentin */ #include #include #include #include #include #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 */ #define SCORE_FILE "/usr/tmp/.TetScores" char ScoreString[10]; struct ScoreStruct { char Name[10]; int Score; } High[10]; 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,"%-d",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() { Init(); for ( ; ; ) { NewGame(); Play(); ScoreIt(); DrawScore(); } } /*************************************************************/ 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(); /* initilialize 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,10); } 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."); } } /***********************************************************************/ DrawScore() { register int j; 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) { mvprintw(j+8,41,"%-s",(char *)High[j].Name); mvprintw(j+8,54,"%d",High[j].Score); } refresh(); } /*********************************************************************/ Boss() { register int x,y; clear(); refresh(); ioctl (0, TCSETA, &origtty); system("sh /dev/tty"); ioctl (1, TCSETAW, &tty); clear(); 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