Game Control
Welcome to the game control guide! Here's where we'll explore how your arcade system manages games - from starting them up to handling game overs. Let's dive in! ๐ฎ
Quick Overview ๐ฏ
Your arcade's game control system:
- Starts games when players pay
- Manages credits and play time
- Handles game over signals
- Controls the attract screen
- Keeps everything in sync
Think of it Like a DJ System
- The attract screen is like playing music between sets
- Starting a game is like starting your main playlist
- Game over is like finishing your set
- The system smoothly transitions between these modes!
How Games Are Controlled ๐น๏ธ
1. State Management
stateDiagram-v2
[*] --> AttractMode
AttractMode --> GamePlay: Coin Pulse
GamePlay --> AttractMode: Game Over
GamePlay --> GamePlay: Additional Credits
Your cabinet has two main states:
-
Attract Mode
- Shows demo animations
- Displays QR code
- Waits for payment
- Monitors for coin pulse
-
Game Play Mode
- Runs the active game
- Tracks remaining credits
- Monitors game status
- Listens for game over
State Transitions
The system smoothly handles changes between states:
- Attract โ Game: When payment received
- Game โ Attract: When game ends
- Game โ Game: When more credits added
2. Credit System ๐ฐ
The credit system manages:
graph TD
A[Payment Received] -->|Add Credits| B[Credit Counter]
B -->|Credits > 0| C[Enable Game]
B -->|Credits = 0| D[Return to Attract]
C -->|Game Over| E[Decrease Credits]
E -->|Check Credits| B
style A fill:#f9f9f9,stroke:#333,stroke-width:2px
style B fill:#f0f0f0,stroke:#333,stroke-width:2px
style C fill:#e1e1e1,stroke:#333,stroke-width:2px
style D fill:#d3d3d3,stroke:#333,stroke-width:2px
style E fill:#c5c5c5,stroke:#333,stroke-width:2px
- Credit addition from payments
- Credit deduction after games
- Multi-credit game support
- Credit persistence
Credit Scenarios
Here's how credits work:
- Player pays $1 โ 1 credit added
- Game starts โ 1 credit used
- Player adds more credits โ Queue for next game
- Game ends โ Check for remaining credits
3. Game Start Process ๐
When credits are added:
-
System receives coin pulse message
-
The cabinet software:
- Verifies the machine ID
- Adds the specified credits
- Switches to game mode
- Starts the game
Start-up Checks
Before starting a game, the system verifies:
- Valid machine ID
- Sufficient credits
- Game is ready
- No active games running
4. During Gameplay โก
While a game is running:
- System monitors game status
- Tracks remaining credits
- Listens for game over
- Handles additional payments
Multi-Credit Games
Some games might need multiple credits:
- Fighting games: 1 credit per player
- Premium games: 2 credits per play
- Extended play: Credits for continue
5. Game Over Handling ๐
When a game ends:
-
Game sends over signal
-
System processes game over:
- Updates credit count
- Checks for remaining credits
- Decides next state
- Updates display
Game Over Flow
The system checks:
- Are there more credits?
- Yes โ Start new game
- No โ Return to attract mode
- Was this a multi-credit game?
- Update credit display
- Handle any remaining balance
Error Handling ๐ง
The system handles various game control issues:
1. Game Crashes
If a game crashes:
- Credits are preserved
- System logs the error
- Cabinet returns to attract mode
- Player can start again
2. Power Issues
If power is lost:
- Credit state is saved
- System recovers on restart
- Games resume if possible
- Players don't lose credits
Data Protection
The system protects player credits by:
- Saving credit state regularly
- Using persistent storage
- Implementing recovery logic
- Maintaining transaction logs
Testing Game Control ๐งช
You can test the system using:
-
Manual Tests:
- Add test credits
- Start games
- Trigger game overs
- Check state transitions
-
Automated Tests:
- Send test MQTT messages
- Verify credit handling
- Check state management
- Test error recovery
Testing Best Practices
Always test:
- Multiple credit scenarios
- Rapid game starts/stops
- Power loss recovery
- Multi-player games
Monitoring & Debugging ๐
Keep track of your games:
-
System Logs:
- Game start/stop events
- Credit changes
- Error conditions
- State transitions
-
MQTT Messages:
- Coin pulse receipts
- Game over signals
- State changes
- Error notifications
-
Cabinet Status:
- Current game state
- Credit count
- Active players
- System health
Next Steps ๐
Now that you understand game control:
- Learn about Cloud Services
- Try testing different scenarios
- Explore credit management
Continue to Cloud Services โ Back to Payment Flow
Need Help?
- Check our Troubleshooting Guide
- Ask your teacher or mentor
- Review the code examples