feat: added features, refactored code, updated readme

This commit is contained in:
2025-11-21 16:41:16 +01:00
parent 64119550f0
commit 19f0ccb126
4 changed files with 87 additions and 59 deletions

53
ui.ts
View File

@@ -72,11 +72,11 @@ export async function selectGameMode(): Promise<GameMode> {
value: "full",
},
{
name: `${colors.cyan("Challenge")} - Words`,
name: `${colors.cyan("Challenge")} - Words (3-8 letters 🥵)`,
value: "words",
},
{
name: `${colors.red("Expert")} - Phrases`,
name: `${colors.red("Expert")} - Phrases (2-4 words 🤯)`,
value: "phrases",
},
],
@@ -244,9 +244,9 @@ export async function playRound(
// Longer wait time for words and phrases
let waitTime = 2000; // Default: 2 seconds
if (session.config.mode === "words") {
waitTime = 4000; // 4 seconds for words
waitTime = 6000; // 6 seconds for words
} else if (session.config.mode === "phrases") {
waitTime = 6000; // 6 seconds for phrases
waitTime = 8000; // 8 seconds for phrases
}
// Wait for user to continue
@@ -266,16 +266,30 @@ export function showGameResults(session: GameSession): void {
console.log(colors.bold.cyan("\n🎮 GAME COMPLETE!\n"));
const tableBody: string[][] = [
["Total Rounds", summary.totalRounds.toString()],
["Correct", colors.green(summary.correct.toString())],
["Incorrect", colors.red(summary.incorrect.toString())],
["Accuracy", `${summary.accuracy.toFixed(1)}%`],
["Average Time", `${(summary.averageTime / 1000).toFixed(1)}s`],
];
// Add average time per character for words/phrases modes
if (session.config.mode === "words" || session.config.mode === "phrases") {
const totalChars = session.results.reduce(
(sum, r) => sum + r.challenge.length,
0
);
const totalTime = session.results.reduce((sum, r) => sum + r.timeSpent, 0);
const avgTimePerChar = totalChars > 0 ? totalTime / totalChars / 1000 : 0;
tableBody.push(["Avg Time/Char", `${avgTimePerChar.toFixed(2)}s`]);
}
tableBody.push(["Best Streak", colors.yellow(summary.streak.toString())]);
const table = new Table()
.header([colors.bold("Metric"), colors.bold("Value")])
.body([
["Total Rounds", summary.totalRounds.toString()],
["Correct", colors.green(summary.correct.toString())],
["Incorrect", colors.red(summary.incorrect.toString())],
["Accuracy", `${summary.accuracy.toFixed(1)}%`],
["Average Time", `${(summary.averageTime / 1000).toFixed(1)}s`],
["Best Streak", colors.yellow(summary.streak.toString())],
])
.body(tableBody)
.border(true)
.padding(1);
@@ -289,16 +303,31 @@ export function showGameResults(session: GameSession): void {
colors.bold("Challenge"),
colors.bold("Expected"),
colors.bold("Your Answer"),
colors.bold("Translates To"),
colors.bold("Result"),
colors.bold("Time"),
]);
session.results.forEach((result, index) => {
// Try to decode the user's morse input
let translation = "-";
if (result.userInput && result.userInput.trim()) {
try {
const decoded = morseToText(result.userInput);
if (decoded && decoded !== result.userInput) {
translation = decoded;
}
} catch {
translation = "?";
}
}
detailsTable.push([
(index + 1).toString(),
result.challenge,
result.expectedMorse,
result.userInput || "-",
translation,
result.correct ? colors.green("✓") : colors.red("✗"),
`${(result.timeSpent / 1000).toFixed(1)}s`,
]);