feat(arcade): register Math Sprint in game system

Register math-sprint in all required places:
- validators.ts: Add mathSprintValidator to registry
- game-registry.ts: Register mathSprintGame
- game-configs.ts: Add MathSprintGameConfig type and defaults
- game-config-helpers.ts: Add config getters and validation

This demonstrates the boilerplate issue documented in AUDIT_2:
Had to update 4 files with switch/case statements and type definitions.

Addresses issue #2 and #3 from architecture audit.
This commit is contained in:
Thomas Hallock
2025-10-15 21:11:03 -05:00
parent e5be09ef5f
commit 0c05a7c6bb
4 changed files with 43 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ import {
DEFAULT_MEMORY_QUIZ_CONFIG,
DEFAULT_COMPLEMENT_RACE_CONFIG,
DEFAULT_NUMBER_GUESSER_CONFIG,
DEFAULT_MATH_SPRINT_CONFIG,
} from './game-configs'
/**
@@ -36,6 +37,8 @@ function getDefaultGameConfig(gameName: ExtendedGameName): GameConfigByName[Exte
return DEFAULT_COMPLEMENT_RACE_CONFIG
case 'number-guesser':
return DEFAULT_NUMBER_GUESSER_CONFIG
case 'math-sprint':
return DEFAULT_MATH_SPRINT_CONFIG
default:
throw new Error(`Unknown game: ${gameName}`)
}
@@ -215,6 +218,18 @@ export function validateGameConfig(gameName: ExtendedGameName, config: any): boo
config.roundsToWin >= 1
)
case 'math-sprint':
return (
typeof config === 'object' &&
config !== null &&
['easy', 'medium', 'hard'].includes(config.difficulty) &&
typeof config.questionsPerRound === 'number' &&
typeof config.timePerQuestion === 'number' &&
config.questionsPerRound >= 5 &&
config.questionsPerRound <= 20 &&
config.timePerQuestion >= 10
)
default:
return false
}

View File

@@ -11,6 +11,7 @@
import type { DifficultyLevel } from '@/app/arcade/memory-quiz/types'
import type { Difficulty, GameType } from '@/app/games/matching/context/types'
import type { Difficulty as MathSprintDifficulty } from '@/arcade-games/math-sprint/types'
/**
* Configuration for matching (memory pairs) game
@@ -49,6 +50,15 @@ export interface NumberGuesserGameConfig {
roundsToWin: number
}
/**
* Configuration for math-sprint game
*/
export interface MathSprintGameConfig {
difficulty: MathSprintDifficulty
questionsPerRound: number
timePerQuestion: number
}
/**
* Union type of all game configs for type-safe access
*/
@@ -57,6 +67,7 @@ export type GameConfigByName = {
'memory-quiz': MemoryQuizGameConfig
'complement-race': ComplementRaceGameConfig
'number-guesser': NumberGuesserGameConfig
'math-sprint': MathSprintGameConfig
}
/**
@@ -68,6 +79,7 @@ export interface RoomGameConfig {
'memory-quiz'?: MemoryQuizGameConfig
'complement-race'?: ComplementRaceGameConfig
'number-guesser'?: NumberGuesserGameConfig
'math-sprint'?: MathSprintGameConfig
}
/**
@@ -95,3 +107,9 @@ export const DEFAULT_NUMBER_GUESSER_CONFIG: NumberGuesserGameConfig = {
maxNumber: 100,
roundsToWin: 3,
}
export const DEFAULT_MATH_SPRINT_CONFIG: MathSprintGameConfig = {
difficulty: 'medium',
questionsPerRound: 10,
timePerQuestion: 30,
}

View File

@@ -107,5 +107,7 @@ export function clearRegistry(): void {
// ============================================================================
import { numberGuesserGame } from '@/arcade-games/number-guesser'
import { mathSprintGame } from '@/arcade-games/math-sprint'
registerGame(numberGuesserGame)
registerGame(mathSprintGame)

View File

@@ -13,6 +13,7 @@
import { matchingGameValidator } from './validation/MatchingGameValidator'
import { memoryQuizGameValidator } from './validation/MemoryQuizGameValidator'
import { numberGuesserValidator } from '@/arcade-games/number-guesser/Validator'
import { mathSprintValidator } from '@/arcade-games/math-sprint/Validator'
import type { GameValidator } from './validation/types'
/**
@@ -24,6 +25,7 @@ export const validatorRegistry = {
matching: matchingGameValidator,
'memory-quiz': memoryQuizGameValidator,
'number-guesser': numberGuesserValidator,
'math-sprint': mathSprintValidator,
// Add new games here - GameName type will auto-update
} as const
@@ -65,4 +67,9 @@ export function getRegisteredGameNames(): GameName[] {
/**
* Re-export validators for backwards compatibility
*/
export { matchingGameValidator, memoryQuizGameValidator, numberGuesserValidator }
export {
matchingGameValidator,
memoryQuizGameValidator,
numberGuesserValidator,
mathSprintValidator,
}