Skip to content

useGameStore makes gameplay decisions from a hardcoded difficulty list on the client #61

Description

@mercy60

Internal ID: #60

Imported from ISSUES.md via scripts/import-issues.mjs.

Problem Statement. frontend/store/useGameStore.js::completePuzzle:

const difficultyLevels = ["easy", "medium", "difficult", "advanced"];
...
nextPuzzleIndex = (currentPuzzleIndex + 1) % 5;
if (isLevelCompleted) {
  ...
  if (currentIndex < difficultyLevels.length - 1) {
    nextDifficulty = difficultyLevels[currentIndex + 1];
    nextPuzzleIndex = 0;
  }
}
const newScore = score + 100;

Three problems:

  1. Constant difficulty list; backend/Smart-contract uses different names.
  2. 100 always added regardless of level.
  3. The level wrap-around + 1 % 5 happens before the level-completed check, so a player who just completed level n has nextPuzzleIndex = (4 + 1) % 5 = 0 by accident — this works!

Why it matters. Console vs back-end/client drift makes the leaderboard inconsistent. Score inflation is too easy.

Expected Outcome.

  • Difficulty list and scoring pulled from API.
  • Server is authoritative.

Acceptance Criteria.

  • A test simulates: client says "completed level 3," server says "easier to next level allowed," and client applies correctly.

Implementation Notes.

  • Use TanStack Query to fetch authoritative level config.

Files / modules affected.

  • frontend/store/useGameStore.js
  • New: frontend/services/gameApi.js

Dependencies. None.

Difficulty / Effort. Medium / M (≈ 4 hours).

Labels. area:frontend, architecture, priority:high

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programarchitectureImported from ISSUES.mdarea:frontendImported from ISSUES.mdpriority:highImported from ISSUES.md

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions