t3core 1.0.0
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 +69 -0
- package/dist/eslint.config.d.mts +2 -0
- package/dist/eslint.config.mjs +86 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/src/app.d.ts +1 -0
- package/dist/src/app.js +9 -0
- package/dist/src/core/Board.d.ts +34 -0
- package/dist/src/core/Board.js +51 -0
- package/dist/src/core/Game.d.ts +42 -0
- package/dist/src/core/Game.js +83 -0
- package/dist/src/core/constants/index.d.ts +2 -0
- package/dist/src/core/constants/index.js +14 -0
- package/dist/src/core/index.d.ts +30 -0
- package/dist/src/core/index.js +14 -0
- package/dist/src/core/tests/gameCore.test.d.ts +1 -0
- package/dist/src/core/tests/gameCore.test.js +50 -0
- package/dist/src/core/tests/getWinnerFromFields.test.d.ts +1 -0
- package/dist/src/core/tests/getWinnerFromFields.test.js +24 -0
- package/dist/src/core/types/Board.d.ts +9 -0
- package/dist/src/core/types/Board.js +2 -0
- package/dist/src/core/types/Game.d.ts +21 -0
- package/dist/src/core/types/Game.js +2 -0
- package/dist/src/core/types/Symbol.d.ts +3 -0
- package/dist/src/core/types/Symbol.js +2 -0
- package/dist/src/core/utils/getWinnerFromFields.d.ts +2 -0
- package/dist/src/core/utils/getWinnerFromFields.js +16 -0
- package/dist/src/ui/components/Header/Header.d.ts +1 -0
- package/dist/src/ui/components/Header/Header.js +20 -0
- package/dist/src/ui/components/Header/index.d.ts +1 -0
- package/dist/src/ui/components/Header/index.js +17 -0
- package/dist/src/ui/components/UserInput/UserInput.d.ts +2 -0
- package/dist/src/ui/components/UserInput/UserInput.js +20 -0
- package/dist/src/ui/components/UserInput/index.d.ts +1 -0
- package/dist/src/ui/components/UserInput/index.js +17 -0
- package/dist/src/ui/features/game/components/Board/Board.d.ts +1 -0
- package/dist/src/ui/features/game/components/Board/Board.js +21 -0
- package/dist/src/ui/features/game/components/Board/index.d.ts +1 -0
- package/dist/src/ui/features/game/components/Board/index.js +17 -0
- package/dist/src/ui/features/game/components/GameEntryMessage/GameEntryMessage.d.ts +1 -0
- package/dist/src/ui/features/game/components/GameEntryMessage/GameEntryMessage.js +22 -0
- package/dist/src/ui/features/game/components/GameEntryMessage/index.d.ts +1 -0
- package/dist/src/ui/features/game/components/GameEntryMessage/index.js +17 -0
- package/dist/src/ui/features/game/components/GameHeader/GameHeader.d.ts +1 -0
- package/dist/src/ui/features/game/components/GameHeader/GameHeader.js +17 -0
- package/dist/src/ui/features/game/components/GameHeader/index.d.ts +1 -0
- package/dist/src/ui/features/game/components/GameHeader/index.js +17 -0
- package/dist/src/ui/features/game/components/GameStatusMessage/GameStatusMessage.d.ts +1 -0
- package/dist/src/ui/features/game/components/GameStatusMessage/GameStatusMessage.js +28 -0
- package/dist/src/ui/features/game/components/GameStatusMessage/index.d.ts +1 -0
- package/dist/src/ui/features/game/components/GameStatusMessage/index.js +17 -0
- package/dist/src/ui/features/game/components/PlayerEntry/PlayerEntry.d.ts +1 -0
- package/dist/src/ui/features/game/components/PlayerEntry/PlayerEntry.js +37 -0
- package/dist/src/ui/features/game/components/PlayerEntry/index.d.ts +1 -0
- package/dist/src/ui/features/game/components/PlayerEntry/index.js +17 -0
- package/dist/src/ui/features/game/components/PlayerEntry/utils/getPlayerAnswer.d.ts +1 -0
- package/dist/src/ui/features/game/components/PlayerEntry/utils/getPlayerAnswer.js +34 -0
- package/dist/src/ui/features/game/components/PlayerEntry/utils/playAgain.d.ts +1 -0
- package/dist/src/ui/features/game/components/PlayerEntry/utils/playAgain.js +20 -0
- package/dist/src/ui/features/game/components/PlayerEntry/utils/validatePlayerEntry.d.ts +1 -0
- package/dist/src/ui/features/game/components/PlayerEntry/utils/validatePlayerEntry.js +18 -0
- package/dist/src/ui/features/game/services/gameSession.d.ts +3 -0
- package/dist/src/ui/features/game/services/gameSession.js +19 -0
- package/dist/src/ui/features/game/util/colorLabelSymbol.d.ts +2 -0
- package/dist/src/ui/features/game/util/colorLabelSymbol.js +15 -0
- package/dist/src/ui/features/menu/components/MenuEntry/MenuEntry.d.ts +1 -0
- package/dist/src/ui/features/menu/components/MenuEntry/MenuEntry.js +36 -0
- package/dist/src/ui/features/menu/components/MenuEntry/index.d.ts +1 -0
- package/dist/src/ui/features/menu/components/MenuEntry/index.js +17 -0
- package/dist/src/ui/features/menu/components/MenuHeader/MenuHeader.d.ts +1 -0
- package/dist/src/ui/features/menu/components/MenuHeader/MenuHeader.js +18 -0
- package/dist/src/ui/features/menu/components/MenuHeader/index.d.ts +1 -0
- package/dist/src/ui/features/menu/components/MenuHeader/index.js +17 -0
- package/dist/src/ui/features/menu/components/MenuOptions/MenuOptions.d.ts +1 -0
- package/dist/src/ui/features/menu/components/MenuOptions/MenuOptions.js +18 -0
- package/dist/src/ui/features/menu/components/MenuOptions/index.d.ts +1 -0
- package/dist/src/ui/features/menu/components/MenuOptions/index.js +17 -0
- package/dist/src/ui/features/menu/constants/menuItems.d.ts +4 -0
- package/dist/src/ui/features/menu/constants/menuItems.js +8 -0
- package/dist/src/ui/features/settings/components/SettingsEntry/SettingsEntry.d.ts +1 -0
- package/dist/src/ui/features/settings/components/SettingsEntry/SettingsEntry.js +42 -0
- package/dist/src/ui/features/settings/components/SettingsEntry/index.d.ts +1 -0
- package/dist/src/ui/features/settings/components/SettingsEntry/index.js +17 -0
- package/dist/src/ui/features/settings/components/SettingsHeader/SettingsHeader.d.ts +1 -0
- package/dist/src/ui/features/settings/components/SettingsHeader/SettingsHeader.js +18 -0
- package/dist/src/ui/features/settings/components/SettingsHeader/index.d.ts +1 -0
- package/dist/src/ui/features/settings/components/SettingsHeader/index.js +17 -0
- package/dist/src/ui/features/settings/components/SettingsOptions/SettingsOptions.d.ts +1 -0
- package/dist/src/ui/features/settings/components/SettingsOptions/SettingsOptions.js +34 -0
- package/dist/src/ui/features/settings/components/SettingsOptions/index.d.ts +1 -0
- package/dist/src/ui/features/settings/components/SettingsOptions/index.js +17 -0
- package/dist/src/ui/features/settings/constants/settingsOptions.d.ts +8 -0
- package/dist/src/ui/features/settings/constants/settingsOptions.js +7 -0
- package/dist/src/ui/global/settings.global.d.ts +12 -0
- package/dist/src/ui/global/settings.global.js +24 -0
- package/dist/src/ui/navigation/index.d.ts +3 -0
- package/dist/src/ui/navigation/index.js +27 -0
- package/dist/src/ui/navigation/routes.d.ts +6 -0
- package/dist/src/ui/navigation/routes.js +8 -0
- package/dist/src/ui/screens/Game.screen.d.ts +1 -0
- package/dist/src/ui/screens/Game.screen.js +20 -0
- package/dist/src/ui/screens/Menu.screen.d.ts +1 -0
- package/dist/src/ui/screens/Menu.screen.js +25 -0
- package/dist/src/ui/screens/Settings.screen.d.ts +1 -0
- package/dist/src/ui/screens/Settings.screen.js +16 -0
- package/dist/src/ui/utils/beepAndClear.d.ts +1 -0
- package/dist/src/ui/utils/beepAndClear.js +9 -0
- package/dist/src/ui/utils/beepSound.d.ts +1 -0
- package/dist/src/ui/utils/beepSound.js +10 -0
- package/dist/src/ui/utils/styledLabel.d.ts +9 -0
- package/dist/src/ui/utils/styledLabel.js +76 -0
- package/dist/vitest.config.d.mts +2 -0
- package/dist/vitest.config.mjs +6 -0
- package/package.json +59 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.closeInput = exports.UserInput = void 0;
|
|
7
|
+
const readline_1 = __importDefault(require("readline"));
|
|
8
|
+
// terminal communication interface
|
|
9
|
+
const rl = readline_1.default.createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout,
|
|
12
|
+
});
|
|
13
|
+
const UserInput = (query) => {
|
|
14
|
+
return new Promise((resolve) => rl.question(query, resolve));
|
|
15
|
+
};
|
|
16
|
+
exports.UserInput = UserInput;
|
|
17
|
+
const closeInput = () => {
|
|
18
|
+
rl.close();
|
|
19
|
+
};
|
|
20
|
+
exports.closeInput = closeInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UserInput";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./UserInput"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Board: () => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Board = void 0;
|
|
4
|
+
const gameSession_1 = require("../../../../../ui/features/game/services/gameSession");
|
|
5
|
+
const colorLabelSymbol_1 = require("../../../../../ui/features/game/util/colorLabelSymbol");
|
|
6
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
7
|
+
const borderStyle = { color: "grey", textStyle: "bold" };
|
|
8
|
+
const Board = () => {
|
|
9
|
+
const game = (0, gameSession_1.getGame)();
|
|
10
|
+
const fields = game.getBoard();
|
|
11
|
+
const border = (0, styledLabel_1.styledLabel)("-------------", borderStyle);
|
|
12
|
+
const fieldBorder = (0, styledLabel_1.styledLabel)("|", borderStyle);
|
|
13
|
+
console.log(border);
|
|
14
|
+
fields.forEach((i, idx) => {
|
|
15
|
+
if (idx % 3 === 0) {
|
|
16
|
+
console.log(`${fieldBorder} ${(0, colorLabelSymbol_1.colorLabelSymbol)(i)} ${fieldBorder} ${(0, colorLabelSymbol_1.colorLabelSymbol)(fields[idx + 1])} ${fieldBorder} ${(0, colorLabelSymbol_1.colorLabelSymbol)(fields[idx + 2])} ${fieldBorder}`);
|
|
17
|
+
console.log(border);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.Board = Board;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Board";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Board"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GameEntryMessage: () => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GameEntryMessage = void 0;
|
|
4
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
5
|
+
const GameEntryMessage = () => {
|
|
6
|
+
const border = (0, styledLabel_1.styledLabel)("--------------------------------------------", {
|
|
7
|
+
color: "yellow",
|
|
8
|
+
});
|
|
9
|
+
console.log(border);
|
|
10
|
+
const gameEntryMessage = (0, styledLabel_1.styledLabel)(`Tic-tac-toe is a simple two-player game
|
|
11
|
+
played on a 3×3 grid. Players take turns
|
|
12
|
+
marking a square with X or O, trying to get
|
|
13
|
+
three in a row horizontally, vertically,
|
|
14
|
+
or diagonally.
|
|
15
|
+
|
|
16
|
+
The game ends when one player wins or all
|
|
17
|
+
squares are filled, resulting in a draw.`, { textStyle: "italic", color: "grey" });
|
|
18
|
+
console.log(gameEntryMessage);
|
|
19
|
+
console.log(border);
|
|
20
|
+
console.log(`\t`);
|
|
21
|
+
};
|
|
22
|
+
exports.GameEntryMessage = GameEntryMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./GameEntryMessage";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./GameEntryMessage"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GameHeader: () => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GameHeader = void 0;
|
|
4
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
5
|
+
const GameHeader = () => {
|
|
6
|
+
console.log("\t");
|
|
7
|
+
const mainMenuLabel = (0, styledLabel_1.styledLabel)("GAME", {
|
|
8
|
+
color: "red",
|
|
9
|
+
textStyle: "bold",
|
|
10
|
+
});
|
|
11
|
+
const border = (0, styledLabel_1.styledLabel)("===================", {
|
|
12
|
+
color: "green",
|
|
13
|
+
textStyle: "dim",
|
|
14
|
+
});
|
|
15
|
+
console.log(`${border} ${mainMenuLabel} ${border}`);
|
|
16
|
+
};
|
|
17
|
+
exports.GameHeader = GameHeader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./GameHeader";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./GameHeader"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GameStatusMessage: () => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GameStatusMessage = void 0;
|
|
4
|
+
const gameSession_1 = require("../../../../../ui/features/game/services/gameSession");
|
|
5
|
+
const colorLabelSymbol_1 = require("../../../../../ui/features/game/util/colorLabelSymbol");
|
|
6
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
7
|
+
const textStyle = { color: "lightWhite" };
|
|
8
|
+
function messageForGameStatus(gameStatus) {
|
|
9
|
+
switch (gameStatus.status) {
|
|
10
|
+
case "running":
|
|
11
|
+
return undefined;
|
|
12
|
+
case "draw":
|
|
13
|
+
return (0, styledLabel_1.styledLabel)("The game is a draw 🤝", textStyle).toString();
|
|
14
|
+
case "win":
|
|
15
|
+
return `${(0, styledLabel_1.styledLabel)("Player", textStyle).toString()} ${(0, colorLabelSymbol_1.colorLabelSymbol)(gameStatus.winner)} ${(0, styledLabel_1.styledLabel)("wins! 🎉", textStyle).toString()}`;
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(`Unknown game status: ${gameStatus}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const GameStatusMessage = () => {
|
|
21
|
+
const line = messageForGameStatus((0, gameSession_1.getGame)().gameStatus);
|
|
22
|
+
if (line === undefined) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
console.log("\t");
|
|
26
|
+
console.log(line);
|
|
27
|
+
};
|
|
28
|
+
exports.GameStatusMessage = GameStatusMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./GameStatusMessage";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./GameStatusMessage"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PlayerEntry: (callback: () => void) => Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PlayerEntry = void 0;
|
|
13
|
+
const gameSession_1 = require("../../../../../ui/features/game/services/gameSession");
|
|
14
|
+
const colorLabelSymbol_1 = require("../../../../../ui/features/game/util/colorLabelSymbol");
|
|
15
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
16
|
+
const getPlayerAnswer_1 = require("./utils/getPlayerAnswer");
|
|
17
|
+
const playAgain_1 = require("./utils/playAgain");
|
|
18
|
+
const PlayerEntry = (callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const game = (0, gameSession_1.getGame)();
|
|
20
|
+
if (game.gameStatus.status !== "running") {
|
|
21
|
+
yield (0, playAgain_1.playAgain)();
|
|
22
|
+
callback();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
console.log(`\t`);
|
|
26
|
+
console.log(`${(0, styledLabel_1.styledLabel)("Player:", { textStyle: "underline", color: "white" })} (${(0, colorLabelSymbol_1.colorLabelSymbol)(game.currentPlayer)})`);
|
|
27
|
+
console.log(`\t`);
|
|
28
|
+
console.log(`${(0, styledLabel_1.styledLabel)("Select the number of the field (1-9)", { color: "white" })}`);
|
|
29
|
+
console.log(`${(0, styledLabel_1.styledLabel)('Press "q" to back to the main menu', { textStyle: "dim" })}`);
|
|
30
|
+
console.log(`\t`);
|
|
31
|
+
const answer = yield (0, getPlayerAnswer_1.getPlayerAnswer)();
|
|
32
|
+
if (answer == null)
|
|
33
|
+
return;
|
|
34
|
+
game.savePlayerSelection(answer);
|
|
35
|
+
callback();
|
|
36
|
+
});
|
|
37
|
+
exports.PlayerEntry = PlayerEntry;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PlayerEntry";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PlayerEntry"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPlayerAnswer: () => Promise<number | null>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getPlayerAnswer = void 0;
|
|
13
|
+
const UserInput_1 = require("../../../../../../ui/components/UserInput");
|
|
14
|
+
const navigation_1 = require("../../../../../../ui/navigation");
|
|
15
|
+
const styledLabel_1 = require("../../../../../../ui/utils/styledLabel");
|
|
16
|
+
const gameSession_1 = require("../../../services/gameSession");
|
|
17
|
+
const validatePlayerEntry_1 = require("./validatePlayerEntry");
|
|
18
|
+
const getPlayerAnswer = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const question = (0, styledLabel_1.styledLabel)("Your choice: ", {
|
|
20
|
+
color: "yellow",
|
|
21
|
+
});
|
|
22
|
+
const answer = yield (0, UserInput_1.UserInput)(question.toString());
|
|
23
|
+
if (answer === "q") {
|
|
24
|
+
(0, navigation_1.goToMenu)();
|
|
25
|
+
(0, gameSession_1.resetGame)();
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const answerNumeric = Number(answer);
|
|
29
|
+
if ((0, validatePlayerEntry_1.validatePlayerEntry)(answerNumeric)) {
|
|
30
|
+
return answerNumeric;
|
|
31
|
+
}
|
|
32
|
+
return yield (0, exports.getPlayerAnswer)();
|
|
33
|
+
});
|
|
34
|
+
exports.getPlayerAnswer = getPlayerAnswer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const playAgain: () => Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.playAgain = void 0;
|
|
13
|
+
const UserInput_1 = require("../../../../../../ui/components/UserInput");
|
|
14
|
+
const gameSession_1 = require("../../../../../../ui/features/game/services/gameSession");
|
|
15
|
+
const playAgain = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
console.log(`\t`);
|
|
17
|
+
yield (0, UserInput_1.UserInput)("Press enter to play again ");
|
|
18
|
+
(0, gameSession_1.resetGame)();
|
|
19
|
+
});
|
|
20
|
+
exports.playAgain = playAgain;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validatePlayerEntry: (field: number) => boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePlayerEntry = void 0;
|
|
4
|
+
const Board_1 = require("../../../../../../core/Board");
|
|
5
|
+
const gameSession_1 = require("../../../../../../ui/features/game/services/gameSession");
|
|
6
|
+
const validatePlayerEntry = (field) => {
|
|
7
|
+
const isFieldOutOfRange = field < 1 || field > Board_1.BOARD_SIZE;
|
|
8
|
+
if (!field || isFieldOutOfRange) {
|
|
9
|
+
console.log("Please enter a valid number (1-9) and press enter");
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if ((0, gameSession_1.getGame)().isFieldSelected(field)) {
|
|
13
|
+
console.log("Field already selected");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
exports.validatePlayerEntry = validatePlayerEntry;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetGame = exports.getGame = void 0;
|
|
4
|
+
const Game_1 = require("../../../../core/Game");
|
|
5
|
+
let game = null;
|
|
6
|
+
const createNewGame = () => {
|
|
7
|
+
return new Game_1.Game();
|
|
8
|
+
};
|
|
9
|
+
const getGame = () => {
|
|
10
|
+
if (!game) {
|
|
11
|
+
game = createNewGame();
|
|
12
|
+
}
|
|
13
|
+
return game;
|
|
14
|
+
};
|
|
15
|
+
exports.getGame = getGame;
|
|
16
|
+
const resetGame = () => {
|
|
17
|
+
(0, exports.getGame)().reset();
|
|
18
|
+
};
|
|
19
|
+
exports.resetGame = resetGame;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.colorLabelSymbol = void 0;
|
|
4
|
+
const constants_1 = require("../../../../core/constants");
|
|
5
|
+
const colorCodes = new Map([
|
|
6
|
+
[constants_1.DEFAULT_GAME_SYMBOLS[0], 32],
|
|
7
|
+
[constants_1.DEFAULT_GAME_SYMBOLS[1], 31],
|
|
8
|
+
]);
|
|
9
|
+
const colorLabelSymbol = (label) => {
|
|
10
|
+
if (typeof label === "number")
|
|
11
|
+
return `\x1b[90m${label}\x1b[0m`;
|
|
12
|
+
const colorCode = colorCodes.get(label);
|
|
13
|
+
return `\x1b[1;${colorCode}m${label}\x1b[0m`;
|
|
14
|
+
};
|
|
15
|
+
exports.colorLabelSymbol = colorLabelSymbol;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MenuEntry: () => Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MenuEntry = void 0;
|
|
13
|
+
const UserInput_1 = require("../../../../../ui/components/UserInput");
|
|
14
|
+
const navigation_1 = require("../../../../../ui/navigation");
|
|
15
|
+
const routes_1 = require("../../../../../ui/navigation/routes");
|
|
16
|
+
const beepSound_1 = require("../../../../../ui/utils/beepSound");
|
|
17
|
+
const MenuEntry = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
console.log("\t");
|
|
19
|
+
const answer = yield (0, UserInput_1.UserInput)("Enter your choice (1-3): ");
|
|
20
|
+
if (answer === "1") {
|
|
21
|
+
(0, navigation_1.navigateTo)(routes_1.ROUTES.GAME);
|
|
22
|
+
}
|
|
23
|
+
else if (answer === "2") {
|
|
24
|
+
(0, navigation_1.navigateTo)(routes_1.ROUTES.SETTINGS);
|
|
25
|
+
}
|
|
26
|
+
else if (answer === "3") {
|
|
27
|
+
(0, UserInput_1.closeInput)();
|
|
28
|
+
(0, beepSound_1.beepSound)();
|
|
29
|
+
console.log("Exiting the app");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
(0, navigation_1.goToMenu)();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.MenuEntry = MenuEntry;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./MenuEntry";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./MenuEntry"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MenuHeader: () => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MenuHeader = void 0;
|
|
4
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
5
|
+
const MenuHeader = () => {
|
|
6
|
+
console.log("\t");
|
|
7
|
+
const mainMenuLabel = (0, styledLabel_1.styledLabel)("MAIN MENU", {
|
|
8
|
+
color: "red",
|
|
9
|
+
textStyle: "bold",
|
|
10
|
+
});
|
|
11
|
+
const border = (0, styledLabel_1.styledLabel)("================", {
|
|
12
|
+
color: "yellow",
|
|
13
|
+
textStyle: "dim",
|
|
14
|
+
});
|
|
15
|
+
console.log(`${border} ${mainMenuLabel} ${border}`);
|
|
16
|
+
console.log("\t");
|
|
17
|
+
};
|
|
18
|
+
exports.MenuHeader = MenuHeader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./MenuHeader";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./MenuHeader"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MenuOptions: () => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MenuOptions = void 0;
|
|
4
|
+
const styledLabel_1 = require("../../../../../ui/utils/styledLabel");
|
|
5
|
+
const menuItems_1 = require("../../constants/menuItems");
|
|
6
|
+
const MenuOptions = () => {
|
|
7
|
+
menuItems_1.MENU_ITEMS.forEach((item) => {
|
|
8
|
+
const itemNumber = (0, styledLabel_1.styledLabel)(item.id, {
|
|
9
|
+
color: "lightYellow",
|
|
10
|
+
textStyle: "bold",
|
|
11
|
+
});
|
|
12
|
+
const itemLabel = (0, styledLabel_1.styledLabel)(item.label, {
|
|
13
|
+
color: "lightBlue",
|
|
14
|
+
});
|
|
15
|
+
console.log(`[${itemNumber}] ${itemLabel}`);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.MenuOptions = MenuOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./MenuOptions";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./MenuOptions"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SettingsEntry: () => Promise<void>;
|