|
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 m
Length: 2507 (0x9cb) Types: TextFile Names: »main.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Yahtzee/main.c«
#include "types.h" #include <sys/time.h> #include <signal.h> Game player[4]; char DELETE1, DELETE2; int select = 0; main() { int np, clean(); seedrand(); initscr(); initkey(&DELETE1, &DELETE2); signal(SIGINT, clean); crmode(); noecho(); nonl(); np = getnames(); while(1) { init(np); if(playgame(np) == 0) break; move(23,0); clrtoeol(); addstr("Same Players? (Y/N) "); refresh(); if(yes(23,21)) continue; else np = getnames(); } clean(); } clean() { clear(); refresh(); endwin(); endkey(); exit(0); } yes(y,x) int y,x; { char s[2]; while(1) { getstring(s,1,0, y,x); s[0] |= 040; if(s[0] == 'y') return(1); else if(s[0] == 'n') return(0); else { DisplayBeep(0); mvaddstr(y,x+1," "); move(y,x+1); refresh(); } } } init(n) int n; { int i,j; for(i=0; i<n; i++) for(j=0; j<NS; j++) player[i].score[j] = -1; player[i].ycount = 0; } playgame(n) int n; { int which = 0, old = 0, i, j; drawscreen(n); while(gameon(n)) { select = 1; setname(old,which); roll(); for(i=0; i<2; i++) { if(choose()) break; roll(); } clrroll(); makechoice(which); old = which; if(++which == n) which=0; select = 0; } return(winner(n)); } gameon(n) { int i,j; for(i=0; i<n; i++) for(j=0; j<NS; j++) { if(j == 6) continue; if(player[i].score[j] == -1) return(1); } return(0); } getnames() { int n,i; char s[7]; clear(); mvaddstr(0,0,"How many players: "); refresh(); while(1) { move(0,18); clrtoeol(); refresh(); getstring(s,1,1,0,18); if((n=atoi(s)) >= 1 && n <= 4) break; DisplayBeep(0); } for(i=0; i<n; i++) { mvaddstr(i+1,0,"Enter name: "); refresh(); move(i+1,12); clrtoeol(); getstring(s, 6, 0, i+1, 12); strcpy(player[i].name, s); } return(n); } getstring(s,n,flag,y,x) char *s; int n,flag,y,x; { int c,i=0; while(1) { c = key(); if(c < 0 && c!=LF_ARROW) DisplayBeep(0); else if(c == 8 || c == LF_ARROW) { if(i == 0) DisplayBeep(0); else { s[--i] = 0; addch(8); addch(' '); addch(8); refresh(); x--; } } else if(c == '\r') { s[i]=0; return; } else { if(i < n) { if(flag) { if(c<'0' || c>'9') { DisplayBeep(0); continue; } } s[i++] = c; x++; addch(c); refresh(); } else DisplayBeep(0); } } } seedrand() { struct timeval tp; struct timezone tpz; gettimeofday(&tp,&tpz); srandom((int)tp.tv_sec); } get_rand() { long random(); return( (int) random() % 6 + 1); }