All files / web/src/arcade-games/memory-quiz index.ts

67.25% Statements 76/113
100% Branches 0/0
0% Functions 0/1
67.25% Lines 76/113

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 1141x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                           1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Memory Quiz (Memory Lightning) Game Definition
 *
 * A memory game where players memorize soroban numbers and recall them.
 * Supports both cooperative and competitive multiplayer modes.
 */
 
import { defineGame, getGameTheme } from '@/lib/arcade/game-sdk'
import type { GameManifest } from '@/lib/arcade/game-sdk'
import { MemoryQuizGame } from './components/MemoryQuizGame'
import { MemoryQuizProvider } from './Provider'
import type { MemoryQuizConfig, MemoryQuizMove, MemoryQuizState } from './types'
import { memoryQuizGameValidator } from './Validator'
 
const manifest: GameManifest = {
  name: 'memory-quiz',
  displayName: 'Memory Lightning',
  icon: '🧠',
  description: 'Memorize soroban numbers and recall them',
  longDescription:
    'Test your memory by studying soroban numbers for a brief time, then recall as many as you can. ' +
    'Choose your difficulty level, number of cards, and display time. Play cooperatively with friends or compete for the highest score!',
  maxPlayers: 8,
  difficulty: 'Intermediate',
  chips: ['👥 Multiplayer', '🧠 Memory', '🧮 Soroban'],
  ...getGameTheme('purple'),
  available: true,
  practiceBreakReady: true,
  practiceBreakConfig: {
    suggestedConfig: {
      selectedCount: 5,
      displayTime: 2.0,
      selectedDifficulty: 'easy',
      playMode: 'cooperative', // Solo = cooperative with one player
    },
    lockedFields: ['playMode'], // Keep it solo for practice breaks
    minDurationMinutes: 1,
    maxDurationMinutes: 5,
    difficultyPresets: {
      easy: {
        selectedCount: 5,
        displayTime: 2.5,
        selectedDifficulty: 'beginner',
      },
      medium: {
        selectedCount: 5,
        displayTime: 2.0,
        selectedDifficulty: 'easy',
      },
      hard: {
        selectedCount: 8,
        displayTime: 1.5,
        selectedDifficulty: 'medium',
      },
    },
  },
  coPlay: { mode: 'drop-in' },
}
 
const defaultConfig: MemoryQuizConfig = {
  selectedCount: 5,
  displayTime: 2.0,
  selectedDifficulty: 'easy',
  playMode: 'cooperative',
}
 
// Config validation function
function validateMemoryQuizConfig(config: unknown): config is MemoryQuizConfig {
  if (typeof config !== 'object' || config === null) {
    return false
  }

  const c = config as any

  // Validate selectedCount
  if (!('selectedCount' in c) || ![2, 5, 8, 12, 15].includes(c.selectedCount)) {
    return false
  }

  // Validate displayTime
  if (
    !('displayTime' in c) ||
    typeof c.displayTime !== 'number' ||
    c.displayTime < 0.5 ||
    c.displayTime > 10
  ) {
    return false
  }

  // Validate selectedDifficulty
  if (
    !('selectedDifficulty' in c) ||
    !['beginner', 'easy', 'medium', 'hard', 'expert'].includes(c.selectedDifficulty)
  ) {
    return false
  }

  // Validate playMode
  if (!('playMode' in c) || !['cooperative', 'competitive'].includes(c.playMode)) {
    return false
  }

  return true
}
 
export const memoryQuizGame = defineGame<MemoryQuizConfig, MemoryQuizState, MemoryQuizMove>({
  manifest,
  Provider: MemoryQuizProvider,
  GameComponent: MemoryQuizGame,
  validator: memoryQuizGameValidator,
  defaultConfig,
  validateConfig: validateMemoryQuizConfig,
})