Skip to content

DaInfLoop/knavalbattle.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

knavalbattle.js

A Node.js library for KNavalBattle/KBattleship.

How to use:

  1. Install the library into your Node.js project:
$ npm install knavalbattle.js
  1. Import the client:
// ESM:
import { NavalClient } from "knavalbattle.js";

// CJS:
const { NavalClient } = require("knavalbattle.js");
  1. Initialize the client and events:
const client = new NavalClient("NICKNAME");

client.on("connect", (player) => {
    client.sendChatMessage(`Hi ${player.nickname}!`);
});

client.on("begin", () => {
    // Create your own ships and track them.
});

client.on("move", (hit) => {
    client.sendMoveResponse(hit.respond('miss'));
});

client.on("gameOver", (winner) => {
    if (winner.me) {
        client.sendChatMessage("I win!");
    } else { 
        client.sendChatMessage("You won!");
    }
});
  1. Connect to a peer!
client.connect(54321, "127.0.0.1");

Contributing

YES PLEASE. I made this in about 7 hours and so there are bound to be bugs. If you discover any bugs or anything, make an issue or a PR on the GitHub repo!

Licensing

This repository and NPM package are licensed under the MIT License. A version of the license can be viewed in the LICENSE file.

About

A Node.js library for KNavalBattle/KBattleship.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published