How komjaur/runescape-clone-study-js-html-css-web works
Project Type and Purpose
• This is a lightweight full-stack web application: a browser-based game prototype front end (HTML, CSS, JavaScript) paired with a simple PHP backend that persists user state in MySQL.
• Its purpose is to demonstrate RuneScape-style mechanics (combat, skills, adventures, shop, quests, housing) in the browser, with persistent saves via server APIs.
File Structure
Top-level layout:
• RunescapeWebGame/
– html/index.php (main game UI)
– css/style.css (styling)
– js/*.js (game logic modules: main.js, skills.js, entities.js, adventure.js, quests.js, shop.js, units.js, house.js)
• php/
– login.php, logout.php (authentication)
– load.php, save.php (state persistence endpoints)
– db.php (DB connection config)
– schema.sql (DB schema)
• README.md (project description)
Architectural hints:
– Clear frontend vs. backend separation
– REST-style PHP endpoints for login/load/save
– In-memory game state on client, synchronized via AJAX calls
Extract Key Insights from README
• Frontend: object-oriented JS classes for units, items, drop tables, timed adventures.
• Backend: PHP scripts invoked automatically by the game UI to persist or retrieve user progress in MySQL.
• Workflow: user logs in → UI loads saved state → user actions update the client state and trigger save.php → DB updates → UI updates.
Main Components & Their Relationships
a. Components:
• Browser / Client
– UI Layer: HTML/CSS
– Game Engine: JS modules (main.js orchestrates skills.js, entities.js, adventure.js, shop.js, quests.js, units.js, house.js)
• Web Server (PHP)
– Authentication APIs: login.php, logout.php
– Data APIs: load.php, save.php
– DB Connector: db.php
• Database
– MySQL database defined in schema.sql (users, stats, inventory tables)
b. Interactions:
1. Client → login.php (POST username) → Server → DB → return session/userID
2. Client loads index.php → JS issues AJAX to load.php → Server retrieves saved game state → Client initializes UI
3. Client UI events (Train, Attack, Adventure, Shop, Quest, House) update in-memory state → JS issues AJAX to save.php with new state → Server writes to DB
4. logout.php invalidates session
c. Architectural Patterns & Principles
• Client-Side MVC-ish separation: main.js updates Views (DOM) and delegates to Model modules (skills, entities, adventures)
• Stateless REST APIs on backend (each request carries user context via session or token)
• Single responsibility: each PHP script does one job (login, load, save)
• Data persistence via relational DB
d. Key Technologies
• Frontend: HTML5, CSS, Vanilla JavaScript (ES5-style OOP modules)
• Backend: PHP 7+, MySQL
• AJAX calls (XMLHttpRequest or fetch) between JS and PHP
Diagramming Recommendations
• Browser → login.php → DB → login.php → Browser
• Browser → load.php → DB → load.php → Browser
• Browser → save.php → DB → save.php → Browser
Essential Details to Capture
• The JS module clustering: group skills.js, entities.js, adventure.js, shop.js, quests.js, units.js, house.js under “Game Engine”.
• The single-file CSS and single HTML entry point.
• The PHP scripts’ roles and how they connect to the DB via db.php.
• The automatic save/load after each action.
• The DB schema (users table for credentials/session, progress table(s) for state).