RCRPG/Nim: Difference between revisions

Content added Content deleted
(Created page with "{{collection|RCRPG}} This Nim version proposes the following commands: – alias <alias name> <command>: define an alias. – aliases: list aliases. – attack <direction>:...")
 
No edit summary
Line 4: Line 4:


– alias <alias name> <command>: define an alias.
– alias <alias name> <command>: define an alias.

– aliases: list aliases.
– aliases: list aliases.

– attack <direction>: use sledge to dig a tunnel in the given direction.
– attack <direction>: use sledge to dig a tunnel in the given direction.

– drop all | <item>: drop all items or a specified item.
– drop all | <item>: drop all items or a specified item.

– east: move to East.
– east: move to East.

– equip <item>: equip an item present in inventory.
– equip <item>: equip an item present in inventory.

– help: display the list of commands and directions.
– help: display the list of commands and directions.

– inventory: list items in the inventory.
– inventory: list items in the inventory.

– look: display location, items and exits.
– look: display location, items and exits.

– name <name>: give a name to the current room.
– name <name>: give a name to the current room.

– north: move to North.
– north: move to North.

– south: move to South.
– south: move to South.

– quit: quit game.
– quit: quit game.

– take all | <item>: take all items or a specified item.
– take all | <item>: take all items or a specified item.

– unequip: unequip the equipped item.
– unequip: unequip the equipped item.

– west: move to West.
– west: move to West.


Directions are: north, east, south, west, up, down.


==Code==
==Code==
Line 57: Line 75:


# Command names and number of tokens required for this command.
# Command names and number of tokens required for this command.
Commands = [("alias", 3), ("aliases", 1), ("quit", 1), ("name", 2), ("look", 1),
Commands = {"alias": 3, "aliases": 1, "quit": 1, "name": 2, "look": 1,
("help", 1), ("north", 1), ("east", 1), ("south", 1), ("west", 1),
"help": 1, "north": 1, "east": 1, "south": 1, "west": 1,
("up", 1), ("down", 1), ("attack", 2), ("inventory", 1),
"up": 1, "down": 1, "attack": 2, "inventory": 1,
("take", 2), ("drop", 2), ("equip", 2), ("unequip", 1)].toTable()
"take": 2, "drop": 2, "equip": 2, "unequip": 1}.toTable()


StartRoomPos: Position = (0, 0, 0)
StartRoomPos: Position = (0, 0, 0)
Line 69: Line 87:
# Miscellaneous.
# Miscellaneous.


func nextPos(oldCoords: Position; direction: Direction): Position =
func nextPos(oldPos: Position; direction: Direction): Position =
## Compute new coordinates from current position and direction.
## Compute new coordinates from current position and direction.
(oldCoords.x + IncPos[direction].x,
(oldPos.x + IncPos[direction].x,
oldCoords.y + IncPos[direction].y,
oldPos.y + IncPos[direction].y,
oldCoords.z + IncPos[direction].z)
oldPos.z + IncPos[direction].z)


#___________________________________________________________________________________________________
#___________________________________________________________________________________________________
Line 169: Line 187:
items: @[gold, gold, gold, gold, gold])
items: @[gold, gold, gold, gold, gold])
# Create room names.
# Create room names.
result.roomNames = [(StartRoomPos, "the starting room"),
result.roomNames = {StartRoomPos: "the starting room",
(PrizeRoomPos, "the prize room")]. toTable()
PrizeRoomPos: "the prize room"}.toTable()
# Create aliases.
# Create aliases.
result.aliases = [("n", "north"), ("e", "east"), ("s", "south"),
result.aliases = {"n": "north", "e": "east", "s": "south", "w": "west", "u": "up",
("w", "west"), ("u", "up"), ("d", "down"),
"d": "down", "a": "attack", "i": "inventory", "l": "look"}.toTable()
("a", "attack"), ("i", "inventory"), ("l", "look")].toTable()


#___________________________________________________________________________________________________
#___________________________________________________________________________________________________