disgamekit
Advanced tools
Comparing version 1.0.3 to 1.1.0
{ | ||
"name": "disgamekit", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A small package that will help making ts/js discord bot mini games way easier!", | ||
@@ -12,3 +12,3 @@ "main": "src/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/Yetity/disgamekit.git" | ||
"url": "git+https://github.com/YetNT/disgamekit.git" | ||
}, | ||
@@ -23,10 +23,12 @@ "keywords": [ | ||
"game-engine", | ||
"light" | ||
"light", | ||
"turns", | ||
"discord" | ||
], | ||
"author": "Yetity", | ||
"author": "YetNT", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Yetity/disgamekit/issues" | ||
"url": "https://github.com/YetNT/disgamekit/issues" | ||
}, | ||
"homepage": "https://github.com/Yetity/disgamekit#readme", | ||
"homepage": "https://github.com/YetNT/disgamekit#readme", | ||
"devDependencies": { | ||
@@ -33,0 +35,0 @@ "expect.js": "^0.3.1", |
143
README.md
<h1 align="center"> disgamekit </h1> | ||
<p align="center"> | ||
<img alt="Static Badge" src="https://img.shields.io/badge/version-1.0.1-baige"> | ||
<img alt="Static Badge" src="https://img.shields.io/badge/version-1.1.0-baige"> | ||
</p> | ||
@@ -30,5 +30,12 @@ | ||
- [All classes exmaple](#example-discordjs) | ||
- [Turns Class](#turns-class) | ||
- - [Constructor](#constructor-3) | ||
- - [Methods](#methods-2) | ||
- [Player Class (Turns)](#player-class) | ||
- - [Constructor](#constructor-4) | ||
## Game Class | ||
The Game class represents a simple game controller with start, end, and error handling functionality. It manages the overall state of the game and provides methods to start, end, and handle game events. | ||
### Constructor | ||
@@ -255,3 +262,3 @@ | ||
Represents an object to be placed on the plane. | ||
The PlaneObject class represents an object that can be placed on the Plane. It emits events for collision detection and can be used to create interactive game elements. | ||
@@ -525,1 +532,133 @@ ### Constructor | ||
**NOTE** - The code above is set up in a way that every user plays the same game . To avoid this either initialize the variables in the message create or use a map. | ||
## Turns Class | ||
The Turns class manages a turn-based system for games with multiple players. It allows adding, removing, and advancing turns for players. | ||
### Constructor | ||
#### Parameters | ||
- `...players`: Numerous players to be added | ||
```js | ||
const { Turns, Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
const player3 = new Player('3', 'Charlie'); | ||
const turns = new Turns(player1, player2, player3); | ||
``` | ||
### Methods | ||
#### `addPlayer` | ||
Adds a new player to the game. | ||
##### Parameters | ||
- `player`: The player represented by the player class | ||
```js | ||
const { Turns, Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
const turns = new Turns(player1); | ||
const player3 = new Player('3', 'Charlie'); | ||
turns.addPlayer(player3); | ||
``` | ||
#### `removePlayer` | ||
Removes a player from the game. | ||
##### Parameters | ||
- `player`: The player represented by the player class | ||
```js | ||
const { Turns, Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
const player3 = new Player('3', 'Charlie'); | ||
const turns = new Turns(player1, player2, player3); | ||
turns.removePlayer(player2); | ||
``` | ||
#### `startTurns` | ||
Starts the turn-based game. | ||
```js | ||
const { Turns, Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
const turns = new Turns(player1, player2); | ||
turns.startTurns(); | ||
``` | ||
#### `nextTurn` | ||
Advances to the next turn. | ||
##### Parameters | ||
- `overridePlayer`:**(optional)** Override with an additional player, making them have an extra turn | ||
```js | ||
const { Turns, Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
const turns = new Turns(player1, player2); | ||
turns.startTurns(); | ||
turns.nextTurn(); | ||
``` | ||
#### `reverseOrder()` | ||
Reverses the order of turns. | ||
```js | ||
const { Turns, Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
const player3 = new Player('3', 'Charlie'); | ||
const turns = new Turns(player1, player2, player3); | ||
turns.reverseOrder(); | ||
``` | ||
## Player Class | ||
The Player class represents a player in the game (specifically for the Turns class). It holds a unique identifier (id) and the player's name (name). | ||
### Constructor | ||
#### Parameters | ||
- `id`: The player's unique identifier. | ||
- `name`: The player's name. | ||
```js | ||
const { Player } = require('disgamekit'); | ||
const player1 = new Player('1', 'Alice'); | ||
const player2 = new Player('2', 'Bob'); | ||
``` |
@@ -199,2 +199,61 @@ import { EventEmitter } from 'events'; | ||
export { Game, Plane, PlaneObject }; | ||
/** | ||
* @class | ||
* Class for handling Turn based games. | ||
*/ | ||
declare class Turns extends EventEmitter { | ||
/** | ||
* | ||
* @param {Player} players The plane instance that this wil be placed on. | ||
*/ | ||
constructor(...players: Player); | ||
/** | ||
* | ||
* @param {Player} player Player to be added to the Turns arrrray | ||
*/ | ||
addPlayer(player: Player): void; | ||
/** | ||
* | ||
* @param {Player} player Player to be removed from the Turns arrrray | ||
*/ | ||
removePlayer(player: Player): void; | ||
/** | ||
* Start by adding the first player as the current player | ||
*/ | ||
startTurns(): void; | ||
/** | ||
* | ||
* @param {Player} overridePlayer Overrides with a player, if overriden with a player who recently had a turn, they'll have an extra turn | ||
*/ | ||
nextTurn(overridePlayer?: Player): void; | ||
/** | ||
* Reverses the order of the turns | ||
*/ | ||
reverseOrder(): void | ||
/** | ||
* The current player. If `startTurns` was not run, this will be equal to undefined | ||
*/ | ||
currentPlayer: Player; | ||
} | ||
/** | ||
* @class | ||
* Player class for the Turns class | ||
*/ | ||
declare class Player { | ||
/** | ||
* | ||
* @param id Unique Id for the player | ||
* @param name Name for said Player | ||
*/ | ||
constructor(id: string, name: string); | ||
} | ||
export { Game, Plane, PlaneObject, Turns, Player }; |
const Game = require('./class/Game'); | ||
const { PlaneObject, Plane } = require('./class/Plane'); | ||
const { Turns, Player } = require('./class/Turns'); | ||
module.exports = { Game, Plane, PlaneObject }; | ||
module.exports = { Game, Plane, PlaneObject, Turns, Player }; |
const expect = require('expect.js'); | ||
const { describe, it } = require('mocha'); | ||
const { Game, Plane, PlaneObject } = require('./index'); | ||
const { Game, Plane, PlaneObject, Turns, Player } = require('./index'); | ||
@@ -19,2 +19,6 @@ const testGameId = 'gameId'; | ||
var martin = new Player('martin', 'Martin'); | ||
var rider = new Player('rider', 'Rider'); | ||
var turns = new Turns(martin); | ||
describe('Game', () => { | ||
@@ -101,1 +105,19 @@ it('should have a started game', () => { | ||
}); | ||
describe('Turns', () => { | ||
it('should have a current player of undefined as the startTurns method was not called yet', () => { | ||
expect(turns.currentPlayer).to.be(undefined); | ||
}); | ||
it('should start the turn, making martin the current player', () => { | ||
turns.startTurns(); | ||
turns.addPlayer(rider); | ||
expect(turns.currentPlayer).to.be(martin); | ||
}); | ||
it('should make rider the current player.', () => { | ||
turns.nextTurn(); | ||
expect(turns.currentPlayer).to.be(rider); | ||
}); | ||
it('should keep rider as the current playr by overriding next turn', () => { | ||
turns.nextTurn(rider); | ||
expect(turns.currentPlayer).to.be(rider); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39716
10
670
662