254 lines
7.8 KiB
Markdown
254 lines
7.8 KiB
Markdown
# Development Guide - Neural Nexus
|
|
|
|
## Table of Contents
|
|
|
|
1. [Project Overview](#project-overview)
|
|
2. [Architecture](#architecture)
|
|
3. [Technology Stack](#technology-stack)
|
|
4. [Development Setup](#development-setup)
|
|
5. [Project Structure](#project-structure)
|
|
6. [Development Workflow](#development-workflow)
|
|
7. [Game Design Guidelines](#game-design-guidelines)
|
|
8. [Code Standards](#code-standards)
|
|
9. [Testing Strategy](#testing-strategy)
|
|
10. [Performance Guidelines](#performance-guidelines)
|
|
11. [Deployment Process](#deployment-process)
|
|
12. [Troubleshooting](#troubleshooting)
|
|
|
|
## Project Overview
|
|
|
|
### Vision
|
|
Neural Nexus is a modern HTML5 puzzle game that challenges players to connect neural network nodes in specific patterns. We're building an engaging, visually appealing game that combines contemporary themes with accessible gameplay mechanics.
|
|
|
|
### Goals
|
|
- **Primary:** Create a polished, addictive puzzle game with 50+ levels
|
|
- **Secondary:** Achieve smooth 60fps performance across all modern devices
|
|
- **Success Metrics:**
|
|
- 5+ minute average session time
|
|
- 80%+ level completion rate for first 10 levels
|
|
- <3 second load time on mobile devices
|
|
|
|
### Target Users
|
|
- **Primary Users:** Casual puzzle game players aged 16-45
|
|
- **Use Cases:** Quick gaming sessions, brain training, stress relief
|
|
- **User Needs:** Engaging mental challenge without complexity overload
|
|
|
|
## Architecture
|
|
|
|
### System Design
|
|
```
|
|
┌─────────────────┐ ┌─────────────────┐
|
|
│ Game UI │────▶│ Game State │
|
|
│ (Canvas/HTML) │ │ Manager │
|
|
└─────────────────┘ └─────────────────┘
|
|
│ │
|
|
▼ ▼
|
|
┌─────────────────┐ ┌─────────────────┐
|
|
│ Render Engine │ │ Game Logic │
|
|
│ (Canvas 2D API) │ │ (Nodes/Levels) │
|
|
└─────────────────┘ └─────────────────┘
|
|
│ │
|
|
▼ ▼
|
|
┌─────────────────┐ ┌─────────────────┐
|
|
│ Input Handler │ │ Local Storage │
|
|
│(Mouse/Touch) │ │ (Save Data) │
|
|
└─────────────────┘ └─────────────────┘
|
|
```
|
|
|
|
### Component Relationships
|
|
- **Game State:** Central store for level progress, score, timer
|
|
- **Rendering:** Canvas-based with CSS for UI overlays
|
|
- **Input System:** Unified mouse/touch handling for connections
|
|
- **Game Objects:** Node and Connection classes with physics
|
|
|
|
### Design Decisions
|
|
| Decision | Choice | Rationale |
|
|
|----------|--------|-----------|
|
|
| Graphics API | Canvas 2D | Excellent performance, wide compatibility, simpler than WebGL |
|
|
| State Management | Single Global Object | Sufficient for game scope, easy debugging |
|
|
| Input Handling | Event-based | Responsive feel, works across devices |
|
|
| Styling | CSS + Canvas | Leverage CSS for UI, Canvas for game graphics |
|
|
|
|
## Technology Stack
|
|
|
|
### Core Technologies
|
|
- **Frontend:** Vanilla HTML5, JavaScript ES6+, CSS3
|
|
- **Graphics:** Canvas 2D API with CSS animations
|
|
- **Architecture:** Object-oriented game components
|
|
- **Storage:** LocalStorage for save data and preferences
|
|
|
|
### Key Libraries
|
|
```json
|
|
{
|
|
"dependencies": {
|
|
"No external dependencies": "Vanilla JS for maximum performance and control"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Development Tools
|
|
- **Browser DevTools:** Performance profiling and debugging
|
|
- **Testing:** Manual testing across browsers and devices
|
|
- **Version Control:** Git with feature branching
|
|
- **Performance:** Lighthouse for optimization audits
|
|
|
|
## Game Design Guidelines
|
|
|
|
### Core Mechanics Principles
|
|
1. **Clarity:** Player immediately understands connection system
|
|
2. **Progressive Difficulty:** Each level introduces manageable challenge increase
|
|
3. **Feedback:** Visual and audio cues for all player actions
|
|
4. **Flow State:** Difficulty curve maintains engagement without frustration
|
|
|
|
### Level Design Standards
|
|
```javascript
|
|
// Level generation guidelines
|
|
const levelDesign = {
|
|
nodes: {
|
|
minimum: 3,
|
|
maximum: 12,
|
|
progression: "gradual increase with occasional easier levels"
|
|
},
|
|
connections: {
|
|
formula: "nodeCount - 1 + Math.floor(level / 3)",
|
|
maxComplexity: "avoid overly complex patterns"
|
|
},
|
|
timing: {
|
|
baseTime: 60,
|
|
adjustment: "decrease by 2 seconds every 3 levels",
|
|
minimum: 30
|
|
}
|
|
};
|
|
```
|
|
|
|
### Visual Design Patterns
|
|
```css
|
|
/* Color scheme consistency */
|
|
:root {
|
|
--primary-cyan: #00d4ff;
|
|
--secondary-magenta: #ff00ff;
|
|
--success-green: #00ff64;
|
|
--warning-orange: #ff6400;
|
|
--background-dark: #0a0a0a;
|
|
--surface-glass: rgba(255, 255, 255, 0.1);
|
|
}
|
|
```
|
|
|
|
## Performance Guidelines
|
|
|
|
### Target Metrics
|
|
- **Frame Rate:** 60fps on desktop, 30fps+ on mobile
|
|
- **Load Time:** <3 seconds on 3G connection
|
|
- **Memory Usage:** <50MB on mobile devices
|
|
- **Bundle Size:** <1MB total (including assets)
|
|
|
|
### Optimization Techniques
|
|
|
|
1. **Rendering Optimization**
|
|
```javascript
|
|
// Efficient canvas clearing
|
|
function clearCanvas() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
// Better than: ctx.fillRect() for transparency
|
|
}
|
|
|
|
// Object pooling for particles
|
|
class ParticlePool {
|
|
constructor(size = 100) {
|
|
this.pool = [];
|
|
this.active = [];
|
|
for (let i = 0; i < size; i++) {
|
|
this.pool.push(new Particle());
|
|
}
|
|
}
|
|
|
|
acquire() {
|
|
return this.pool.pop() || new Particle();
|
|
}
|
|
|
|
release(particle) {
|
|
particle.reset();
|
|
this.pool.push(particle);
|
|
}
|
|
}
|
|
```
|
|
|
|
## Testing Strategy
|
|
|
|
### Manual Testing Checklist
|
|
```markdown
|
|
**Core Functionality:**
|
|
- [ ] Node connections work with mouse
|
|
- [ ] Node connections work with touch
|
|
- [ ] Level progression advances correctly
|
|
- [ ] Score calculation accurate
|
|
- [ ] Timer counts down properly
|
|
- [ ] Game over conditions trigger
|
|
|
|
**Performance Testing:**
|
|
- [ ] 60fps on Desktop Chrome/Firefox/Safari
|
|
- [ ] 30fps+ on mobile devices
|
|
- [ ] No memory leaks after 10+ levels
|
|
- [ ] Smooth animations during gameplay
|
|
|
|
**Device Compatibility:**
|
|
- [ ] Desktop: Windows/Mac/Linux browsers
|
|
- [ ] Mobile: iOS Safari, Android Chrome
|
|
- [ ] Tablet: iPad, Android tablets
|
|
- [ ] Various screen sizes and orientations
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Development Issues
|
|
|
|
#### Performance Problems
|
|
**Problem:** Game running slowly, stuttering animations
|
|
```javascript
|
|
// Debug: Check frame time
|
|
function debugFrameTime() {
|
|
const times = [];
|
|
let lastTime = performance.now();
|
|
|
|
function measureFrame() {
|
|
const now = performance.now();
|
|
times.push(now - lastTime);
|
|
lastTime = now;
|
|
|
|
if (times.length > 60) {
|
|
const avg = times.reduce((a, b) => a + b) / times.length;
|
|
console.log(`Average frame time: ${avg.toFixed(2)}ms`);
|
|
times.length = 0;
|
|
}
|
|
|
|
requestAnimationFrame(measureFrame);
|
|
}
|
|
|
|
measureFrame();
|
|
}
|
|
```
|
|
|
|
**Solutions:**
|
|
- Reduce particle count
|
|
- Optimize drawing operations
|
|
- Use `requestAnimationFrame` properly
|
|
- Check for memory leaks
|
|
|
|
#### Touch Controls Not Working
|
|
**Problem:** Mobile touch events not registering properly
|
|
```javascript
|
|
// Solution: Prevent default touch behavior
|
|
canvas.addEventListener('touchstart', (e) => {
|
|
e.preventDefault(); // Prevent scrolling
|
|
// Handle touch
|
|
}, { passive: false });
|
|
|
|
canvas.addEventListener('touchmove', (e) => {
|
|
e.preventDefault(); // Prevent scrolling
|
|
// Handle drag
|
|
}, { passive: false });
|
|
```
|
|
|
|
---
|
|
|
|
**Remember:** This is a living document. Update it as the game evolves and you discover new patterns or solutions! |