void game_roll (struct Game *game, int roll) { printf ("%s is the current player\n", game->players[game->current_player]); printf ("They have rolled a %d\n", roll); if (game->in_penalty_box[game->current_player]) { if (roll % 2 != 0) { game->is_getting_out_of_penalty_box = true; printf ("%s is getting out of the penalty box\n", game->players[game->current_player]); game->places[game->current_player] = game->places[game->current_player] + roll; if (game->places[game->current_player] > 11) game->places[game->current_player] = game->places[game->current_player] - 12; printf ("%s's new location is %d\n", game->players[game->current_player], game->places[game->current_player]); printf ("The category is %s\n", current_category (game)); ask_question (game); } else { printf ("%s is not getting out of the penalty box\n", game->players[game->current_player]); game->is_getting_out_of_penalty_box = false; } } else { game->places[game->current_player] = game->places[game->current_player] + roll; if (game->places[game->current_player] > 11) game->places[game->current_player] = game->places[game->current_player] - 12; printf ("%s's new location is %d\n", game->players[game->current_player], game->places[game->current_player]); printf ("The category is %s\n", current_category (game)); ask_question (game); } }
int *ask_int_question() { return ask_question("Enter an integer: ", is_valid_int, str_to_int, true); }
shelf_t *ask_shelf_question() { return ask_question("Enter a character followed by an integer between 0-99: ", is_valid_shelf, str_to_shelf, true); }
char *ask_string_question() { return ask_question("Enter a string:", NULL, NULL, true); }
/** * @short Just asks the user for the answer. */ onion_connection_status ask_handler(void *none, onion_request *req, onion_response *res){ char temp[1024]; strcpy(temp, onion_request_get_path(req)); onion_dict_preorder(onion_request_get_query_dict(req),format_query,temp); char *resp=ask_question(temp); if (!resp) return OCS_INTERNAL_ERROR; onion_response_write0(res, resp); free(resp); return OCS_PROCESSED; }
static bool test_pwm_manual_check(void) { int ret = ask_question("Do you have a frequency meter ?", 15); if (ret == 2) return true; if (ret == -1) return false; if (pwm_init(MIKROBUS_1) < 0) return false; if (pwm_enable(MIKROBUS_1) < 0) return false; printf("The PWM pin on mikrobus 1 has been configured.\n"); printf("frequency: 3kHz\n"); printf("duty cycle: 50%%\n"); if (ask_question("Does it match what you measure ?", 60) != 1) return false; if (pwm_set_frequency(MIKROBUS_1, 10000) < 0) return false; printf("Frequency has been changed to 10kHz.\n"); if (ask_question("Does it match what you measure ?", 60) != 1) return false; if (pwm_disable(MIKROBUS_1) < 0) return false; printf("PWM pin has been disabled.\n"); if (ask_question("Is there still some output?", 60) != 2) return false; return pwm_release(MIKROBUS_1) == 0; }
/* Run the client server roleplay. Note the user inputs for both parties. By Nicolas Knoebber and Erin Callaway */ int main() { server_init(); unsigned char server_pk[32]; unsigned char init_sk[32]; unsigned char nonce0[24]; get_server_keys(server_pk,init_sk); getN0(nonce0); c_send_verif(server_pk,init_sk,nonce0); s_recieve_verif(); c_recieve_verif(server_pk); ask_question(server_pk); answer_question(); recieve_answer(server_pk); return 0; }
void init_game() { WINDOW* map_win = newwin(24, 80, 0, 0); WINDOW* area_win = newwin(6, 10, 0, 80); WINDOW* stats_win = newwin(8, 10, 6, 80); WINDOW* examine_win = newwin(10, 10, 14, 80); WINDOW* hp_win = newwin(1, 90, 24, 0); WINDOW* log_win = newwin(10, 90, 25, 0); dead = false; init_log(log_win); init_map(map_win); init_items(); world = calloc(LEVEL_COUNT, sizeof(map*)); world[0] = load_map("data/maps/farm.map", 78, 22, false, true); for(int i = 1; i < 3; ++i) world[i] = load_map("data/maps/easy_cave.map", 80 + 10 * (i - 1), 24 + 4 * (i - 1), true, true); for(int i = 3; i < 5; ++i) world[i] = load_map("data/maps/mid_cave.map", 80 + 10 * (i - 1), 24 + 4 * (i - 1), true, true); for(int i = 5; i < 7; ++i) world[i] = load_map("data/maps/hard_cave.map", 80 + 15 * (i - 1), 24 + 6 * (i - 1), true, true); for(int i =7; i < 9; ++i) world[i] = load_map("data/maps/crazy_cave.map", 80 + 18 * (i - 1), 24 + 8 * (i - 1), true, true); world[LEVEL_COUNT - 1] = load_map("data/maps/final.map", 78, 22, true, false); init_player(map_win, stats_win, hp_win, area_win, examine_win, world[0]); int x, y; get_random_empty_tile(&x, &y, world[LEVEL_COUNT - 1]); spawn_item(x, y, "data/items/cat.item", world[LEVEL_COUNT - 1]); get_random_empty_tile(&x, &y, world[0]); player_set_position(x, y); draw_map(x, y, world[0]); add_message(COLOR_DEFAULT, "@ symbol, a brave young farmer, was out for a stroll on his farm when his cat Cuddles ran down into the gaping starcase to the deadly Caves of Consternation! @ symbol had been meaning to patch that up for a while, but hadn't gotten a chance yet. Don't judge."); if(ask_question(COLOR_SELECTION, "Will you help @ symbol retrieve his cat, Cuddles?")) add_message(COLOR_HP_GOOD, "Excellent! Get to it, then!"); else { add_message(COLOR_HP_CRIT, "Well that was unexpected. Okay then, press q to quit to the main menu."); dead = true; } draw_log(); }
int main(int argc, char *argv[]) { char answ[MAX_ANSW_SIZE]; char character[MAX_ANSW_SIZE]; character[0] = '0'; printWelcome(); seedDb(50); while(tolower(character[0]) != 'x') { listOptions(); ask_question(answ, "Command me, master:", "Invalid input master, try again:", CHARACTER); strcpy(character, answ); if(!executeCommand(character)) { printf("Invalid input, try again\n"); } } return 0; }
static void exec_action(int op,int arg1,int arg2) { int i, j; char *tmpstr; switch(op) { case 1000:goto_room(arg1-first_room);break; case 1001:goto_room(agt_rand(arg1,arg2)-first_room);break; case 1002:agt_var[arg1]=loc+first_room;break; case 1003:agt_var[arg1]=dobj;break; case 1004:agt_var[arg1]=iobj;break; case 1005:goto_room(agt_var[arg1]-first_room);break; case 1006:it_move(arg1,agt_var[arg2]);break; case 1007:get_obj(agt_var[arg1]);break; case 1008:msgout(agt_var[arg1],1);break; case 1009:get_obj(arg1);break; case 1010:get_obj(arg1);it_move(arg1,1000);break; case 1011:drop_obj(arg1);break; case 1012: if (it_loc(arg1)==1000) { if (PURE_WEAR) drop_obj(arg1); else it_move(arg1,1); } break; case 1013:fontcmd(0,arg1-1);break; /* Load font */ case 1014:pictcmd(1,pictable[arg1-1]);break; /* Show picture */ case 1015:changepict(arg1,arg2);break; /* ChangePicture */ case 1016: if (PICT_SUPPORT && yesno("Would you like to see the picture?")) pictcmd(1,pictable[arg1-1]);break; case 1017:pictcmd(2,arg1);break; /* Show room pix */ case 1018: if (PICT_SUPPORT && yesno("Would you like to see the picture?")) pictcmd(2,arg1-1);break; case 1019:musiccmd(1,arg1-1);break; case 1020:musiccmd(1,agt_rand(arg1,arg2)-1);break; case 1021:musiccmd(2,arg1-1);break; case 1022:musiccmd(3,-1); break; /* Stop Repeat */ case 1023:musiccmd(4,-1); break; /* Stop song */ case 1024:musiccmd(5,-1); break; /* Suspend song */ case 1025:musiccmd(6,-1);break; /* Resume song */ case 1026: if (tnoun(dobj)) noun[dobj-first_noun].movable=!noun[dobj-first_noun].movable; break; case 1027: it_newdesc(arg1,&msg_ptr[arg2-1]); break; case 1028: if (tnoun(arg1)) noun[arg1-first_noun].points=arg2; else if (tcreat(arg1)) creature[arg1-first_creat].points=arg2; else if (troom(arg1)) room[arg1-first_room].points=arg2; break; case 1029:it_destroy(iobj);break; case 1030: tmpstr=agt_readline(3); i=strlen(tmpstr)-1; if (i>0 && tmpstr[i]=='\n') tmpstr[i]=0; strncpy(userstr[arg1-1],tmpstr,80); rfree(tmpstr); break; case 1031:agt_var[arg1]=read_number();break; case 1032:agt_var[arg1]=curr_time;break; case 1033:curr_time=normalize_time(agt_var[arg1]);break; case 1034:curr_time=normalize_time(arg1); break; case 1035:add_time(arg1);break; case 1036:delta_time=arg1;break; /* 1037 and 1038 are subroutine commands */ case 1039:get_obj(dobj);break; case 1040:it_move(dobj,1000);break; case 1041:drop_obj(dobj);break; case 1042: if (it_loc(dobj)==1000) { if (PURE_WEAR) it_move(dobj,1); else drop_obj(dobj); } break; case 1043: /* drop all */ safecontloop(i,j,1) drop_obj(i); break; case 1044: /* remove all */ safecontloop(i,j,1000) drop_obj(i); break; case 1045:deadflag=1;break; case 1046:it_move(arg1,loc+first_room);break; case 1047:it_move(arg1,arg2);break; case 1048:it_reposition(arg1,arg2,1);break; /* RePosition */ case 1049:it_move(dobj,loc+first_room);break; case 1050:it_move(dobj,arg1);break; case 1051: safecontloop(i,j,1) it_move(i,arg1); safecontloop(i,j,1000) it_move(i,arg1); break; case 1052: nounloop(i) if (player_has(i+first_noun) && noun[i].points>arg2) it_move(i+first_noun,arg1); break; case 1053: safecontloop(i,j,arg1) if (tnoun(i)) it_move(i,arg2); break; case 1054:it_destroy(arg1);break; case 1055:it_destroy(dobj);break; case 1056:i=it_loc(arg1); it_move(arg1,it_loc(arg2)); it_move(arg2,i); break; case 1057:it_move(arg1,it_loc(arg2));break; case 1058:it_move(dobj,it_loc(arg2));break; case 1059: case 1060: /* Add to/remove from group */ if (tcreat(arg1)) creature[arg1-first_creat].groupmemb=(op==1059); break; case 1061: /* Move group */ safecontloop(i,j,loc+first_room) if (it_group(i)) it_move(i,arg1); break; /* 1062 is RedirectTo */ case 1063:msgout(agt_rand(arg1,arg2),1);break; case 1064:print_contents(arg1,1);break; case 1065: case 1066: case 1067: case 1068: obj_act(op-1065,arg1);break; case 1069: case 1070: case 1071: case 1072: obj_act(op-1069,dobj);break; case 1073:print_score();break; case 1074: tscore+=arg1;break; case 1075: tscore-=arg1;break; case 1076:v_inventory();break; case 1077:wait_return();break; case 1078:writeln("Time passes...");break; case 1079:agt_delay(arg1);break; case 1080:agt_clrscr();break; case 1081:it_describe(arg1);break; case 1082:look_room();break; /* LOOK */ case 1083:msgout(arg1,1);break; case 1084:writeln("");break; case 1085:if (PURE_TONE && sound_on) agt_tone(arg1,arg2);break; /* Tone */ case 1086:agt_number=ask_for_number(arg1,arg2);break; case 1087:agt_answer=ask_question(arg1);break; case 1088:change_passage(loc,arg1,arg2);break; case 1089:flag[arg1]=1;break; case 1090:flag[arg1]=0;break; case 1091:flag[arg1]=!flag[arg1];break; case 1092:room[loc].flag_noun_bits|=(1 << (arg1-1) ); break; /* Roomflag on */ case 1093:room[loc].flag_noun_bits&=~(1 << (arg1-1) );break; /* Off */ case 1094:room[loc].flag_noun_bits^=(1 << (arg1-1) );break; /* Toggle */ case 1095: /* if (agt_counter[arg1]==-1)*/ agt_counter[arg1]=1;break; case 1096:agt_counter[arg1]=-1;break; case 1097:agt_var[arg1]=arg2;break; case 1098:agt_var[arg1]+=arg2;break; case 1099:agt_var[arg1]-=arg2;break; case 1100:agt_var[arg1]+=agt_var[arg2];break; case 1101:agt_var[arg1]-=agt_var[arg2];break; case 1102:agt_var[arg1]=agt_rand(0,arg2);break; case 1103:agt_var[arg1]=dobj_rec->num;break; case 1104:agt_var[arg1]=iobj_rec->num;break; /* The following are v1.8x specific */ case 1105:quote(arg1);break; case 1106:add_time(arg1);break; case 1107:add_time(-arg1);break; case 1108:curr_time=(curr_time%100)+100*arg1;break; case 1109:curr_time=(curr_time/100)*100+arg1;break; case 1110:add_time(agt_var[arg1]);break; case 1111:add_time(-agt_var[arg1]);break; case 1112:curr_time=(curr_time%100)+100*agt_var[arg1];break; case 1113:curr_time=(curr_time/100)*100+agt_var[arg1];break; /* Now for the AGX additions */ case 1114:add_time(-arg1);break; /* ME-style SubtractFromTime */ case 1115: disambig_score=arg1; break; /* SetDisambigPriority */ case 1116:agt_var[arg1]=delta_time;break; case 1117: /* ChangeStatus */ statusmode=arg1; break; case 1118: if (!mult_rangecheck(agt_var[arg1],arg2)) break; agt_var[arg1]*=arg2;break; case 1119: if (arg2==0) { if (!PURE_ERROR) writeln("GAME ERROR: Division by zero."); } else agt_var[arg1]/=arg2; break; case 1120: if (arg2==0) { if (!PURE_ERROR) writeln("GAME ERROR: Attempt to divide by zero."); } else agt_var[arg1]%=arg2; break; case 1121:agt_waitkey();break; case 1122:last_he=arg1;break; /* SetHE */ case 1123:last_she=arg1;break; case 1124:last_it=arg1;break; case 1125:last_they=arg1;break; case 1126:msgout(arg1,0);break; case 1127: if (!PURE_ERROR) sysmsg(arg1,"GAME ERROR: Standard message not defined."); break; case 1128: msgout(arg1,1);break; /* FailMessage */ case 1129: /* StdMessage */ sysmsg(arg1,"GAME ERROR: Standard message not defined."); break; case 1130: msgout(arg2,1);break; /* ErrMessage */ case 1131: /* StdErrMessage */ sysmsg(arg1,"GAME ERROR: Standard message not defined."); break; case 1132: /* AND */ break; /* These don't do anything under normal circumstances */ case 1133: /* SetClass */ if (troom(arg1)) room[arg1-first_room].oclass=arg2; else if (tnoun(arg1)) noun[arg1-first_noun].oclass=arg2; else if (tcreat(arg1)) noun[arg1-first_creat].oclass=arg2; break; case 1134: agt_var[arg1]=it_class(arg2); break; /* SetVariableToClass */ /* Stack commands */ case 1135: push_stack(arg1); break; case 1136: agt_var[arg1]=pop_stack(); break; case 1137: case 1138: case 1139: case 1140: case 1141: op_stack(op-1137); /* +,-,*, /,% * */ break; case 1142: { /* DupStack */ long n; n=pop_stack(); push_stack(n); push_stack(n); break; } case 1143: pop_stack();break; /* Discard TOS */ case 1144: agt_var[arg1]=agt_number;break; /* SetVariableToInput */ case 1145: setattr(arg1,arg2,1); break; /* Set */ case 1146: setattr(arg1,arg2,0); break; /* Clear */ case 1147: push_stack(getprop(arg1,arg2));break; /* PushProp */ case 1148: setprop(arg1,arg2,pop_stack());break; /* PopProp */ /* 1149, 1150 handled by run_metacommand */ /* 1151 is EndDisambig */ /* 1152 is XRedirect */ case 1153: rstrncpy(userstr[arg1-1],userstr[arg2-1],81);break; case 1154: setcase(userstr[arg1-1],1); break; case 1155: setcase(userstr[arg1-1],0);break; case 1156: op_objflag(1,arg1,arg2);break; case 1157: op_objflag(0,arg1,arg2);break; case 1158: op_objflag(3,arg1,arg2);break; case 1159: push_stack(op_objprop(2,arg1,arg2,0)); break; case 1160: op_objprop(1,arg1,arg2,pop_stack()); break; case 1161: move_in_dir(arg1,arg2); break; default: writeln("INTERNAL ERROR: Action token not supported."); rprintf("Action #%d",op); writeln(""); } }