How amazingcoderpro/harmonyos_2048 works
Project type and purpose
• This is a HarmonyOS native mobile app implementing the classic 2048 puzzle game (4×4 grid) using eTS/ArkUI.
• It’s a pure client-side, standalone game—no external backend. It uses local storage for high-score persistence.
File structure
• Top-level modules:
• AppScope/ – global app configuration (app.json5) and shared resources
• entry/ – the main application module containing:
– src/main/ets/ – ArkUI abilities (EntryAbility, EntryBackupAbility) and pages (Index.ets, SoundManager.ets)
– src/main/resources/ – multi-language strings, media assets (audio, layered images), themes, and profile configs
– src/mock/ – mocking utilities/config for development
– src/ohosTest/ – HarmonyOS integration tests (Ability.test.ets, List.test.ets)
– src/test/ – local unit tests (List.test.ets, LocalUnit.test.ets)
– module.json5 – module metadata for the app module
– hvigorfile.ts – build tasks (packaging, obfuscation rules)
– obfuscation-rules.txt
• hvigor/ – shared hvigor build configuration
• build-profile.json5 – project-wide build settings
• code-linter.json5 – lint rules
• oh-package.json5 & lock – package dependencies and versioning
• Release/ contains the published .app and screenshot assets.
README
• Confirms game features: swipe gestures, merge logic, multiple game modes, theme switching, audio effects, local high-score storage.
• No remote services or login implemented yet—pure single-player.
Main components and relationships
a. Components:
1) Application Shell (EntryAbility & EntryBackupAbility)
2) UI Layer (ArkUI pages: Index, SoundManager, Mode/Theme selectors)
3) Game Logic Module (4×4 grid data structure, merge/score algorithms)
4) Resource Manager (multilingual strings, media assets, themes)
5) Local Storage (high-score persistence)
6) Audio Engine (plays .mp3 files for merge, game over etc.)
7) Build Pipeline (Hvizor tasks, obfuscation, packaging)
8) Test Suite (unit tests, integration tests)
b. Relationships & Interactions:
– The Application Shell launches the UI Layer.
– UI Layer captures swipe gestures → invokes Game Logic → updates grid model.
– Game Logic emits events to UI for re-render and to Audio Engine to play sounds.
– When score changes, Game Logic writes to Local Storage via Resource Manager API.
– Resource Manager supplies strings/media to UI.
– Build Pipeline ingests source, applies obfuscation rules, bundles resources, outputs .app.
– Test Suite runs against Game Logic and Abilities in CI.
c. Architectural patterns & principles
– Separation of concerns: UI (presentational) vs. Game Logic (business rules) vs. Resource access.
– ArkUI’s ability/page lifecycle (similar to Activity/Fragment).
– Modular structure: entry module encapsulates all app code, AppScope holds shareable config/resources.
– CI stages: lint → build → obfuscate → package → test.
d. Key technologies/frameworks
– eTS (ArkUI) for declarative UI in .ets files
– HarmonyOS Ability framework (EntryAbility)
– hvigor build tool for custom build steps
– JSON5 for config, theme, and resource descriptors
– Local Storage API for persistence
– Test runner for .ets tests