Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/game-engine/controllers/practice-mode.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
import type { CreatePracticeSessionInput } from '../services/practice-mode.service';
import { PracticeModeService } from '../services/practice-mode.service';
import { DifficultyLevel } from '../types/puzzle.types';

@Controller('puzzles/practice')
export class PracticeModeController {
constructor(private readonly practiceMode: PracticeModeService) {}

@Post()
startPractice(@Body() input: CreatePracticeSessionInput) {
return this.practiceMode.startPractice(input);
}

@Post(':practiceSessionId/player/:playerId/attempts')
submitAttempt(
@Param('practiceSessionId') practiceSessionId: string,
@Param('playerId') playerId: string,
@Body() body: { answer: unknown },
) {
return this.practiceMode.submitAttempt(
practiceSessionId,
playerId,
body.answer,
);
}

@Get(':practiceSessionId/player/:playerId/progress')
getProgress(
@Param('practiceSessionId') practiceSessionId: string,
@Param('playerId') playerId: string,
) {
return this.practiceMode.getProgress(practiceSessionId, playerId);
}

@Get(':practiceSessionId/player/:playerId/hints/:level')
getHint(
@Param('practiceSessionId') practiceSessionId: string,
@Param('playerId') playerId: string,
@Param('level') level: string,
) {
return this.practiceMode.getHint(
practiceSessionId,
playerId,
Number(level),
);
}

@Post(':practiceSessionId/player/:playerId/replay')
replay(
@Param('practiceSessionId') practiceSessionId: string,
@Param('playerId') playerId: string,
) {
return this.practiceMode.replay(practiceSessionId, playerId);
}

@Patch(':practiceSessionId/player/:playerId/difficulty')
adjustDifficulty(
@Param('practiceSessionId') practiceSessionId: string,
@Param('playerId') playerId: string,
@Body() body: { difficulty: DifficultyLevel },
) {
return this.practiceMode.adjustDifficulty(
practiceSessionId,
playerId,
body.difficulty,
);
}

@Get('player/:playerId/analytics')
getPlayerAnalytics(@Param('playerId') playerId: string) {
return this.practiceMode.getPlayerAnalytics(playerId);
}
}
24 changes: 24 additions & 0 deletions src/game-engine/entities/practice-attempt.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryGeneratedColumn,
} from 'typeorm';

@Entity('practice_attempts')
@Index(['practiceSessionId', 'createdAt'])
export class PracticeAttempt {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
@Index()
practiceSessionId: string;

@Column({ type: 'boolean' })
isCorrect: boolean;

@CreateDateColumn({ type: 'timestamp with time zone' })
createdAt: Date;
}
69 changes: 69 additions & 0 deletions src/game-engine/entities/practice-session.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import type { DifficultyLevel, PuzzleType } from '../types/puzzle.types';

@Entity('practice_sessions')
@Index(['playerId', 'updatedAt'])
export class PracticeSession {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
@Index()
playerId: string;

@Column({ type: 'varchar', length: 255 })
@Index()
puzzleId: string;

@Column({ type: 'varchar', length: 50 })
puzzleType: PuzzleType;

@Column({ type: 'int' })
difficulty: DifficultyLevel;

@Column({ type: 'jsonb' })
content: Record<string, unknown>;

@Column({ type: 'jsonb' })
solution: unknown;

@Column({ type: 'jsonb', default: [] })
hints: string[];

@Column({ type: 'varchar', nullable: true })
solutionGuide?: string;

@Column({ type: 'int', default: 0 })
attemptsCount: number;

@Column({ type: 'int', default: 0 })
correctAttempts: number;

@Column({ type: 'int', default: 0 })
hintsRequested: number;

@Column({ type: 'int', default: 0 })
replays: number;

@Column({ type: 'int', default: 0 })
totalTimeSpent: number;

@Column({ type: 'boolean', default: false })
completed: boolean;

@Column({ type: 'timestamp with time zone' })
startedAt: Date;

@CreateDateColumn({ type: 'timestamp with time zone' })
createdAt: Date;

@UpdateDateColumn({ type: 'timestamp with time zone' })
updatedAt: Date;
}
17 changes: 16 additions & 1 deletion src/game-engine/game-engine.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import { PuzzleState } from './entities/puzzle-state.entity';
import { PlayerProgress } from './entities/player-progress.entity';
import { GameSession } from './entities/game-session.entity';
import { PuzzleAnalytics } from './entities/puzzle-analytics.entity';
import { PracticeSession } from './entities/practice-session.entity';
import { PracticeAttempt } from './entities/practice-attempt.entity';
import { PracticeModeService } from './services/practice-mode.service';
import { PracticeModeController } from './controllers/practice-mode.controller';
import { Puzzle } from '../puzzles/entities/puzzle.entity';
import { gameEngineConfig } from './config/game-engine.config';
import { EnergyModule } from '../energy/energy.module';

Expand All @@ -34,6 +39,9 @@ import { EnergyModule } from '../energy/energy.module';
PlayerProgress,
GameSession,
PuzzleAnalytics,
PracticeSession,
PracticeAttempt,
Puzzle,
]),
EnergyModule,
],
Expand All @@ -52,8 +60,14 @@ import { EnergyModule } from '../energy/energy.module';
PuzzleRegistryService,
ScoringService,
AchievementsService,
PracticeModeService,
],
controllers: [
PuzzleController,
GameStateController,
AnalyticsController,
PracticeModeController,
],
controllers: [PuzzleController, GameStateController, AnalyticsController],
exports: [
PuzzleEngineService,
StateManagementService,
Expand All @@ -69,6 +83,7 @@ import { EnergyModule } from '../energy/energy.module';
PuzzleRegistryService,
ScoringService,
AchievementsService,
PracticeModeService,
],
})
export class GameEngineModule {}
Loading