-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrpg.al
More file actions
157 lines (130 loc) · 3.57 KB
/
Copy pathrpg.al
File metadata and controls
157 lines (130 loc) · 3.57 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// --- DATA STRUCTURES ---
struct Hero {
int hp;
int max_hp;
int mana;
int strength;
str name;
}
struct Monster {
int hp;
int max_hp;
int damage;
str name;
}
// --- GLOBAL SEED FOR RNG ---
int seed = 54321;
// Function: Random Number Generator
function rand(int max) : (int val) {
seed = (seed * 1103515245 + 12345);
val = seed % max;
if (val < 0) { val = val * -1; }
return val;
}
// Function: Calculate Attack Damage
function calc_attack(int strength_stat) : (int dmg, int is_crit) {
int variance = rand(5);
dmg = strength_stat + variance;
int luck = rand(100);
is_crit = 0;
if (luck < 20) {
dmg = dmg * 2;
is_crit = 1;
}
return dmg, is_crit;
}
// Function: Cast Spell
function cast_fireball(int current_mana) : (int cost) {
cost = 15;
if (current_mana < cost) {
throw "Not enough mana to cast Fireball!";
}
return cost;
}
// --- MAIN GAME LOOP ---
void main() {
seed = clock() * 1000; // Seed RNG
print("--- ABYSS QUEST: THE DARK DEPTHS ---");
Hero player = new(Hero);
player.name = "Artorias";
player.max_hp = 100;
player.hp = 100;
player.mana = 30;
player.strength = 8;
Monster mob = new(Monster);
mob.name = "Abyss Watcher";
mob.max_hp = 150;
mob.hp = 150;
mob.damage = 12;
print("A wild %{str} appears!", mob.name);
print("");
int round = 1;
int fighting = 1;
while (fighting) {
print("=== ROUND %{int} ===", round);
print("%{str} HP: %{int} | Mana: %{int}", player.name, player.hp, player.mana);
print("%{str} HP: %{int}", mob.name, mob.hp);
print("1. Attack");
print("2. Fireball (15 Mana)");
print("3. Flurry (Multi-hit)");
print("Choose action:");
// FIX: Explicit assignment to ensure correct stack behavior
int choice = 0;
choice = input_int();
// DEBUG: Verify input
print("DEBUG: You chose %{int}", choice);
int dmg = 0;
int crit = 0;
if (choice == 1) {
dmg, crit = calc_attack(player.strength);
if (crit) {
print("CRITICAL HIT!");
}
print("You hit for %{int} damage.", dmg);
mob.hp -= dmg;
}
else if (choice == 2) {
try {
int cost = cast_fireball(player.mana);
player.mana -= cost;
dmg = 40;
print("FIREBALL EXPLODES! %{int} damage.", dmg);
mob.hp -= dmg;
}
catch (err) {
print("SPELL FAILED: %{str}", err);
}
}
else if (choice == 3) {
print("You unleash a flurry of blows!");
for (int i = 0; i < 3; i++) {
int hit = 4;
print(" Hit %{int}: %{int} dmg", i + 1, hit);
mob.hp -= hit;
}
}
if (mob.hp > 0) {
print("%{str} attacks you!", mob.name);
int mob_dmg = mob.damage + rand(3);
player.hp -= mob_dmg;
print("You took %{int} damage.", mob_dmg);
} else {
print("");
print("VICTORY! The %{str} has been defeated.", mob.name);
fighting = 0;
}
if (player.hp <= 0) {
print("");
print("DEFEAT... You have died.");
fighting = 0;
}
print("");
round++;
}
print("--- Game Over ---");
abyss_eye();
free(player);
free(mob);
print("Memory cleaned.");
abyss_eye();
}