int menu_getcmd(Menu menu) { int i; printf("\n> "); scanf("%d", &i); putchar('\n'); purge_stdin(); if (i >= 1 && i < 1 + (int)menu.endList) return i; return 0; }
void drop_weapon(Player *player) { if (CHANCE(10)) { Weapon w = weapon_create_rand(player->lvl); char c; printf("\nVous trouvez une arme: "); weapon_display(w); printf("Voulez vous la prendre [o/n]? "); scanf("%c", &c); purge_stdin(); if (c == 'o') { ship_set_item(&player->ship, I_WEAPON, 0, &w); } } }
void drop_staff(Player *player) { if (CHANCE(7)) { Staff staff = staff_create(); char c; printf("Vous trouvez un membre du vaisseau: "); staff_set_life(&staff, rand_born(10, 80)); staff_display(staff); printf("Voulez vous le recruter [o/n]?"); scanf("%c", &c); purge_stdin(); if (c == 'o') { if (CHANCE(10)) { int rep = rand_born(1, 2); int money; static const char *sentence[] = { "C'etait un piege! La personne que vous venez de recruter est une kamikaze!\nElle explose dans le vaisseau et fait de serieux degats...", "La personne vous remercies, et vous donnes %d d'argent." }; switch (rep) { case 1: puts(sentence[rep - 1]); ship_get_damage(&player->ship, rand_born(50, player->ship.hull.life.max / 2)); break; case 2: money = rand_born(100, 1000); player->money += money; printf(sentence[rep - 1], money); break; default: break; } } crew_add_staff(&player->ship.crew, staff); } } }
void set_seed(void) { Menu *menu = menu_create(); int cmd = 1; bool running = true; unsigned seed = 42; menu_setTitle(menu, "Seed"); menu_addButtonText(menu, "Generer aleatoirement un seed"); menu_addButtonText(menu, "Entrer un seed"); while (running) { menu_display(*menu); cmd = menu_getcmd(*menu); switch (cmd) { case 1: { seed = (unsigned)time(NULL) / clock(); printf("Seed: %u\n", seed); running = false; break; } case 2: running = false; printf("Entrez un seed: "); scanf("%u", &seed); purge_stdin(); break; default: running = false; break; } srand(seed); } }