kimmel@umvlsi.ecs.umass.edu (Mathew Kimmel) (06/02/91)
I just assumed it wasn't cool to post sources here, since I'd never seen any. But, maybe I was wrong, so I'll give it a shot. Here is a shar of my port of Tetris, the popular falling-blocks game. Enjoy, and please send me any questions/comments... -Matt ---CUT HERE---------------CUT HERE-----------------CUT HERE--- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: COPYRIGHT Makefile Makefile.orig README README.Coh defs.h # main.c polluser.c score.c shape.c support.c tetris.6 # Wrapped by kimmel@risky.ecs.umass.edu on Sat Jun 1 14:34:47 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f COPYRIGHT -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"COPYRIGHT\" else echo shar: Extracting \"COPYRIGHT\" \(1295 characters\) sed "s/^X//" >COPYRIGHT <<'END_OF_COPYRIGHT' XCopyright 1989 Phill Everson & Martyn Shortley XCopyright 1989 Roberto Biancardi X XThis notice and any statement of authorship must be reproduced Xon all copies. The authors do not make any warranty expressed Xor implied, or assume any liability or responsiblity for the Xuse of this software. X XAny distributor of copies of this software shall grant the Xrecipient permission for further redistribution as permitted Xby this notice. Any distributor must distribute this software Xwithout any fee or other monetary gains, unless expressed written Xpermission is granted by the authors. X XThis software or its use shall not be: sold, rented, leased, Xtraded, or otherwise marketed without the expressed written Xpermission of the authors. X XIf the software is modified in a manner creating derivative Xcopyrights, appropriate legends may be placed on derivative Xwork in addition to that set forth above. X XPermission is hereby granted to copy, reproduce, redistribute or Xotherwise use this software as long as the conditions above Xare met. X XAll rights not granted by this notice are reserved. X XAuthors: Phill Everson <everson@cs.bris.ac.uk> X Martyn Shortley <shortley@cs.bris.ac.uk> X Biancardi Roberto tmpmbx!deejay!i2ack!usixth!bob X (on EUcon, the FREE European Connection for UUCP) X END_OF_COPYRIGHT if test 1295 -ne `wc -c <COPYRIGHT`; then echo shar: \"COPYRIGHT\" unpacked with wrong size! fi # end of overwriting check fi if test -f Makefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile\" else echo shar: Extracting \"Makefile\" \(2377 characters\) sed "s/^X//" >Makefile <<'END_OF_Makefile' X# **THIS MAKEFILE IS CONFIGURED FOR COHERENT** X########################################################################### X# Define this line, if you are using Xenix. X#XENLIB=-ltermlib -lx XXENLIB=-lterm X########################################################################### X# Define this if you have an old version of curses. XXENFLAGS=-DOLDCURSES X########################################################################### X# Define this if you have the nap call, probably your xenix has X# but it seem to do not work at all. To test this, try: X# X# #include <sys/param.h> X# main() { nap(HZ); } X# X# Then: X# X# /bin/time a.out X# X# If nap works, real execution time of this test program should X# be about one second. Else, your nap don't work at all. X# X#POLLFLAGS=-DUSENAP X########################################################################### X# Define this if you have the poll system call (not tested). X#POLLFLAGS=-DUSEPOLL X########################################################################### X# Define this if you don't have poll() or nap() and you don't X# want to consume cpu time for games. That's because on poor 2.0 X# to perform delay with a better resolution than 1/10 secs X# tetris busy wait on times(). This does not seem to be a super-hogger, X# because busy-wating is done only when the player reach higher X# levels, but if you see your response time going down because of X# tetris, use this. X#POLLFLAGS=-DDONTHOG X########################################################################### X# My keyboard seems to have some problems with the space bar, X# particularly generating two space instead of one, causing two X# consecutive fast drop to be executed. If you esperience something X# of similar use this. X#KEYBDFLAGS=-DKEYBDKLUDGE X########################################################################### X XCFLAGS=-O -DCOHERENT $(POLLFLAGS) $(XENFLAGS) $(KEYBDFLAGS) XLIBES=-lcurses $(XENLIB) XBINDIR=/usr/games XPROG=tetris XCFILES=main.c shape.c support.c score.c polluser.c XOFILES=main.o shape.o support.o score.o polluser.o X X$(PROG): $(OFILES) X cc $(CFLAGS) -o $(PROG) $(OFILES) $(LIBES) X X$(OFILES): defs.h X Xinstall: $(PROG) X strip $(PROG) X install -s $(PROG) $(BINDIR) X Xclean: X rm -f *.o core X Xshar : X shar -a README \ X COPYRIGHT \ X Makefile \ X tetris.6 \ X defs.h \ X main.c \ X polluser.c \ X score.c \ X shape.c \ X support.c \ X >tetris.shar END_OF_Makefile if test 2377 -ne `wc -c <Makefile`; then echo shar: \"Makefile\" unpacked with wrong size! fi # end of overwriting check fi if test -f Makefile.orig -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile.orig\" else echo shar: Extracting \"Makefile.orig\" \(2306 characters\) sed "s/^X//" >Makefile.orig <<'END_OF_Makefile.orig' X########################################################################### X# Define this line, if you are using Xenix. X#XENLIB=-ltermlib -lx X########################################################################### X# Define this if you have an old version of curses. X#XENFLAGS=-DOLDCURSES X########################################################################### X# Define this if you have the nap call, probably your xenix has X# but it seem to do not work at all. To test this, try: X# X# #include <sys/param.h> X# main() { nap(HZ); } X# X# Then: X# X# /bin/time a.out X# X# If nap works, real execution time of this test program should X# be about one second. Else, your nap don't work at all. X# X#POLLFLAGS=-DUSENAP X########################################################################### X# Define this if you have the poll system call (not tested). X#POLLFLAGS=-DUSEPOLL X########################################################################### X# Define this if you don't have poll() or nap() and you don't X# want to consume cpu time for games. That's because on poor 2.0 X# to perform delay with a better resolution than 1/10 secs X# tetris busy wait on times(). This does not seem to be a super-hogger, X# because busy-wating is done only when the player reach higher X# levels, but if you see your response time going down because of X# tetris, use this. X#POLLFLAGS=-DDONTHOG X########################################################################### X# My keyboard seems to have some problems with the space bar, X# particularly generating two space instead of one, causing two X# consecutive fast drop to be executed. If you esperience something X# of similar use this. X#KEYBDFLAGS=-DKEYBDKLUDGE X########################################################################### X XCFLAGS=-O $(POLLFLAGS) $(XENFLAGS) $(KEYBDFLAGS) XLIBES=-lcurses $(XENLIB) XBINDIR=/usr/games XPROG=tetris XCFILES=main.c shape.c support.c score.c polluser.c XOFILES=main.o shape.o support.o score.o polluser.o X X$(PROG): $(OFILES) X cc $(CFLAGS) -o $(PROG) $(OFILES) $(LIBES) X X$(OFILES): defs.h X Xinstall: $(PROG) X strip $(PROG) X install -s $(PROG) $(BINDIR) X Xclean: X rm -f *.o core X Xshar : X shar -a README \ X COPYRIGHT \ X Makefile \ X tetris.6 \ X defs.h \ X main.c \ X polluser.c \ X score.c \ X shape.c \ X support.c \ X >tetris.shar END_OF_Makefile.orig if test 2306 -ne `wc -c <Makefile.orig`; then echo shar: \"Makefile.orig\" unpacked with wrong size! fi # end of overwriting check fi if test -f README -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"README\" else echo shar: Extracting \"README\" \(511 characters\) sed "s/^X//" >README <<'END_OF_README' X XThis version on tetris should run on any system V and xenix system Xwhich supports the curses library. XCarefully look at the begging of the Makefile, then make and run. X XI used the game-logic of the version posted to the net by Phill Everson X<everson@cs.bris.ac.uk> and Martyn Shortley <shortley@cs.bris.ac.uk>_ X XLet bob@usixth know about any bug, fixes, enhancements and so on. XIf you have curses which support colors, it should be easy Xto modify set1pixel in main.c to attrset, depending on the value of col. END_OF_README if test 511 -ne `wc -c <README`; then echo shar: \"README\" unpacked with wrong size! fi # end of overwriting check fi if test -f README.Coh -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"README.Coh\" else echo shar: Extracting \"README.Coh\" \(1122 characters\) sed "s/^X//" >README.Coh <<'END_OF_README.Coh' XThis game was originally posted as tetris-v to comp.sources.games, in Xvolume 8. It seemed the closest of all versions of tetris I found to Xrunning under Coherent, so I've "ported" it. This involved some Xmodifications to score.c, since Coherent doesn't support uname() (although Xit defines the utsname structure and declares it as an external variable Xwhich the linker can't find in sys/utsname.h, very strange); extensive Xmodifications to polluser.c (I rewrote the timer function as well as Xfixing some weirdnesses), and minor changes to the other source files. XAll of my modifications are #ifdefed, and the program should compile Xfine on System V with the original makefile. X XI also added the -g command line option, which allows you to set the X"speed" of the game--actually the number of milliseconds between Xiterations of the main loop. You'll have to experiment with this; Xthe game was originally hardwired to 100 msecs, which I thought was Xtoo fast for the first level. The default speed is now 200. X XEnjoy, and please mail any feedback, bug reports, or suggestions to: Xkimmel@umvlsi.ecs.umass.edu X X-Matt Kimmel END_OF_README.Coh if test 1122 -ne `wc -c <README.Coh`; then echo shar: \"README.Coh\" unpacked with wrong size! fi # end of overwriting check fi if test -f defs.h -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"defs.h\" else echo shar: Extracting \"defs.h\" \(1166 characters\) sed "s/^X//" >defs.h <<'END_OF_defs.h' X#include <stdio.h> X X#define UWIDTH 10 X#define UHEIGHT 22 X X#define WHITE 1 X#define BLACK 2 X#define RED 3 X#define ORANGE 4 X#define YELLOW 5 X#define GREEN 6 X#define BLUE 7 X#define CYAN 8 X#define VIOLET 9 X#define LSIDE 10 X#define RSIDE 11 X#define BOTTOM 12 X#define SHADOW 13 X#define ULCORN 14 X#define URCORN 15 X#define BLCORN 16 X#define BRCORN 17 X Xint score_position; /* position of this game in the hiscore tab */ Xint shape_no; /* the dripping shape */ Xint xpos, ypos, rot; /* x, y, rotation of shape_no */ Xint score; /* current score */ Xint rows; /* number of rows deleted */ Xint next_no; /* next shape */ Xint next_rot; /* rotation of next shape */ Xchar *name; /* username */ X Xunsigned char grid[UWIDTH][UHEIGHT]; X Xstruct shape_table { X int table[4][4]; X int width; X int height; X int offset; X int pointv[4]; X char color; X} shape[7]; X Xstruct shape { X int shape; X int rot; X int width; X int height; X int offset; X int pointv; X char color; X int was_shown; X int was_shadowed; X} ; END_OF_defs.h if test 1166 -ne `wc -c <defs.h`; then echo shar: \"defs.h\" unpacked with wrong size! fi # end of overwriting check fi if test -f main.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"main.c\" else echo shar: Extracting \"main.c\" \(12253 characters\) sed "s/^X//" >main.c <<'END_OF_main.c' X#include "defs.h" X X#include <sys/types.h> X#include <setjmp.h> X#include <pwd.h> X#include <curses.h> X#ifndef COHERENT X#include <term.h> X#endif X X#define VUNIT 1 /* ver unit */ X#define HUNIT 2 /* hor unit */ X#define NORM_OFFSET 15 /* x offset for blocks */ X#define NEXT_HEIGHT (VUNIT*5) /* Height for next block */ X Xstatic char *blostr = " "; /* char used to draw blocks */ Xstatic jmp_buf rest; /* to restart the game */ Xstatic int beep = 1; Xstatic int beginlev = 0; X Xint speed = 200; X Xmain(argc, argv) X int argc; X char **argv; X{ X int i, c; X X for ( i=1; i < argc; i++ ) { X if ( argv[i][0] == '-' ) switch ( argv[i][1] ) { X case 's' : X beep = 0; X break; X case 'l' : X if ( argv[i][2] ) X beginlev = atoi(argv[i]+2); X else X beginlev = atoi(argv[++i]); X if ( beginlev < 0 ) X beginlev = 0; X break; X case 'b' : X if ( argv[i][2] ) X c = argv[i][2]; X else X c = argv[++i][0]; X blostr[0] = blostr[1] = c; X break; X case 'g' : X if ( argv[i][2] ) X speed = atoi(argv[i]+2); X else X speed = atoi(argv[++i]); X if( speed < 10 ) X speed = 10; X break; X } X } X initialise(); X setjmp(rest); X init_all(); X main_loop(); X exit(0); X} X Xinitialise() X{ X struct passwd *who; X char *getenv(); X int end_proc(); X X print_authors(); X srand((unsigned) time((time_t *) 0)); X define_shapes(); X who = (struct passwd *)getpwuid(getuid()); X name = who->pw_name; X init_tty(); X read_high_scores(); X#ifndef OLDCURSES X if ( enter_reverse_mode ) X enter_standout_mode = enter_reverse_mode; X else if ( blostr[0] == ' ' ) X blostr[0] = blostr[1] = '#'; X#endif X} X Xinit_all() X{ X int i, j; X X score_position = -1; X rows = score = shape_no = rot = xpos = ypos = 0; X for (i = 0; i < UWIDTH; i++) X for (j = 0; j < UHEIGHT; j++) X grid[i][j] = 0; X create_shape(); /* Set up 1st shape */ X create_shape(); /* Set up next shape */ X clear(); X setpixels(NORM_OFFSET-1, 0, 1, UHEIGHT , LSIDE); X set1pixel(NORM_OFFSET-1, UHEIGHT, BLCORN); X setpixels(NORM_OFFSET+UWIDTH, 0, 1, UHEIGHT , RSIDE); X set1pixel(NORM_OFFSET+UWIDTH, UHEIGHT, BRCORN); X show_score(1); X show_next(1); X draw_shadow(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X setuptty(); X} X Xinit_tty() { X initscr(); X leaveok(stdscr,FALSE); X raw(); X noecho(); X nonl(); X} X Xmain_loop() X{ X register char *p; X register int nc; X#ifdef KEYBDKLUDGE X register prevop; X register int lastop = 0; X#endif X char buf[16]; X X for ( setlevel(beginlev); ; ) { X refresh(); X nc = polluser(buf,sizeof(buf)); X for ( p = buf; nc-- > 0; ) { X#ifdef KEYBDKLUDGE X prevop = lastop; X lastop = 0; X#endif X switch ( *p++ ) { X case 0 : X drop_block(); X#ifdef KEYBDKLUDGE X lastop = prevop; X#endif X break; X case '8' : X anti_proc(); X break; X case '7' : X left_proc(); X break; X case '*' : X clock_proc(); X break; X case '9' : X right_proc(); X break; X case ' ' : X#ifdef KEYBDKLUDGE X if ( prevop != ' ' ) { X fast_proc(); X lastop = ' '; X } X#else X fast_proc(); X#endif X break; X case 'q' : X case 'Q' : X closeuptty(); X end_proc(); X break; X } X } X } X} X Xdrop_block() X{ X register int orows; X X if (block_can_drop(shape_no, xpos, ypos, rot)) X print_shape(shape_no, xpos + NORM_OFFSET, ypos++, rot, WHITE); X else { X if (ypos < 0) X end_game(); X else { X orows = rows; X score += shape[shape_no].pointv[rot]; X store_shape(shape_no, xpos, ypos, rot); X remove_full_lines(ypos); X create_shape(); X show_score(1); X show_next(1); X if ( orows != rows ) { X scbeep(); X setlevel(beginlev + (rows/10)); X } X } X } X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X} X Xstatic show_score(on) X{ X register int y, x; X char b1[32], b2[32], b3[32]; X char *p1, *p2, *p3; X X if ( on ) { X sprintf(p1 = b1, "S C O R E : %d", score); X sprintf(p2 = b2, "L e v e l : %d", beginlev + (rows/10) ); X sprintf(p3 = b3, "R o w s : %d", rows); X } else X p1 = p2 = p3 = " "; X x = NORM_OFFSET + UWIDTH + 5; X y = 1; X wtext(x, y , p1, 0); X wtext(x, y + 2, p2, 0); X wtext(x, y + 4, p3, 0); X} X Xint waituser(echon) { X int c; X X refresh(); X if ( echon ) X echo(); X else X noecho(); X c = getch(); X return c; X} X Xend_game() { X int c; X X closeuptty(); X setpixels(9, 6, 22 , 10, WHITE); X set1pixel(9,6,ULCORN); X setpixels(10, 6, 20 , 1, BOTTOM); X set1pixel(30,6,URCORN); X setpixels(9, 7, 1 , 9, LSIDE); X setpixels(30, 7, 1 , 9, RSIDE); X set1pixel(9,16,BLCORN); X setpixels(10, 16, 20 , 1, BOTTOM); X set1pixel(30,16,BRCORN); X wtext(15,11," G A M E O V E R ", 1); X scbeep(); X while ( waituser(0) != ' ' ) X ; X update_highscore_table(); X print_high_scores(); X wtext(15,20," Another game ? ", 0); X c = waituser(1); X if ( c == 'n' || c == 'N' || c == 'q' || c == 'Q' ) X end_proc(); X longjmp(rest,1); X} X Xend_proc() X{ X wtext(15,LINES-6," ",1); X wtext(15,LINES-5," Play Tetris! ",1); X wtext(15,LINES-4," ",1); X move(LINES-1,0); X refresh(); X endwin(); X exit(0); X} X Xleft_proc() X{ X if (block_can_left(shape_no, xpos, ypos, rot)) { X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, WHITE); X xpos--; X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X } X} X Xright_proc() X{ X if (block_can_right(shape_no, xpos, ypos, rot)) { X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, WHITE); X xpos++; X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X } X} X Xanti_proc() X{ X int newrot; X X newrot = (rot + 3) % 4; X if (check_rot(shape_no, xpos, ypos, newrot)) { X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, WHITE); X rot = newrot; X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X } X} X Xclock_proc() X{ X int newrot; X X newrot = (rot + 1) % 4; X if (check_rot(shape_no, xpos, ypos, newrot)) { X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, WHITE); X rot = newrot; X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X } X} X Xfast_proc() X{ X while (block_can_drop(shape_no, xpos, ypos, rot)) { X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, WHITE); X ypos++; X print_shape(shape_no, xpos + NORM_OFFSET, ypos, rot, shape[shape_no].color); X } X} X X/* Drawing primitives X */ Xdraw_shadow(shape_no, xpos, ypos, rot, col) X int shape_no, xpos, ypos, rot, col; X{ X int y1; X int x1, x2, x3, x4; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X x1 = xpos; /* Position of 1st column of block grid */ X x2 = x1+1; /* Position of 2nd column of block grid */ X x3 = x2+1; /* Position of 3rd column of block grid */ X x4 = x3+1; /* Position of 4th column of block grid */ X X y1 = UHEIGHT; X X setpixels(NORM_OFFSET, y1, UWIDTH, 1, BOTTOM); X if (t0 & 8 || t1 & 8 || t2 & 8 || t3 & 8) X set1pixel(x1, y1, SHADOW); X if (t0 & 4 || t1 & 4 || t2 & 4 || t3 & 4) X set1pixel(x2, y1, SHADOW); X if (t0 & 2 || t1 & 2 || t2 & 2 || t3 & 2) X set1pixel(x3, y1, SHADOW); X if (t0 & 1 || t1 & 1 || t2 & 1 || t3 & 1) X set1pixel(x4, y1, SHADOW); X} X Xshow_next(on) X{ X int y; X X y = 1; X setpixels(0, y , UWIDTH, NEXT_HEIGHT - 1, WHITE); X if ( on ) { X wtext(0, y , " N e x t : ", 0); X print_shape(next_no, 6, y, next_rot, shape[next_no].color); X } X} X Xprint_shape(shape_no, x, y, rot, col) X int shape_no, x, y, rot, col; X{ X int x1, x2, x3, x4, y1; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X x1 = x; /* Position of 1st column of block grid */ X x2 = x1 + 1; /* Position of 2nd column of block grid */ X x3 = x2 + 1; /* Position of 3rd column of block grid */ X x4 = x3 + 1; /* Position of 4th column of block grid */ X y1 = y; /* Position of 1st row of block grid */ X X if (y > -1) { X if (t0 & 8) X set1pixel(x1, y1, col); X if (t0 & 4) X set1pixel(x2, y1, col); X if (t0 & 2) X set1pixel(x3, y1, col); X if (t0 & 1) X set1pixel(x4, y1, col); X } X y1 += 1; /* Position of next row */ X if (y > -2) { X if (t1 & 8) X set1pixel(x1, y1, col); X if (t1 & 4) X set1pixel(x2, y1, col); X if (t1 & 2) X set1pixel(x3, y1, col); X if (t1 & 1) X set1pixel(x4, y1, col); X } X y1 += 1; /* Position of next row */ X if (y > -3) { X if (t2 & 8) X set1pixel(x1, y1, col); X if (t2 & 4) X set1pixel(x2, y1, col); X if (t2 & 2) X set1pixel(x3, y1, col); X if (t2 & 1) X set1pixel(x4, y1, col); X } X y1 += 1; /* Position of next row */ X if (y > -4) { X if (t3 & 8) X set1pixel(x1, y1, col); X if (t3 & 4) X set1pixel(x2, y1, col); X if (t3 & 2) X set1pixel(x3, y1, col); X if (t3 & 1) X set1pixel(x4, y1, col); X } X} X X/* Term routines X */ X Xwtext(x,y,text,bold) Xchar *text; X{ X scmove(x,y); X if ( bold ) { X standout(); X addstr(text); X standend(); X } else X addstr(text); X} X Xstatic setpixels(x,y,xsize,ysize,col) X{ X int yy; X int xx; X X for ( yy=y; yy < y+ysize; yy++ ) { X for ( xx=x; xx < x+xsize; xx++ ) { X set1pixel(xx,yy,col); X } X } X} X Xstatic int set1pixel(x,y,col) { X scmove(x,y); X switch ( col ) { X case WHITE : X addstr(" "); X break; X case RSIDE : X addstr("||"); X break; X case LSIDE : X addstr("||"); X break; X case BOTTOM : X addstr("--"); X break; X case ULCORN : X case BLCORN : X addstr("+-"); X break; X case URCORN : X case BRCORN : X addstr("-+"); X break; X case SHADOW : X addstr("=="); X break; X default : X standout(); X addstr(blostr); X standend(); X break; X } X} X Xscinsert(y) X{ X scmove(0,y); X insertln(); X set1pixel(NORM_OFFSET-1, 0, LSIDE); X set1pixel(NORM_OFFSET+UWIDTH, 0, RSIDE); X} X Xscdelete(y) X{ X show_score(0); X show_next(0); X scmove(0,y); X deleteln(); X} X Xstatic scmove(x,y) X{ X move(y*VUNIT,x*HUNIT); X} X Xstatic int scbeep() { X int c = 7; X X if ( beep ) { X refresh(); X write(2,&c,1); X } X} X END_OF_main.c if test 12253 -ne `wc -c <main.c`; then echo shar: \"main.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f polluser.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"polluser.c\" else echo shar: Extracting \"polluser.c\" \(2542 characters\) sed "s/^X//" >polluser.c <<'END_OF_polluser.c' X X#include <termio.h> X#ifdef COHERENT X#include <sys/fcntl.h> X#include <sys/timeb.h> X#else X#include <fcntl.h> X#endif X#include <sys/param.h> X#include <sys/types.h> X X#ifndef USENAP X#ifdef USEPOLL X#include <sys/poll.h> X#else X#define USETIMES 1 X#include <sys/times.h> X#endif X#endif X Xstatic struct termio orig; X X#ifdef DONTHOG Xstatic char timings[] = { 30, 20, 20, 20, 10, 10 }; X#else Xstatic char timings[] = { 30, 25, 20, 15, 10, 8 }; X#endif Xstatic int currtim; X Xextern int speed; X Xsetuptty() { X struct termio tt; X static int getdone = 0; X X if ( !getdone ) { X ioctl(0,TCGETA,&orig); X getdone = 1; X } X memcpy( (char*)&tt, (char*)&orig, sizeof(orig) ); X tt.c_cc[VMIN] = 0; X tt.c_cc[VTIME] = 1; X ioctl(0,TCSETA,&tt); X} X Xcloseuptty() { X ioctl(0,TCSETA,&orig); X} X Xsetlevel(level) X{ X if ( level >= sizeof(timings) ) X level = sizeof(timings) - 1; X currtim = timings[level]; X} X Xpolluser(buf,sizebuf) Xchar *buf; Xint sizebuf; X{ X static int timeleft = 0; X int nc; X X if ( timeleft <= 0 ) X timeleft = currtim; X if ( timeleft < 10 ) { X wait_ms(timeleft*(speed/10)); X fcntl(0,F_SETFL,O_NDELAY); X nc = read(0,buf,sizebuf); X fcntl(0,F_SETFL,0); X timeleft = 0; X } else { X/* This ifdeffing of USETIMES makes no sense to me, so I've commented it out. -mk */ X/* #ifdef USETIMES X nc = read(0,buf,sizebuf); X#else */ X wait_ms(speed); X fcntl(0,F_SETFL,O_NDELAY); X nc = read(0,buf,sizebuf); X fcntl(0,F_SETFL,0); X/* #endif */ X timeleft -= 10; X } X#ifdef COHERENT X if(nc == -1) nc = 0; /* A kludge...weird that read() sometimes returns -1 for no reason. */ X#endif X if ( timeleft <= 0 ) X buf[nc++] = 0; /* not an eos but the signal to drop */ X return nc; X} X X#ifdef COHERENT Xstatic wait_ms( msecs ) Xint msecs; X{ X struct timeb tmbuf; X time_t untiltime; X unsigned short untilmsecs; X X /* Figure out when we can return */ X ftime(&tmbuf); X untiltime = tmbuf.time + ((long)(msecs / 1000)); X untilmsecs = tmbuf.millitm + (msecs % 1000); X if(untilmsecs > 990) { /* milliseconds rolled over */ X untiltime++; X untilmsecs -= 990; X } X X /* Wait until we can return. Warning, this is a BIG CPU hog. */ X for(;;) { X ftime(&tmbuf); X if((tmbuf.time >= untiltime) && (tmbuf.millitm >= untilmsecs)) X return; X } X} X#else Xstatic wait_ms( msecs ) X{ X#ifdef USETIMES X register time_t etime; X long times(); X struct tms junk; X X etime = times(&junk) + ((HZ * msecs) + 999) / 1000; X while ( times(&junk) <= etime ) X ; X#endif X#ifdef USEPOLL X poll( (struct pollfd *)0, 0L, msecs ); X#endif X#ifdef USENAP X nap( ((HZ * msecs) + 999) / 1000 ) ; X#endif X} X#endif END_OF_polluser.c if test 2542 -ne `wc -c <polluser.c`; then echo shar: \"polluser.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f score.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"score.c\" else echo shar: Extracting \"score.c\" \(5960 characters\) sed "s/^X//" >score.c <<'END_OF_score.c' X#include "defs.h" X#include <curses.h> X#ifndef COHERENT /* Coherent only kinda supports utsname. See further mods below. */ X#include <sys/utsname.h> X#endif X X#define HIGH_SCORE_TABLE "/usr/games/lib/Tetris_scores" X X#define HIGH_TABLE_SIZE 10 X Xstatic struct score_table { X char name[BUFSIZ]; X int score; X int rows; X int level; X char hostname[BUFSIZ]; X char date[BUFSIZ]; X} high_scores[HIGH_TABLE_SIZE]; X Xupdate_highscore_table() X{ X int i, j; X long when; X extern char *ctime(); X extern long time(); X char buf[BUFSIZ]; X#ifndef COHERENT X struct utsname utsname; X#endif X X X /* re-read high-score table in case someone else on the network is X * playing at the same time */ X read_high_scores(); X X /* Next line finds score greater than current one */ X for (i = 0; ((i < HIGH_TABLE_SIZE) && (score >= high_scores[i].score)); i++); X i--; X score_position = i; X if (i >= 0) { X for (j = 0; j < i; j++) X high_scores[j] = high_scores[j + 1]; X strcpy(high_scores[i].name, name); X high_scores[i].score = score; X high_scores[i].rows = rows; X high_scores[i].level = rows / 10; X#ifdef COHERENT X strcpy(high_scores[i].hostname, "coherent"); X#else X if ( uname(&utsname) < 0 ) X strcpy(high_scores[i].hostname, "unknown-host"); X else X strcpy(high_scores[i].hostname, utsname.nodename); X#endif X time(&when); X strcpy(buf, ctime(&when)); /* ctime() adds a newline X * char */ X strip_eoln(buf);/* so remove it */ X strcpy(high_scores[i].date, buf); X write_high_scores(); X } X} X Xread_high_scores() X{ X FILE *fp; X int i; X char buf[BUFSIZ]; X X for (i = 0; i < HIGH_TABLE_SIZE; i++) { X strcpy(high_scores[i].name, " "); X high_scores[i].score = 0; X high_scores[i].rows = 0; X high_scores[i].level = 0; X strcpy(high_scores[i].hostname, " "); X strcpy(high_scores[i].date, " "); X } X if ((fp = fopen(HIGH_SCORE_TABLE, "r")) == NULL) { X fprintf(stderr, "tetris: No High score file\n"); X return; X } X for (i = 0; i < HIGH_TABLE_SIZE; i++) { X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X strcpy(high_scores[i].name, buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X high_scores[i].score = atoi(buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X high_scores[i].rows = atoi(buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X high_scores[i].level = atoi(buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X strcpy(high_scores[i].hostname, buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X strcpy(high_scores[i].date, buf); X } X fclose(fp); X} X Xstrip_eoln(s) X char *s; X{ X char *s1; X X while (*s != '\0') { X if (*s == '\n') { /* End of line char */ X s1 = s; X do { X *s1 = *(s1 + 1); /* Copy rest of string */ X s1++; X } while (*s1 != '\0'); X } else X s++; X } X} X Xwrite_high_scores() X{ X FILE *fp; X int i; X X if ((fp = fopen(HIGH_SCORE_TABLE, "w")) == NULL) { X fprintf(stderr, "tetris: Couldn't open high score file %s\n", HIGH_SCORE_TABLE); X return; X } X for (i = 0; i < HIGH_TABLE_SIZE; i++) X fprintf(fp, "%s\n%d\n%d\n%d\n%s\n%s\n", X high_scores[i].name, X high_scores[i].score, X high_scores[i].rows, X high_scores[i].level, X high_scores[i].hostname, X high_scores[i].date); X fclose(fp); X} X Xvoid print_high_scores() X{ X int i; X char buf[BUFSIZ]; X X /* re-read high-score table in case someone else on the network is X * playing at the same time */ X read_high_scores(); X X clear(); X wtext(10,1,"T e t r i s H i g h e s t r e s u l t s", 0); X X wtext(4,3,"Pos Name Score Rows Lev When", 0); X wtext(4,4,"=== ==== ===== ==== === ====", 0); X for ( i = 0; i < HIGH_TABLE_SIZE; i++ ) { X sprintf(buf, "%3d) %-15s %6d %5d %3d %s\n", X HIGH_TABLE_SIZE - i, X high_scores[i].name, X high_scores[i].score, X high_scores[i].rows, X high_scores[i].level, X high_scores[i].date); X wtext(4,14-i,buf, score_position == i); X } X} X Xprint_authors() X{ X int i; X static char *au[] = { X"\n", X" Tetris Version 1.1\n\n", X"This version of tetris was modified to run on ascii terminals by:\n", X" Roberto Biancardi <..!unido!tmpmbx!deejay!i2ack!usixth!bob>\n", X"Based on the version posted by Phill Everson <everson@cs.bris.ac.uk>\n", X"and Martyn Shortley <shortley@cs.bris.ac.uk>, based on the version posted\n", X"to comp.sources.games by Adam Marguilies <vespa@ssyx.ucsc.edu>\n", X"\n", X"Wed Jun 21 22:35:52 ITA 1989\n\n", X"Modified to run under Coherent and -g (game speed) option added by\n", X"Matt Kimmel <kimmel@umvlsi.ecs.umass.edu> 6/1/91\n", XNULL X}; X X for ( i=0; au[i] != NULL; i++ ) X write(1,au[i],strlen(au[i])); X sleep(2); X} END_OF_score.c if test 5960 -ne `wc -c <score.c`; then echo shar: \"score.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f shape.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"shape.c\" else echo shar: Extracting \"shape.c\" \(7330 characters\) sed "s/^X//" >shape.c <<'END_OF_shape.c' X#include "defs.h" X Xvoid define_shapes() X{ X X /* begin shape 0 definition, four rotations */ X X shape[0].table[0][0] = 0; X shape[0].table[1][0] = 15; /* #### */ X shape[0].table[2][0] = 0; X shape[0].table[3][0] = 0; X shape[0].pointv[0] = 5; X X shape[0].table[0][1] = 4; /* # */ X shape[0].table[1][1] = 4; /* # */ X shape[0].table[2][1] = 4; /* # */ X shape[0].table[3][1] = 4; /* # */ X shape[0].pointv[1] = 8; X X shape[0].table[0][2] = 0; X shape[0].table[1][2] = 15; /* #### */ X shape[0].table[2][2] = 0; X shape[0].table[3][2] = 0; X shape[0].pointv[2] = 5; X X shape[0].table[0][3] = 4; /* # */ X shape[0].table[1][3] = 4; /* # */ X shape[0].table[2][3] = 4; /* # */ X shape[0].table[3][3] = 4; /* # */ X shape[0].pointv[2] = 8; X X shape[0].width = 4; X shape[0].height = 1; X shape[0].offset = 153; X shape[0].color = RED; X X /* begin shape 1 definition, four rotations */ X X shape[1].table[0][0] = 12; /* ## */ X shape[1].table[1][0] = 12; /* ## */ X shape[1].table[2][0] = 0; /* */ X shape[1].table[3][0] = 0; /* */ X shape[1].pointv[0] = 6; X X shape[1].table[0][1] = 12; /* ## */ X shape[1].table[1][1] = 12; /* ## */ X shape[1].table[2][1] = 0; /* */ X shape[1].table[3][1] = 0; /* */ X shape[1].pointv[1] = 6; X X shape[1].table[0][2] = 12; /* ## */ X shape[1].table[1][2] = 12; /* ## */ X shape[1].table[2][2] = 0; /* */ X shape[1].table[3][2] = 0; /* */ X shape[1].pointv[2] = 6; X X shape[1].table[0][3] = 12; /* ## */ X shape[1].table[1][3] = 12; /* ## */ X shape[1].table[2][3] = 0; /* */ X shape[1].table[3][3] = 0; /* */ X shape[1].pointv[3] = 6; X X shape[1].width = 2; X shape[1].height = 2; X shape[1].offset = 0; X shape[1].color = ORANGE; X X /* begin shape 2 definition, four rotations */ X X shape[2].table[0][0] = 4; /* # */ X shape[2].table[1][0] = 14; /* ### */ X shape[2].table[2][0] = 0; /* */ X shape[2].table[3][0] = 0; /* */ X shape[2].pointv[0] = 5; X X shape[2].table[0][1] = 4; /* # */ X shape[2].table[1][1] = 6; /* ## */ X shape[2].table[2][1] = 4; /* # */ X shape[2].table[3][1] = 0; /* */ X shape[2].pointv[0] = 5; X X shape[2].table[0][2] = 0; /* */ X shape[2].table[1][2] = 14; /* ### */ X shape[2].table[2][2] = 4; /* # */ X shape[2].table[3][2] = 0; /* */ X shape[2].pointv[2] = 6; X X shape[2].table[0][3] = 4; /* # */ X shape[2].table[1][3] = 12; /* ## */ X shape[2].table[2][3] = 4; /* # */ X shape[2].table[3][3] = 0; /* */ X shape[2].pointv[3] = 5; X X shape[2].width = 3; X shape[2].height = 2; X shape[2].offset = 24; X shape[2].color = YELLOW; X X /* begin shape 3 definition, four rotations */ X X shape[3].table[0][0] = 12; /* ## */ X shape[3].table[1][0] = 6; /* ## */ X shape[3].table[2][0] = 0; /* */ X shape[3].table[3][0] = 0; /* */ X shape[3].pointv[0] = 6; X X shape[3].table[0][1] = 4; /* # */ X shape[3].table[1][1] = 12; /* ## */ X shape[3].table[2][1] = 8; /* # */ X shape[3].table[3][1] = 0; /* */ X shape[3].pointv[1] = 7; X X shape[3].table[0][2] = 12; /* ## */ X shape[3].table[1][2] = 6; /* ## */ X shape[3].table[2][2] = 0; /* */ X shape[3].table[3][2] = 0; /* */ X shape[3].pointv[2] = 6; X X shape[3].table[0][3] = 4; /* # */ X shape[3].table[1][3] = 12; /* ## */ X shape[3].table[2][3] = 8; /* # */ X shape[3].table[3][3] = 0; /* */ X shape[3].pointv[3] = 7; X X shape[3].width = 3; X shape[3].height = 2; X shape[3].offset = 0; X shape[3].color = GREEN; X X /* begin shape 4 definition, four rotations */ X X shape[4].table[0][0] = 6; /* ## */ X shape[4].table[1][0] = 12; /* ## */ X shape[4].table[2][0] = 0; /* */ X shape[4].table[3][0] = 0; /* */ X shape[4].pointv[0] = 6; X X shape[4].table[0][1] = 8; /* # */ X shape[4].table[1][1] = 12; /* ## */ X shape[4].table[2][1] = 4; /* # */ X shape[4].table[3][1] = 0; /* */ X shape[4].pointv[1] = 7; X X shape[4].table[0][2] = 6; /* ## */ X shape[4].table[1][2] = 12; /* ## */ X shape[4].table[2][2] = 0; /* */ X shape[4].table[3][2] = 0; /* */ X shape[4].pointv[2] = 6; X X shape[4].table[0][3] = 8; /* # */ X shape[4].table[1][3] = 12; /* ## */ X shape[4].table[2][3] = 4; /* # */ X shape[4].table[3][3] = 0; /* */ X shape[4].pointv[3] = 7; X X shape[4].width = 3; X shape[4].height = 2; X shape[4].offset = 0; X shape[4].color = BLUE; X X /* begin shape 5 definition, four rotations */ X X shape[5].table[0][0] = 2; /* # */ X shape[5].table[1][0] = 14; /* ### */ X shape[5].table[2][0] = 0; /* */ X shape[5].table[3][0] = 0; /* */ X shape[5].pointv[0] = 6; X X shape[5].table[0][1] = 8; /* # */ X shape[5].table[1][1] = 8; /* # */ X shape[5].table[2][1] = 12; /* ## */ X shape[5].table[3][1] = 0; /* */ X shape[5].pointv[1] = 7; X X shape[5].table[0][2] = 14; /* ### */ X shape[5].table[1][2] = 8; /* # */ X shape[5].table[2][2] = 0; /* */ X shape[5].table[3][2] = 0; /* */ X shape[5].pointv[2] = 6; X X shape[5].table[0][3] = 12; /* ## */ X shape[5].table[1][3] = 4; /* # */ X shape[5].table[2][3] = 4; /* # */ X shape[5].table[3][3] = 0; /* */ X shape[5].pointv[3] = 7; X X shape[5].width = 3; X shape[5].height = 2; X shape[5].offset = 0; X shape[5].color = CYAN; X X /* begin shape 6 definition, four rotations */ X X shape[6].table[0][0] = 14; /* ### */ X shape[6].table[1][0] = 2; /* # */ X shape[6].table[2][0] = 0; /* */ X shape[6].table[3][0] = 0; /* */ X shape[6].pointv[0] = 6; X X shape[6].table[0][1] = 4; /* # */ X shape[6].table[1][1] = 4; /* # */ X shape[6].table[2][1] = 12; /* ## */ X shape[6].table[3][1] = 0; /* */ X shape[6].pointv[1] = 7; X X shape[6].table[0][2] = 8; /* # */ X shape[6].table[1][2] = 14; /* ### */ X shape[6].table[2][2] = 0; /* */ X shape[6].table[3][2] = 0; /* */ X shape[6].pointv[2] = 6; X X shape[6].table[0][3] = 12; /* ## */ X shape[6].table[1][3] = 8; /* # */ X shape[6].table[2][3] = 8; /* # */ X shape[6].table[3][3] = 0; /* */ X shape[6].pointv[3] = 7; X X shape[6].width = 3; X shape[6].height = 2; X shape[6].offset = 0; X shape[6].color = VIOLET; X} X Xstore_shape(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int i; X X for (i = 0; i < 4; i++) { X if (shape[shape_no].table[i][rot] & 8) X grid[xpos][ypos + i] = 1; X if (shape[shape_no].table[i][rot] & 4) X grid[xpos + 1][ypos + i] = 1; X if (shape[shape_no].table[i][rot] & 2) X grid[xpos + 2][ypos + i] = 1; X if (shape[shape_no].table[i][rot] & 1) X grid[xpos + 3][ypos + i] = 1; X } X} X Xcreate_shape() X{ X shape_no = next_no; X rot = next_rot; X next_no = rand() % 7; X next_rot = rand() % 4; X xpos = (UWIDTH / 2) - 1; X ypos = -4; X} X END_OF_shape.c if test 7330 -ne `wc -c <shape.c`; then echo shar: \"shape.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f support.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"support.c\" else echo shar: Extracting \"support.c\" \(6362 characters\) sed "s/^X//" >support.c <<'END_OF_support.c' X#include "defs.h" X Xblock_can_drop(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int y1, c; X X c = 3; X X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 8) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos][y1] != 0)) X return (0); X X c = 3; X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 4) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos + 1][y1] != 0)) X return (0); X X c = 3; X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 2) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos + 2][y1] != 0)) X return (0); X X c = 3; X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 1) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos + 3][y1] != 0)) X return (0); X X return 1; X} X Xblock_can_left(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int x1, c; X int y0, y1, y2, y3; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X y0 = ypos; X y1 = ypos + 1; X y2 = ypos + 2; X y3 = ypos + 3; X X c = 3; X while ((c >= 0) && ((t0 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y0 >= 0) && (grid[x1][y0] != 0))) X return (0); X X c = 3; X while ((c >= 0) && ((t1 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y1 >= 0) && (grid[x1][y1] != 0))) X return (0); X X c = 3; X while ((c >= 0) && ((t2 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y2 >= 0) && (grid[x1][y2] != 0))) X return (0); X X c = 3; X while ((c >= 0) && ((t3 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y3 >= 0) && (grid[x1][y3] != 0))) X return (0); X X return 1; X} X Xblock_can_right(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int x1, c; X int y0, y1, y2, y3; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X y0 = ypos; X y1 = ypos + 1; X y2 = ypos + 2; X y3 = ypos + 3; X X c = 0; X while ((c < 4) && ((t0 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y0 >= 0) && (grid[x1][y0] != 0))) X return (0); X X c = 0; X while ((c < 4) && ((t1 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y1 >= 0) && (grid[x1][y1] != 0))) X return (0); X X c = 0; X while ((c < 4) && ((t2 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y2 >= 0) && (grid[x1][y2] != 0))) X return (0); X X c = 0; X while ((c < 4) && ((t3 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y3 >= 0) && (grid[x1][y3] != 0))) X return (0); X X return 1; X} X Xremove_full_lines(y) X int y; X{ X int y1, y2, x; X X for (y1 = y; y1 < y + 4 && y1 < UHEIGHT; y1++) { X for (x = 0; x < UWIDTH; x++) X if (grid[x][y1] == 0) X break; X if ( x == UWIDTH ) { X for (y2 = y1; y2 > 0; y2--) X for (x = 0; x < UWIDTH; x++) X grid[x][y2] = grid[x][y2 - 1]; X for (x = 0; x < UWIDTH; x++) X grid[x][0] = 0; X scdelete(y1); X scinsert(0); X rows++; X } X } X} X Xcheck_rot(shape_no, xpos, ypos, newrot) X int shape_no, xpos, ypos, newrot; X{ X int i; X int ti; /* Bit map of i'th row */ X int yi; /* Y position on i'th row */ X int x0, x1, x2, x3; X X x0 = xpos; X x1 = xpos + 1; X x2 = xpos + 2; X x3 = xpos + 3; X yi = ypos; X X for (i = 0; i < 4; yi++, i++) { X if ((yi) >= 0) { X ti = shape[shape_no].table[i][newrot]; X if (ti & 8) X if ((x0 < 0) || (x0 >= UWIDTH) || (grid[x0][yi] == 1)) X return 0; X if (ti & 4) X if ((x1 < 0) || (x1 >= UWIDTH) || (grid[x1][yi] == 1)) X return 0; X if (ti & 2) X if ((x2 < 0) || (x2 >= UWIDTH) || (grid[x2][yi] == 1)) X return 0; X if (ti & 1) X if ((x3 < 0) || (x3 >= UWIDTH) || (grid[x3][yi] == 1)) X return 0; X } X } X return 1; X} END_OF_support.c if test 6362 -ne `wc -c <support.c`; then echo shar: \"support.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f tetris.6 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"tetris.6\" else echo shar: Extracting \"tetris.6\" \(1750 characters\) sed "s/^X//" >tetris.6 <<'END_OF_tetris.6' X.TH TETRIS 6 "Jun 21 ITA 1989" X.SH NAME Xtetris \- block dropping game X.SH SYNOPSIS X.B tetris X[ X.B \-s X] X[ X.B \-l<level> X] X[ X.B \-b<blochar> X] X.SH DESCRIPTION X.I Tetris Xis a game involving dropping blocks. As they drop you can move them to Xthe left or to the right using '7' and '9' respectively. X XPressing the '8' key causes the falling shape to rotate anti-clockwise. XPressing the space bar causes the shape to quickly drop. X XPressing the '*' key causes the shape to rotate Xclockwise. XPressing the 'q' or 'Q' key causes Tetris to exit immediately. X.PP XPoints are scored for each block that comes to rest on the gradually Xbuilding up pile of blocks. Different blocks in different orientations Xhave different point values. When the pile reaches the top of the Xscreen and no further blocks can be dropped the game ends. Whenever a Xfull row of blocks across the screen is all completely filled in that Xrow is removed and all the blocks above it drop down a further row. XAs more rows are deleted the blocks drop faster. X.PP XA high score table is kept which is retained between separate executions Xof the game. X.SH OPTIONS X.I Tetris Xtakes the X.B \-s Xoption to suppress the sound beep which may be executed Xslowly on strange videoterminal thus causing blocks to stop for Xa while. X XThe X.B \-l<level> Xoption will make Tetris start each game at level <level>. X X.B \-b<blochar> Xis to change the character used to draw blocks. Use X.B \-b# Xif your tty does not support inverse video. X XThe X.B \-g<speed> Xoption allows you to set Tetris' overall speed. It is Xmeasured in milliseconds between iterations of Tetris' Xmain loop, so you may need to experiment with it. The Xdefault speed is 200 msecs. X X.SH FILES X.PP X/usr/games/lib/Tetris_scores : Top 10 high scores. END_OF_tetris.6 if test 1750 -ne `wc -c <tetris.6`; then echo shar: \"tetris.6\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0 -- Matt Kimmel University of Massachusetts Amherst, Mass. Internet: kimmel@umvlsi.ecs.umass.edu Bitnet: KIMMEL@UMAECS