All files / web/src/arcade-games/type-racer-jr/components TypeRacerGame.tsx

0% Statements 0/194
0% Branches 0/1
0% Functions 0/1
0% Lines 0/194

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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195                                                                                                                                                                                                                                                                                                                                                                                                     
'use client'

import Link from 'next/link'
import { useRouter } from 'next/navigation'
import { PageWithNav } from '@/components/PageWithNav'
import { useGameLayoutMode } from '@/contexts/GameLayoutContext'
import { css } from '../../../../styled-system/css'
import { useTypeRacerJr } from '../Provider'
import { SetupPhase } from './SetupPhase'
import { PlayingPhase } from './PlayingPhase'
import { ResultsPhase } from './ResultsPhase'

// CSS animations
const globalAnimations = `
@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 0 8px rgba(59, 130, 246, 0.2); }
  50% { transform: scale(1.05); box-shadow: 0 0 16px rgba(59, 130, 246, 0.4); }
  100% { transform: scale(1); box-shadow: 0 0 8px rgba(59, 130, 246, 0.2); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes bounceIn {
  0% { opacity: 0; transform: scale(0.3); }
  50% { transform: scale(1.1); }
  70% { transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}
`

export function TypeRacerGame() {
  const router = useRouter()
  const { state, exitSession, resetGame } = useTypeRacerJr()
  const layoutMode = useGameLayoutMode()

  const phaseContent = (
    <>
      {state.gamePhase === 'setup' && <SetupPhase />}
      {state.gamePhase === 'playing' && <PlayingPhase />}
      {state.gamePhase === 'results' && <ResultsPhase />}
    </>
  )

  // Container mode (practice game break)
  if (layoutMode === 'container') {
    return (
      <div
        style={{
          flex: 1,
          display: 'flex',
          flexDirection: 'column',
          overflow: 'auto',
          background: 'linear-gradient(135deg, #fffbeb, #fef3c7)',
        }}
      >
        <style dangerouslySetInnerHTML={{ __html: globalAnimations }} />
        <div
          className={css({
            bg: 'white',
            rounded: 'xl',
            shadow: 'xl',
            overflow: 'hidden',
            border: '1px solid',
            borderColor: 'orange.200',
            flex: 1,
            display: 'flex',
            flexDirection: 'column',
            m: '2',
          })}
        >
          <div
            className={css({
              flex: 1,
              display: 'flex',
              flexDirection: 'column',
              overflow: 'auto',
            })}
          >
            {phaseContent}
          </div>
        </div>
      </div>
    )
  }

  // Full mode with nav
  return (
    <PageWithNav
      navTitle="Type Racer Jr."
      navEmoji="⌨️"
      emphasizePlayerSelection={state.gamePhase === 'setup'}
      onExitSession={() => {
        exitSession?.()
        router.push('/arcade')
      }}
      onNewGame={() => {
        resetGame?.()
      }}
    >
      <style dangerouslySetInnerHTML={{ __html: globalAnimations }} />

      <div
        style={{
          flex: 1,
          display: 'flex',
          flexDirection: 'column',
          overflow: 'auto',
          padding: '20px 8px',
          minHeight: '100vh',
          background: 'linear-gradient(135deg, #fffbeb, #fef3c7)',
        }}
      >
        <div
          style={{
            maxWidth: '100%',
            margin: '0 auto',
            flex: 1,
            display: 'flex',
            flexDirection: 'column',
          }}
        >
          <div
            className={css({
              textAlign: 'center',
              mb: '4',
              flexShrink: 0,
            })}
          >
            <Link
              href="/arcade"
              className={css({
                display: 'inline-flex',
                alignItems: 'center',
                color: 'gray.600',
                textDecoration: 'none',
                mb: '4',
                _hover: { color: 'gray.800' },
              })}
            >
              ← Back to Champion Arena
            </Link>
          </div>

          <div
            className={css({
              bg: 'white',
              rounded: 'xl',
              shadow: 'xl',
              overflow: 'hidden',
              border: '1px solid',
              borderColor: 'orange.200',
              flex: 1,
              display: 'flex',
              flexDirection: 'column',
              maxHeight: '100%',
            })}
          >
            <div
              className={css({
                flex: 1,
                display: 'flex',
                flexDirection: 'column',
                overflow: 'auto',
              })}
            >
              {phaseContent}
            </div>
          </div>
        </div>
      </div>
    </PageWithNav>
  )
}