-
Notifications
You must be signed in to change notification settings - Fork 0
/
cast.h
82 lines (72 loc) · 1.82 KB
/
cast.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdbool.h>
int catch, i, j, choice;
float d;
bool baited = false;
int calc(bool bait) {
d = (float) rand() / (float) RAND_MAX;
for (i = bait ? 7 : 0; i < bait ? 11 : 7; ++i) {
d -= clump[tier][i];
if (d <= 0) {
return i;
break;
}
}
return 0;
}
void cast() {
if (tier >= 11) {
printf("Use some bait to catch better fish?\n\t(You can't catch rod upgrades when using bait) (y/N) ");
fflush(stdout);
choice = getch();
fflush(stdin);
printf("\n");
baited = choice == 'y' || choice == 'Y';
if (baited) {
if (bait > 0) {
bait--;
} else {
baited = false;
printf("You don't have any bait. You can buy bait at the market for $%d per piece.\n", COST);
return;
}
}
}
printf("\nCasting your %s rod...\n\n", rodname[tier]);
catch = calc(baited);
printf("You caught some %s!\n",
catch == 0 ? tiername[tier+1] :
catch == 6 ? (
tier == 15 ? "money" : "junk"
) :
fish[catch-1]
);
if (catch == 0) {
printf("You can upgrade your rod now, to fish better items. Do it now, or sell the %s? [y/N]\n> ", tiername[tier+1]);
fflush(stdout);
choice = getch();
fflush(stdin);
printf("\n");
if (choice == 'y' || choice == 'Y') {
printf("You have upgraded your fishing rod to a %s rod!\n", rodname[++tier]);
} else {
money += tier + 1;
printf(
"You sold the %s for $%d!\n",
tiername[tier+1],
tier + 1
);
}
} else if (catch == 6) {
if (tier == 15) {
j = (rand() % 10 + 1) * 10;
money += j;
printf("You take the (slightly wet) stack of $%d.\n", j);
} else {
j = (rand() % 5) + 1;
money += j;
printf("You sold the junk for $%d!\n", j);
}
} else {
data[catch-(catch > 6 ? 2 : 1)]++;
}
}