int inputoption(void) { ++Player.p_age; /* increase age */ if (Player.p_ring.ring_type != R_SPOILED) /* ring ok */ return (getanswer("T ", TRUE)); else /* bad ring */ { getanswer(" ", TRUE); return ((int) ROLL(0.0, 5.0) + '0'); } }
long recallplayer(void) { long loc = 0L; /* location in player file */ int loop; /* loop counter */ int ch; /* input */ clear(); mvprintw(10, 0, "What was your character's name ? "); getstring(Databuf, SZ_NAME); truncstring(Databuf); if ((loc = findname(Databuf, &Player)) >= 0L) /* found character */ { Echo = FALSE; for (loop = 0; loop < 2; ++loop) { /* prompt for password */ mvaddstr(11, 0, "Password ? "); getstring(Databuf, SZ_PASSWORD); if (strcmp(Databuf, Player.p_password) == 0) /* password good */ { Echo = TRUE; if (Player.p_status != S_OFF) /* player did not exit normally last * time */ { clear(); addstr("Your character did not exit normally last time.\n"); addstr("If you think you have good cause to have your character saved,\n"); printw("you may quit and mail your reason to 'root'.\n"); addstr("Otherwise, continuing spells certain death.\n"); addstr("Do you want to quit ? "); ch = getanswer("YN", FALSE); if (ch == 'Y') { Player.p_status = S_HUNGUP; writerecord(&Player, loc); cleanup(TRUE); } death("Stupidity"); } return (loc); } else mvaddstr(12, 0, "No good.\n"); } Echo = TRUE; } else mvaddstr(11, 0, "Not found.\n"); more(13); return (-1L); }
void interrupt(void) { char line[81]; /* a place to store data already on screen */ int loop; /* counter */ int x, y; /* coordinates on screen */ int ch; /* input */ unsigned savealarm; /* to save alarm value */ savealarm = alarm(0); /* turn off any alarms */ getyx(stdscr, y, x); /* save cursor location */ for (loop = 0; loop < 80; ++loop) { /* save line on screen */ move(4, loop); line[loop] = inch(); } line[80] = '\0'; /* nul terminate */ if (Player.p_status == S_INBATTLE || Player.p_status == S_MONSTER) /* in midst of fighting */ { mvaddstr(4, 0, "Quitting now will automatically kill your character. Still want to ? "); ch = getanswer("NY", FALSE); if (ch == 'Y') death("Bailing out"); } else { mvaddstr(4, 0, "Do you really want to quit ? "); ch = getanswer("NY", FALSE); if (ch == 'Y') leavegame(); } mvaddstr(4, 0, line); /* restore data on screen */ move(y, x); /* restore cursor */ refresh(); alarm(savealarm); /* restore alarm */ }
int main(int argc, char ** argv) { int answer = getanswer(); double fraca = signedfrac(3.2); double fracb = signedfrac(-2.3); printf("answer should be 42; was %d\n", answer); printf("signedfrac 3.2 should yield 0.2; was %f\n", fraca); printf("signedfrac -2.3 should yield -0.3; was %f\n", fracb); return 0; }
int main(){ int flag, num, i = 0, j = 0; scanf("%d", &num); getchar(); char str[num][256]; while(num > 0){ fgets(str[i], 256, stdin); i++; num--; } for(j=0; j<i; j++){ printf("Problem #%d\n", j+1); flag = getanswer(str[j]); printanswer(flag); } return 0; }
/* Loop over lines, reading in answers from stdin */ static void create_code(void) { struct answer **cur_line; int page_num=1; for (cur_line = lines; *cur_line; cur_line++) { struct answer *cur_question; for (cur_question = *cur_line; cur_question->answer; cur_question++, page_num++) { const char *aux_string=NULL; if (cur_question->dependant) { const struct elem *aux = xgetcontent(cur_question-1, "function: %s; line %d\n", __func__, __LINE__); aux_string = aux->alias; } cur_question->answer = getanswer(cur_question->name, page_num, cur_question->contents, aux_string); } } }
void more(int where) { mvaddstr(where, 0, "-- more --"); getanswer(" ", FALSE); }
void changestats(bool ingameflag) { static char flag[2] = /* for printing values of bools */ { 'F', 'T' }; struct player *playerp; /* pointer to structure to alter */ const char *prompt; /* pointer to prompt string */ int c; /* input */ int today; /* day of year of today */ int temp; /* temporary variable */ long loc; /* location in player file */ time_t now; /* time now */ double dtemp; /* temporary variable */ bool *bptr; /* pointer to bool item to change */ double *dptr; /* pointer to double item to change */ short *sptr; /* pointer to short item to change */ clear(); for (;;) { /* get name of player to examine/alter */ mvaddstr(5, 0, "Which character do you want to look at ? "); getstring(Databuf, SZ_DATABUF); truncstring(Databuf); if (Databuf[0] == '\0') userlist(ingameflag); else break; } loc = -1L; if (!ingameflag) /* use 'Player' structure */ playerp = &Player; else if (strcmp(Databuf, Player.p_name) == 0) { /* alter/examine current player */ playerp = &Player; loc = Fileloc; } else /* use 'Other' structure */ playerp = &Other; /* find player on file */ if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L) { /* didn't find player */ clear(); mvaddstr(11, 0, "Not found."); return; } time(&now); today = localtime(&now)->tm_yday; clear(); for (;;) { /* print player structure, and prompt for action */ mvprintw(0, 0, "A:Name %s\n", playerp->p_name); if (Wizard) printw("B:Password %s\n", playerp->p_password); else addstr("B:Password XXXXXXXX\n"); printw(" :Login %s\n", playerp->p_login); printw("C:Experience %.0f\n", playerp->p_experience); printw("D:Level %.0f\n", playerp->p_level); printw("E:Strength %.0f\n", playerp->p_strength); printw("F:Sword %.0f\n", playerp->p_sword); printw(" :Might %.0f\n", playerp->p_might); printw("G:Energy %.0f\n", playerp->p_energy); printw("H:Max-Energy %.0f\n", playerp->p_maxenergy); printw("I:Shield %.0f\n", playerp->p_shield); printw("J:Quickness %.0f\n", playerp->p_quickness); printw("K:Quicksilver %.0f\n", playerp->p_quksilver); printw(" :Speed %.0f\n", playerp->p_speed); printw("L:Magic Level %.0f\n", playerp->p_magiclvl); printw("M:Mana %.0f\n", playerp->p_mana); printw("N:Brains %.0f\n", playerp->p_brains); if (Wizard || playerp->p_specialtype != SC_VALAR) mvaddstr(0, 40, descrstatus(playerp)); mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison); mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold); mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems); mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin); if (Wizard) { mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x); mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y); } else { mvaddstr(5, 40, "S:X-coord ?\n"); mvaddstr(6, 40, "T:Y-coord ?\n"); } mvprintw(7, 40, "U:Age %ld\n", playerp->p_age); mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated); mvprintw(9, 40, "W:Type %d (%s)\n", playerp->p_type, descrtype(playerp, FALSE) + 1); mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype); mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives); mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns); mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms); mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets); mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater); temp = today - playerp->p_lastused; if (temp < 0) /* last year */ temp += 365; mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp); mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c", flag[playerp->p_palantir], flag[playerp->p_blessing], flag[playerp->p_virgin], flag[playerp->p_blindness]); if (!Wizard) mvprintw(19, 8, "8:Ring %c", flag[playerp->p_ring.ring_type != R_NONE]); else mvprintw(19, 8, "8:Ring %d 9:Duration %d", playerp->p_ring.ring_type, playerp->p_ring.ring_duration); if (!Wizard && (ingameflag || strcmp(Login, playerp->p_login) != 0)) { /* in game or not examining own character */ if (ingameflag) { more(LINES - 1); clear(); return; } else cleanup(TRUE); /* NOTREACHED */ } mvaddstr(20, 0, "!:Quit ?:Delete"); mvaddstr(21, 0, "What would you like to change ? "); if (Wizard) c = getanswer(" ", TRUE); else /* examining own player; allow to change name and password */ c = getanswer("!BA", FALSE); switch (c) { case 'A': /* change name */ case 'B': /* change password */ if (!Wizard) { /* prompt for password */ mvaddstr(23, 0, "Password ? "); Echo = FALSE; getstring(Databuf, 9); Echo = TRUE; if (strcmp(Databuf, playerp->p_password) != 0) continue; } if (c == 'A') { /* get new name */ mvaddstr(23, 0, "New name: "); getstring(Databuf, SZ_NAME); truncstring(Databuf); if (Databuf[0] != '\0') if (Wizard || findname(Databuf, &Other) < 0L) strcpy(playerp->p_name, Databuf); } else { /* get new password */ if (!Wizard) Echo = FALSE; do { /* get two copies of new password until they match */ /* get first copy */ mvaddstr(23, 0, "New password ? "); getstring(Databuf, SZ_PASSWORD); if (Databuf[0] == '\0') break; /* get second copy */ mvaddstr(23, 0, "One more time ? "); getstring(playerp->p_password, SZ_PASSWORD); } while (strcmp(playerp->p_password, Databuf) != 0); Echo = TRUE; } continue; case 'C': /* change experience */ prompt = "experience"; dptr = &playerp->p_experience; goto DALTER; case 'D': /* change level */ prompt = "level"; dptr = &playerp->p_level; goto DALTER; case 'E': /* change strength */ prompt = "strength"; dptr = &playerp->p_strength; goto DALTER; case 'F': /* change swords */ prompt = "sword"; dptr = &playerp->p_sword; goto DALTER; case 'G': /* change energy */ prompt = "energy"; dptr = &playerp->p_energy; goto DALTER; case 'H': /* change maximum energy */ prompt = "max energy"; dptr = &playerp->p_maxenergy; goto DALTER; case 'I': /* change shields */ prompt = "shield"; dptr = &playerp->p_shield; goto DALTER; case 'J': /* change quickness */ prompt = "quickness"; dptr = &playerp->p_quickness; goto DALTER; case 'K': /* change quicksilver */ prompt = "quicksilver"; dptr = &playerp->p_quksilver; goto DALTER; case 'L': /* change magic */ prompt = "magic level"; dptr = &playerp->p_magiclvl; goto DALTER; case 'M': /* change mana */ prompt = "mana"; dptr = &playerp->p_mana; goto DALTER; case 'N': /* change brains */ prompt = "brains"; dptr = &playerp->p_brains; goto DALTER; case 'O': /* change poison */ prompt = "poison"; dptr = &playerp->p_poison; goto DALTER; case 'P': /* change gold */ prompt = "gold"; dptr = &playerp->p_gold; goto DALTER; case 'Q': /* change gems */ prompt = "gems"; dptr = &playerp->p_gems; goto DALTER; case 'R': /* change sin */ prompt = "sin"; dptr = &playerp->p_sin; goto DALTER; case 'S': /* change x coord */ prompt = "x"; dptr = &playerp->p_x; goto DALTER; case 'T': /* change y coord */ prompt = "y"; dptr = &playerp->p_y; goto DALTER; case 'U': /* change age */ mvprintw(23, 0, "age = %ld; age = ", playerp->p_age); dtemp = infloat(); if (dtemp != 0.0) playerp->p_age = (long)dtemp; continue; case 'V': /* change degen */ mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated); dtemp = infloat(); if (dtemp != 0.0) playerp->p_degenerated = (int)dtemp; continue; case 'W': /* change type */ prompt = "type"; sptr = &playerp->p_type; goto SALTER; case 'X': /* change special type */ prompt = "special type"; sptr = &playerp->p_specialtype; goto SALTER; case 'Y': /* change lives */ prompt = "lives"; sptr = &playerp->p_lives; goto SALTER; case 'Z': /* change crowns */ prompt = "crowns"; sptr = &playerp->p_crowns; goto SALTER; case '0': /* change charms */ prompt = "charm"; sptr = &playerp->p_charms; goto SALTER; case '1': /* change amulet */ prompt = "amulet"; sptr = &playerp->p_amulets; goto SALTER; case '2': /* change holy water */ prompt = "holy water"; sptr = &playerp->p_holywater; goto SALTER; case '3': /* change last-used */ prompt = "last-used"; sptr = &playerp->p_lastused; goto SALTER; case '4': /* change palantir */ prompt = "palantir"; bptr = &playerp->p_palantir; goto BALTER; case '5': /* change blessing */ prompt = "blessing"; bptr = &playerp->p_blessing; goto BALTER; case '6': /* change virgin */ prompt = "virgin"; bptr = &playerp->p_virgin; goto BALTER; case '7': /* change blindness */ prompt = "blindness"; bptr = &playerp->p_blindness; goto BALTER; case '8': /* change ring type */ prompt = "ring-type"; sptr = &playerp->p_ring.ring_type; goto SALTER; case '9': /* change ring duration */ prompt = "ring-duration"; sptr = &playerp->p_ring.ring_duration; goto SALTER; case '!': /* quit, update */ if (Wizard && (!ingameflag || playerp != &Player)) { /* turn off status if not modifying self */ playerp->p_status = S_OFF; playerp->p_tampered = T_OFF; } writerecord(playerp, loc); clear(); return; case '?': /* delete player */ if (ingameflag && playerp == &Player) /* cannot delete self */ continue; freerecord(playerp, loc); clear(); return; default: continue; } DALTER: mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt); dtemp = infloat(); if (dtemp != 0.0) *dptr = dtemp; continue; SALTER: mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt); dtemp = infloat(); if (dtemp != 0.0) *sptr = (short)dtemp; continue; BALTER: mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt); c = getanswer("\nTF", TRUE); if (c == 'T') *bptr = TRUE; else if (c == 'F') *bptr = FALSE; continue; } }
void neatstuff(void) { double temp; /* for temporary calculations */ int ch; /* input */ switch ((int)ROLL(0.0, 100.0)) { case 1: case 2: if (Player.p_poison > 0.0) { mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? "); temp = floor(infloat()); if (temp < 0.0 || temp > Player.p_gold) { /* negative gold, or more than available */ mvaddstr(6, 0, "He was not amused, and made you worse.\n"); Player.p_poison += 1.0; } else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1)) /* medic wants 1/2 of available gold */ mvaddstr(5, 0, "Sorry, he wasn't interested.\n"); else { mvaddstr(5, 0, "He accepted."); Player.p_poison = MAX(0.0, Player.p_poison - 1.0); Player.p_gold -= temp; } } break; case 3: mvaddstr(4, 0, "You've been caught raping and pillaging!\n"); Player.p_experience += 4000.0; Player.p_sin += 0.5; break; case 4: temp = ROLL(10.0, 75.0); mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp); ch = getanswer("NY", FALSE); if (ch == 'Y') collecttaxes(temp, 0.0); break; case 5: if (Player.p_sin > 1.0) { mvaddstr(4, 0, "You've found a Holy Orb!\n"); Player.p_sin -= 0.25; } break; case 6: if (Player.p_poison < 1.0) { mvaddstr(4, 0, "You've been hit with a plague!\n"); Player.p_poison += 1.0; } break; case 7: mvaddstr(4, 0, "You've found some holy water.\n"); ++Player.p_holywater; break; case 8: mvaddstr(4, 0, "You've met a Guru. . ."); if (drandom() * Player.p_sin > 1.0) addstr("You disgusted him with your sins!\n"); else if (Player.p_poison > 0.0) { addstr("He looked kindly upon you, and cured you.\n"); Player.p_poison = 0.0; } else { addstr("He rewarded you for your virtue.\n"); Player.p_mana += 50.0; Player.p_shield += 2.0; } break; case 9: mvaddstr(4, 0, "You've found an amulet.\n"); ++Player.p_amulets; break; case 10: if (Player.p_blindness) { mvaddstr(4, 0, "You've regained your sight!\n"); Player.p_blindness = FALSE; } break; default: /* deal with poison */ if (Player.p_poison > 0.0) { temp = Player.p_poison * Statptr->c_weakness * Player.p_maxenergy / 600.0; if (Player.p_energy > Player.p_maxenergy / 10.0 && temp + 5.0 < Player.p_energy) Player.p_energy -= temp; } break; } }
long rollnewplayer(void) { int chartype; /* character type */ int ch; /* input */ initplayer(&Player); /* initialize player structure */ clear(); mvaddstr(4, 21, "Which type of character do you want:"); mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento "); if (Wizard) { addstr("7:Super ? "); chartype = getanswer("1234567", FALSE); } else { addstr("? "); chartype = getanswer("123456", FALSE); } do { genchar(chartype); /* roll up a character */ /* print out results */ mvprintw(12, 14, "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n", Player.p_strength, Player.p_quickness, Player.p_mana); mvprintw(13, 14, "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n", Player.p_energy, Player.p_brains, Player.p_magiclvl); if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) break; mvaddstr(14, 14, "Type '1' to keep >"); ch = getanswer(" ", TRUE); } while (ch != '1'); if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) /* get coordinates for experimento */ for (;;) { mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? "); getstring(Databuf, SZ_DATABUF); sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y); if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER) mvaddstr(17, 0, "Invalid coordinates. Try again.\n"); else break; } for (;;) { /* name the new character */ mvprintw(18, 0, "Give your character a name [up to %d characters] ? ", SZ_NAME - 1); getstring(Player.p_name, SZ_NAME); truncstring(Player.p_name); /* remove trailing blanks */ if (Player.p_name[0] == '\0') /* no null names */ mvaddstr(19, 0, "Invalid name."); else if (findname(Player.p_name, &Other) >= 0L) /* cannot have duplicate names */ mvaddstr(19, 0, "Name already in use."); else /* name is acceptable */ break; addstr(" Pick another.\n"); } /* get a password for character */ Echo = FALSE; do { mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? "); getstring(Player.p_password, SZ_PASSWORD); mvaddstr(21, 0, "One more time to verify ? "); getstring(Databuf, SZ_PASSWORD); } while (strcmp(Player.p_password, Databuf) != 0); Echo = TRUE; return (allocrecord()); }
int main(int argc, char **argv) { bool noheader = FALSE; /* set if don't want header */ bool headeronly = FALSE; /* set if only want header */ bool examine = FALSE; /* set if examine a character */ time_t seconds; /* for time of day */ double dtemp; /* for temporary calculations */ initialstate(); /* init globals */ /* process arguments */ while (--argc && (*++argv)[0] == '-') switch ((*argv)[1]) { case 's': /* short */ noheader = TRUE; break; case 'H': /* Header */ headeronly = TRUE; break; case 'a': /* all users */ activelist(); cleanup(TRUE); /* NOTREACHED */ case 'p': /* purge old players */ purgeoldplayers(); cleanup(TRUE); /* NOTREACHED */ case 'S': /* set 'Wizard' */ Wizard = !getuid(); break; case 'x': /* examine */ examine = TRUE; break; case 'm': /* monsters */ monstlist(); cleanup(TRUE); /* NOTREACHED */ case 'b': /* scoreboard */ scorelist(); cleanup(TRUE); /* NOTREACHED */ } if (!isatty(0)) /* don't let non-tty's play */ cleanup(TRUE); /* NOTREACHED */ playinit(); /* set up to catch signals, init curses */ if (examine) { changestats(FALSE); cleanup(TRUE); /* NOTREACHED */ } if (!noheader) { titlelist(); purgeoldplayers(); /* clean up old characters */ } if (headeronly) cleanup(TRUE); /* NOTREACHED */ do { /* get the player structure filled */ Fileloc = -1L; mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? "); switch (getanswer("NYQ", FALSE)) { case 'Y': Fileloc = recallplayer(); break; case 'Q': cleanup(TRUE); /* NOTREACHED */ default: Fileloc = rollnewplayer(); break; } clear(); } while (Fileloc < 0L); if (Player.p_level > 5.0) /* low level players have long timeout */ Timeout = TRUE; /* update some important player statistics */ strcpy(Player.p_login, Login); time(&seconds); Player.p_lastused = localtime(&seconds)->tm_yday; Player.p_status = S_PLAYING; writerecord(&Player, Fileloc); Statptr = &Stattable[Player.p_type]; /* initialize pointer */ /* catch interrupts */ #ifdef BSD41 sigset(SIGINT, interrupt); #endif #ifdef BSD42 signal(SIGINT, interrupt); #endif #ifdef SYS3 signal(SIGINT, interrupt); #endif #ifdef SYS5 signal(SIGINT, interrupt); #endif altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */ clear(); for (;;) { /* loop forever, processing input */ adjuststats(); /* cleanup stats */ if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING) { /* not allowed on throne -- move */ mvaddstr(5, 0, "You're not allowed in the Lord's Chamber without a crown.\n"); altercoordinates(0.0, 0.0, A_NEAR); } checktampered(); /* check for energy voids, etc. */ if (Player.p_status != S_CLOAKED /* not cloaked */ && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y) /* |x| = |y| */ && !Throne) { /* not on throne */ dtemp = sqrt(dtemp / 100.0); if (floor(dtemp) == dtemp) { /* |x| / 100 == n*n; at a trading post */ tradingpost(); clear(); } } checkbattle(); /* check for player to player battle */ neatstuff(); /* gurus, medics, etc. */ if (Player.p_status == S_CLOAKED) { /* costs 3 mana per turn to be cloaked */ if (Player.p_mana > 3.0) Player.p_mana -= 3.0; else { /* ran out of mana, uncloak */ Player.p_status = S_PLAYING; Changed = TRUE; } } if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) { /* change status back to S_PLAYING */ Player.p_status = S_PLAYING; Changed = TRUE; } if (Changed) { /* update file only if important stuff has changed */ writerecord(&Player, Fileloc); Changed = FALSE; continue; } readmessage(); /* read message, if any */ displaystats(); /* print statistics */ move(6, 0); if (Throne) /* maybe make king, print prompt, etc. */ throneroom(); /* print status line */ addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit "); if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK) addstr("6:Cloak "); if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT) addstr("7:Teleport "); if (Player.p_specialtype >= SC_COUNCIL || Wizard) addstr("8:Intervene "); procmain(); /* process input */ } }