Skip to content

Commit 26eede8

Browse files
authored andcommitted
Updated text adventure.
1 parent 32b057d commit 26eede8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

text_adventure.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import string;
1212
import io;
1313

1414
const int COMMAND_SIZE = 8;
15-
string commands COMMAND_SIZE;
15+
const string commands COMMAND_SIZE;
1616
commands[0] = "help";
1717
commands[1] = "take";
1818
commands[2] = "use";
@@ -27,7 +27,6 @@ struct "player";
2727
string inventory 5;
2828
int inventoryIndex;
2929
int inventoryCapacity;
30-
int index;
3130
struct;
3231

3332
struct "item";
@@ -140,30 +139,30 @@ return newRoom;
140139

141140
function useItem : string as toUse;
142141
int i = 0;
143-
p1.index = 0;
142+
int index = 0;
144143

145144
while i < p1.inventoryCapacity;
146-
string item = p1.inventory[index];
145+
string item = p1.inventory[useItem.index];
147146

148147
if item != "";
149148
if item.name == toUse;
150149
println "Used: ", item.name;
151150

152-
p1.inventory[index] = "";
151+
p1.inventory[useItem.index] = "";
153152
p1.health += item.healValue;
154153

155154
println "Health: ", p1.health;
156155
end;
157156
end;
158157

159-
p1.index += 1;
158+
index += 1;
160159
i += 1;
161160
end;
162161
return;
163162

164163
function takeItem : string as currentRoom, string as item;
165164
if p1.inventoryIndex < p1.inventoryCapacity;
166-
p1.inventory[inventoryIndex] = item;
165+
p1.inventory[p1.inventoryIndex] = item;
167166
p1.inventoryIndex += 1;
168167

169168
currentRoom.item = "";
@@ -204,7 +203,7 @@ while input != "exit";
204203
if input == "help";
205204
println "Type name of exit to go to new room.";
206205
int cs = 2;
207-
call printHelp;
206+
call printHelp : COMMAND_SIZE, commands;
208207

209208
break 7;
210209
end;

0 commit comments

Comments
 (0)