RCRPG/D: Difference between revisions
m
→Code: Oops!
(→Code: translation template) |
m (→Code: Oops!) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1:
{{collection|RCRPG}}
<br>
[[D]] version of [[:Category:RCRPG|RCRPG]], with very basic input validation.
===Code===
{{trans|Python}}
<
std.array, std.range, std.algorithm, std.traits, std.typetuple;
Line 37:
bool[string] passages;
this(in string[] items = null) {
this.passages = directions.byKey.zip(repeat(false))
.assocArray
this.items = items.dup;
}
string describe(in P3 location) const {
auto result = "You are at ";
if (location in roomNames)
Line 55:
result ~= "\nExits are: ";
string[] exits = this.passages.byKey
.filter!(k => passages[k]
.array
if (exits.empty) exits = ["None"];
result ~= exits.map!capitalize
return result;
}
Line 132:
}
void newalias(in string newAlias, in string[] command...) {
if (command.length == 2) {
if (command[0] in aliases) { // avoid recursive aliasing
Line 178:
if (idx != -1) {
if (!this.equipped.empty)
this.unequip
this.inv = this.inv.remove(idx);
this.equipped = itemName;
Line 196:
}
void name(in string[] newRoomNameTokens...) {
roomNames[this.currentPos] = newRoomNameTokens.join(
}
Line 210:
direction);
if (joinRoomPos !in this.rooms)
this.rooms[joinRoomPos]= new Room(make_random_items
this.rooms[joinRoomPos]
.passages[opposite_dir(direction)] = true;
Line 219:
}
void processArguments(in string[] a, World w) {
foreach (f; __traits(derivedMembers, World)) {
static if (isCallable!(mixin("World." ~ f))) {
Line 237:
void main() {
auto world = new World
writeln("Welcome to the dungeon!\nGrab the sledge && make your" ~
" way to room 1,1,5 for a non-existent prize!");
while (true) {
writeln("\n", world.look
write("> ");
auto tokens = readln
if (tokens[0] == "quit")
break;
Line 265:
writeln("Thanks for playing!");
}</
|