@pompidup/kingdomino-engine 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +1402 -2
- package/dist/index.js.map +1 -7
- package/package.json +7 -8
- package/dist/bin/test.d.ts +0 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -7
- package/dist/src/_utils/container.d.ts +0 -9
- package/dist/src/application/engine/index.d.ts +0 -31
- package/dist/src/domain/engine/index.d.ts +0 -15
- package/dist/src/domain/entities/domino.d.ts +0 -22
- package/dist/src/domain/entities/game.d.ts +0 -38
- package/dist/src/domain/entities/kingdom.d.ts +0 -15
- package/dist/src/domain/port/dominoesRepository.d.ts +0 -4
- package/dist/src/domain/port/gamesRepository.d.ts +0 -6
- package/dist/src/domain/useCases/game/availableRules.d.ts +0 -4
- package/dist/src/domain/useCases/game/draw.d.ts +0 -6
- package/dist/src/domain/useCases/game/endGame.d.ts +0 -1
- package/dist/src/domain/useCases/game/endTurn.d.ts +0 -8
- package/dist/src/domain/useCases/game/firstTurn.d.ts +0 -8
- package/dist/src/domain/useCases/game/game.d.ts +0 -76
- package/dist/src/domain/useCases/game/init.d.ts +0 -4
- package/dist/src/domain/useCases/game/order.d.ts +0 -6
- package/dist/src/domain/useCases/game/pass.d.ts +0 -4
- package/dist/src/domain/useCases/game/pick.d.ts +0 -4
- package/dist/src/domain/useCases/game/place.d.ts +0 -4
- package/dist/src/domain/useCases/game/result.d.ts +0 -11
- package/dist/src/domain/useCases/game/scoring.d.ts +0 -8
- package/dist/src/domain/useCases/game/setRules.d.ts +0 -6
- package/dist/src/domain/useCases/game/setup.d.ts +0 -10
- package/dist/src/domain/useCases/game/startTurn.d.ts +0 -8
- package/dist/src/index.d.ts +0 -2
- package/dist/src/infrastructure/repositories/inMemoryDominoes.d.ts +0 -3
- package/dist/src/infrastructure/repositories/inMemoryGames.d.ts +0 -8
- package/dist/src/utils/container.d.ts +0 -9
- package/dist/src/utils/testHelpers.d.ts +0 -7
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Kingdomino Engine
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Kingdomino Engine is a simple and lightweight TypeScript engine designed to facilitate the gameplay of Kingdomino. It provides the core logic for managing game states, rules, and player interactions, making it easy to integrate into any application that requires a Kingdomino game engine.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Game State Management**: Efficiently manage game states, including player turns, game rules, and game progression.
|
|
10
|
+
- **Rule Enforcement**: Automatically enforce game rules, ensuring a fair and consistent gameplay experience.
|
|
11
|
+
- **Player Interaction**: Simplify player interactions, including drawing tiles, placing dominoes, and scoring.
|
|
12
|
+
- **Customizable Rules**: Support for custom game rules, allowing for a wide range of gameplay variations.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
To install the Kingdomino Engine, you can use npm or yarn. Run the following command in your terminal:
|
|
17
|
+
bash npm install @pompidup/kingdomino-engine
|
|
18
|
+
|
|
19
|
+
or
|
|
20
|
+
|
|
21
|
+
bash yarn add @pompidup/kingdomino-engine
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Setup
|
|
26
|
+
|
|
27
|
+
To start using the Kingdomino Engine, you need to import it and initialize a new game instance.
|
|
28
|
+
|
|
29
|
+
typescript import { KingdominoEngine } from '@pompidup/kingdomino-engine';
|
|
30
|
+
|
|
31
|
+
const engine = new KingdominoEngine();
|
|
32
|
+
|
|
33
|
+
### Setting Up Rules
|
|
34
|
+
|
|
35
|
+
You can customize the game rules by passing an array of rule names to the `setRules` method.
|
|
36
|
+
|
|
37
|
+
typescript engine.setRules(['rule1', 'rule2']);
|
|
38
|
+
|
|
39
|
+
### Starting a Game
|
|
40
|
+
|
|
41
|
+
To start a new game, use the `startGame` method.
|
|
42
|
+
|
|
43
|
+
typescript engine.startGame();
|
|
44
|
+
|
|
45
|
+
### Player Actions
|
|
46
|
+
|
|
47
|
+
Players can perform actions like drawing tiles, placing dominoes, and passing turns.
|
|
48
|
+
|
|
49
|
+
typescript // Example: Drawing a tile engine.drawTile('player1');
|
|
50
|
+
|
|
51
|
+
// Example: Placing a domino engine.placeDomino('player1', { x: 0, y: 0 }, 'domino1');
|
|
52
|
+
|
|
53
|
+
// Example: Passing a turn engine.passTurn('player1');
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
|
|
57
|
+
Contributions are welcome! Please read the [contributing guide](CONTRIBUTING.md) for details on how to contribute to this project.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
62
|
+
|
|
63
|
+
## Acknowledgments
|
|
64
|
+
|
|
65
|
+
- Thanks to all the contributors who have helped shape this project.
|
|
66
|
+
- Special thanks to the Kingdomino community for their support and feedback.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
declare const ground: readonly ["castle", "wheat", "forest", "sea", "plain", "swamp", "mine"];
|
|
2
|
+
type Ground = (typeof ground)[number];
|
|
3
|
+
type Tile = {
|
|
4
|
+
type: Ground;
|
|
5
|
+
crowns: number;
|
|
6
|
+
};
|
|
7
|
+
type EmptyTile = {
|
|
8
|
+
type: "empty";
|
|
9
|
+
crowns: 0;
|
|
10
|
+
};
|
|
11
|
+
type Domino = {
|
|
12
|
+
left: Tile;
|
|
13
|
+
right: Tile;
|
|
14
|
+
number: number;
|
|
15
|
+
};
|
|
16
|
+
type RevealsDomino = {
|
|
17
|
+
domino: Domino;
|
|
18
|
+
picked: boolean;
|
|
19
|
+
kingId: string | null;
|
|
20
|
+
position: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Position = {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
type Orientation = "vertical" | "horizontal";
|
|
28
|
+
type Rotation = 0 | 180;
|
|
29
|
+
type Kingdom = (Tile | EmptyTile)[][];
|
|
30
|
+
|
|
31
|
+
type King = {
|
|
32
|
+
id: string;
|
|
33
|
+
playerId: string;
|
|
34
|
+
order: number;
|
|
35
|
+
turnEnded: boolean;
|
|
36
|
+
hasPick: boolean;
|
|
37
|
+
hasPlace: boolean;
|
|
38
|
+
dominoPicked?: Domino;
|
|
39
|
+
};
|
|
40
|
+
type Player = {
|
|
41
|
+
id?: string;
|
|
42
|
+
name: string;
|
|
43
|
+
kingdom: Kingdom;
|
|
44
|
+
};
|
|
45
|
+
declare const availableMode: readonly ["Classic"];
|
|
46
|
+
type AvailableMode = (typeof availableMode)[number];
|
|
47
|
+
type Rule = {
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
mode: AvailableMode[];
|
|
51
|
+
playersLimit?: number;
|
|
52
|
+
};
|
|
53
|
+
type Game = {
|
|
54
|
+
id: string;
|
|
55
|
+
dominoes: Domino[];
|
|
56
|
+
currentDominoes: RevealsDomino[];
|
|
57
|
+
players: Player[];
|
|
58
|
+
kings: King[];
|
|
59
|
+
turn: number;
|
|
60
|
+
maxTurns: number;
|
|
61
|
+
maxDominoes: number;
|
|
62
|
+
dominoesPerTurn: number;
|
|
63
|
+
order: Record<number, string>;
|
|
64
|
+
rules?: Rule[];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type Score = {
|
|
68
|
+
score: number;
|
|
69
|
+
maxPropertiesSize: number;
|
|
70
|
+
totalCrowns: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type ScoreResult = {
|
|
74
|
+
playerId: string;
|
|
75
|
+
playerName: string;
|
|
76
|
+
details: Score;
|
|
77
|
+
};
|
|
78
|
+
type FinalResult = ScoreResult & {
|
|
79
|
+
position: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type Resp = {
|
|
83
|
+
nextKing: string;
|
|
84
|
+
nextAction: "pick" | "place" | "end";
|
|
85
|
+
game: Game;
|
|
86
|
+
};
|
|
87
|
+
type GameResult = {
|
|
88
|
+
result: FinalResult[];
|
|
89
|
+
game: Game;
|
|
90
|
+
};
|
|
91
|
+
/** Todo
|
|
92
|
+
* Add rules step
|
|
93
|
+
*
|
|
94
|
+
**/
|
|
95
|
+
declare const gameEngine: () => {
|
|
96
|
+
init: () => Game;
|
|
97
|
+
getMode: () => readonly ["Classic"];
|
|
98
|
+
setMode: (mode: string, game: Game) => Game;
|
|
99
|
+
getRules: (mode: string) => never[];
|
|
100
|
+
setRules: (rules: string[], game: Game) => Game;
|
|
101
|
+
start: (game: Game, players: {
|
|
102
|
+
name: string;
|
|
103
|
+
}[]) => Resp;
|
|
104
|
+
pass: (game: Game, kingId: string) => Resp;
|
|
105
|
+
placeDomino: (game: Game, kingId: string, position: Position, orientation: Orientation, rotation: Rotation) => Resp;
|
|
106
|
+
pickDomino: (game: Game, kingId: string, dominoPick: number) => Resp;
|
|
107
|
+
endGame: (game: Game) => GameResult;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { gameEngine as default };
|