|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T i
Length: 6572 (0x19ac)
Types: TextFile
Names: »init_tetris.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Tetris/init_tetris.c«
/*
** written by adam margulies vespa@ssyx.ucsc.edu
** {...}!ucbvax!ucscc!ssyx!vespa
**
** permission is granted to freely distribute this code provided that you:
**
** 1) don't charge for it
** 2) leave my name and header on it
** 3) clearly document your changes and place your name on them
**
*/
/* Tetris: init_tetris.c */
/* */
/* this is one of the first functions called. It gets user info, */
/* seeds the random number generator, draws the screen, and sets the */
/* interrupt timer. */
#include "tetris.h"
void init_tetris()
{
FILE *fp;
struct passwd *getpwuid();
int i,j,c,counter;
long ctime;
void get_level(), define_shapes(), cursive(), drop_block(), intr_hand();
void cont_hand(), save_game();
char *getenv(), line[15], file[80];
struct stat buf;
int fd;
struct utmp entry;
struct passwd *pwd;
points = 0;
lines = 0;
define_shapes();
cls();
signal(SIGCONT, cont_hand); /* cont trap */
signal(SIGHUP, save_game); /* sighup trap */
user_info = getpwuid(getuid());
current = (struct shape *)malloc(sizeof(struct shape));
next = (struct shape *)malloc(sizeof(struct shape));
key = (struct keystr *)malloc(sizeof(struct keystr));
ttystat = (struct stat *)malloc(sizeof(struct stat));
/*construct the save file name*/
if(getenv("HOME") != NULL) {
strcpy(rcd_file, getenv("HOME"));
strcat(rcd_file, "/tetris.save");
} else {
strcpy(rcd_file, user_info->pw_dir);
strcat(rcd_file, "/tetris.save");
}
srandom(getpid());
/* read in file perms on user's tty and then determine if writable */
stat(ttyname(0), ttystat);
ttystat->st_mode &= 511;
if(ttystat->st_mode & 16)
nowrite |= 2;
if(keystr[0] == '\0')
strcpy(keystr, "hljk nb");
key->left = keystr[0];
key->right = keystr[1];
key->rotleft = keystr[2];
key->rotright = keystr[3];
key->drop = keystr[4];
key->togdisp = keystr[5];
key->togshad = keystr[6];
mvaddstr(01,34,"+----------+");
mvaddstr(22,34,"+----------+");
for (i=0; i < 20; i++)
mvaddstr(i+2,34,"| |");
/* restore the game if necessary */
if (access(rcd_file, R_OK) == 0 ) {
stat(rcd_file, &buf);
if ((fp = fopen(rcd_file, "r")) == NULL){
SIGHOLD(14);
cls();
csr(23,0);
resetty();
fprintf(stderr, "%s\n", rcd_file);
perror("opening save file");
exit(3);
}
for (i=0; i < 20; i++)
for (j=0; j < 10; j++) {
while((c = fgetc(fp)) == '\n');
window1[i+2][j+35] = c;
}
fscanf(fp, "%ld\n", &ctime);
if (ctime + 3 < buf.st_ctime) {
csr(23,0);
resetty();
printf("Panic!\n");
unlink(rcd_file);
exit(1);
}
fscanf(fp, "%d\n", &version);
if(version != VERSION) {
csr(23,0);
resetty();
printf("Sorry your save file is out of date.\n");
unlink(rcd_file);
exit(1);
}
fscanf(fp, "%d\n%d\n%d\n", &points, &level, &lines);
fscanf(fp, "%d\n", &disp_next);
fscanf(fp, "%d\n", &shadow);
fscanf(fp, "%d\n", &disp_tomb);
fscanf(fp, "%d\n", &disp_high);
fscanf(fp, "%d\n%d\n", &cury, &curx);
fscanf(fp, "%d\n%d\n", ¤t->shape, ¤t->rot);
fscanf(fp, "%d\n", ¤t->was_shown);
fscanf(fp, "%d\n", ¤t->was_shadowed);
fscanf(fp, "%d\n%d\n", &next->shape, &next->rot);
fscanf(fp, "%d\n", &next->was_shown);
fscanf(fp, "%d\n", &next->was_shadowed);
fscanf(fp, "%d\n", &addict);
key->right = fgetc(fp);
fgetc(fp);
key->left = fgetc(fp);
fgetc(fp);
key->rotright = fgetc(fp);
fgetc(fp);
key->rotleft = fgetc(fp);
fgetc(fp);
key->drop = fgetc(fp);
fgetc(fp);
key->togdisp = fgetc(fp);
fgetc(fp);
key->togshad = fgetc(fp);
fgetc(fp);
if (current->rot == 0 || current->rot == 2) {
current->width = shape[current->shape].width;
current->height = shape[current->shape].height;
}
if (current->rot == 1 || current->rot == 3) {
current->width = shape[current->shape].height;
current->height = shape[current->shape].width;
}
current->color = shape[current->shape].color;
current->offset = shape[current->shape].offset;
current->pointv = shape[current->shape].pointv[current->rot];
next->color = shape[next->shape].color;
next->offset = shape[next->shape].offset;
next->pointv = shape[next->shape].pointv[next->rot];
}
csr_draw(1,34,22,46);
cursive();
move(3,20);
printc("%2.2f", (VERSION/10.0));
csr_draw(3,20,3,22);
if (access(rcd_file, R_OK) != 0 ) {
next->shape = random() % 7;
next->rot = random() % 4;
next->color = '0';
next->pointv = shape[next->shape].pointv[next->rot];
}
if (next->rot == 0 || next->rot == 2) {
next->width = shape[next->shape].width;
next->height = shape[next->shape].height;
}
if (next->rot == 1 || next->rot == 3) {
next->width = shape[next->shape].height;
next->height = shape[next->shape].width;
}
next->offset = shape[next->shape].offset;
if (access(rcd_file, R_OK) != 0 ) {
if(disp_open && level == 0 && rubble == 0)
get_level();
make_rubble();
csr_draw(5,19,21,62);
setup_next();
}
else if (disp_next)
print_shape(next->shape, 17, 6, next->rot, next->color);
if (access(rcd_file, R_OK) == 0 && shadow == 1 )
draw_shadow();
move(6,5);
printc("next block:");
csr_draw(6,5,6,16);
move(0,65);
printc("score: %7.7d", points);
move(1,65);
printc("lines: %3.3d", lines);
move(2,65);
printc("level: %2.2d", level);
csr_draw(0,65,2,79);
move(22,60);
printc("last mod: %s", LASTDATE);
csr_draw(22,60,22,78);
if ((fp = fopen(HIGHSCOREFILE, "r")) == NULL){
SIGHOLD(14);
cls();
csr(23,0);
resetty();
fprintf(stderr, "%s\n", HIGHSCOREFILE);
perror("opening highscore file");
exit(3);
}
for(counter=0;counter<10;counter++){
fscanf(fp, "%d\n", &high_score[counter]);
fscanf(fp, "%255s\n", high_user[counter]);
fgets(high_name[counter], 255, fp);
move(10+counter,0);
printc("%2.2d. %7.7d (%s) ", counter+1, high_score[counter],
high_user[counter]);
}
fclose(fp);
csr_draw(10,0,20,30);
move(22,0);
printc("? for help");
csr_draw(22,0,22,10);
bzero(&timer, sizeof(timer));
bzero(&otimer, sizeof(otimer));
timer.it_interval.tv_usec = 500000;
timer.it_value.tv_usec = 500000;
setitimer(ITIMER_REAL, &timer, 0);
signal(SIGALRM, drop_block);
set_level();
}