cli-game-utils
is a node module providing functions for games with a command line interface or purely command line games. While the module is intended to be used for games, it can be used for other projects involving text output as well.
sPrint will sequentially print the string inputted with a timed (default is 100 milliseconds) delay between each character. delay
specifies the delay between each character. endNewLine
is a boolean which will determine whether a newline is appended to the string.
sleep will add a delay to the program for a specified amount of time in milliseconds.
The Printer
class currently has 1 function and 1 constructor.
Note: In the source code, there is an instance of the class called printer
with defaultCharDelay
set to 100.
The constructor takes a value, defaultCharDelay
which is used when the user does not specify a delay.
writeQuestion will output the specified query (using sPrint
) and pause until the user gives an input via the command line. If charDelay
is not specified the defaultCharDelay
will be used.
const util = require("cli-game-utils");
util.sPrint("Hello World!", 200, true);
Output:
const util = require("cli-game-utils");
console.log("This is printed immediately.");
util.sleep(3000);
console.log("This is executed three seconds later.");
Output:
genLootTable.js
is a small script that will help a user generate loot tables stored in a JSON file. The format of the JSON file is as follows:
{
"Object1" : {
"Loot1" : 75,
"Loot2" : 25
},
"Object2" : {
"Loot1" : 100
}
}
The percentage for each loot item must add up to 100%, and the script will automatically fill in percentage values when it is at the last pair in each object. The resulting JSON file can be used to your pleasure, and functions to read this file will be added soon.
To run the loot table generator, type the following into your command line and follow the instructions that appear:
node genLootTable.js
{
"Skeleton" : {
"Bone" : 30,
"Sword" : 50,
"Teeth" : 20
},
"Goblin" : {
"Gold" : 45,
"Dagger" : 20,
"Goblin Guts" : 35
},
"Ogre" : {
"Club" : 80,
"Ogre Brains" : 20
}
}