cli-game-utils

1.3.0 • Public • Published

Overview


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.

Functions


1. sPrint(input, [delay, endNewLine])

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.

2. sleep(milliseconds)

sleep will add a delay to the program for a specified amount of time in milliseconds.

Classes


Printer

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.

Constructor:

The constructor takes a value, defaultCharDelay which is used when the user does not specify a delay.

Functions:
writeQuestion(query, [charDelay])

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.

Examples

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:

Other Files and Scripts

1. genLootTable.js

About

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.

Running the Script

To run the loot table generator, type the following into your command line and follow the instructions that appear:

node genLootTable.js
Here is an example of a loot table generated by the script:
{
	"Skeleton" : {
		"Bone" : 30,
		"Sword" : 50,
		"Teeth" : 20
	},
	"Goblin" : {
		"Gold" : 45,
		"Dagger" : 20,
		"Goblin Guts" : 35
	},
	"Ogre" : {
		"Club" : 80,
		"Ogre Brains" : 20
	}

}

Package Sidebar

Install

npm i cli-game-utils

Weekly Downloads

26

Version

1.3.0

License

ISC

Unpacked Size

8 kB

Total Files

4

Last publish

Collaborators

  • tknight20