PetCoder is an interactive game that teaches kids (and beginners!) how to program in Ruby by helping adorable pets reach their goals! Write Ruby code to move your pet around a grid, collect treats, avoid obstacles, and reach the target to advance through increasingly challenging levels.
- 🐱 Choose Your Pet: Pick from various cute pets to guide through the game
- 🍖 Collect Treats: Earn bonus points by collecting treats along the way
- 🎯 Reach Targets: Navigate your pet to the target location to complete each level
- ❤️ Three Lives System: Be careful! You have 3 lives per game
- 🏆 Progressive Difficulty: Multiple levels with walls, holes, and gates to challenge you
- 📝 Real Ruby Code: Learn actual Ruby programming syntax in a fun, visual way
- 🔒 Safe Sandbox: All code runs in a secure Docker container for safety
- Select a Player: Choose or create your player profile
- Write Ruby Code: In the code editor on the right, write Ruby commands to move your pet
- Run Your Code: Click the "Run" button to execute your commands
- Watch Your Pet Move: See your code come to life as your pet follows your instructions!
- Complete the Level: Guide your pet to the target to advance
Your pet understands these Ruby commands:
up # Move your pet up one space
down # Move your pet down one space
left # Move your pet left one space
right # Move your pet right one space
open # Open nearby gatesHere are some examples to get you started:
Simple movement:
right
right
upUsing loops (Ruby's .times method):
5.times { right }
3.times { up }Mix and match:
2.times { up }
open
3.times { right }
downMore complex logic:
# Move in a square pattern
4.times do
3.times { right }
3.times { down }
3.times { left }
3.times { up }
end| Element | Description |
|---|---|
| 🐾 Pet | Your character that you control with code |
| 🎯 Target | The goal location your pet needs to reach |
| 🍖 Treat | Collect these for bonus points! |
| 🧱 Wall | Blocks your pet's path - can't move through |
| 🕳️ Hole | Dangerous! Falling in costs a life |
| 🚪 Gate | Use the open command when nearby to open gates |
- Ruby on Rails (main branch) - Web framework
- Turbo & Stimulus - Modern, reactive UI without heavy JavaScript
- Tailwind CSS - Beautiful, responsive styling
- SQLite - Lightweight database
- Docker - Secure code execution sandbox
- Kamal - Zero-downtime deployment to any server
- RSpec - Testing framework
- Ruby 3.4+
- Rails (main branch)
- Docker (for running user code safely)
- SQLite 3
- Overmind (for running the server with
bin/dev)
-
Clone the repository:
git clone <repository-url> cd pet_coder
-
Install dependencies:
bundle install
-
Setup the database:
rails db:create rails db:migrate rails db:seed
-
Start the server:
bin/dev
-
Open your browser: Navigate to
http://localhost:3000
# Run all tests
bundle exec rspec
# Run specific test file
bundle exec rspec spec/lib/executor_spec.rbPlaying PetCoder teaches fundamental programming concepts:
- Sequencing: Commands execute in order, from top to bottom
- Loops: Use
.timesanddo..endblocks to repeat actions - Problem Solving: Break down complex movements into simple steps
- Debugging: When code doesn't work, figure out why and fix it
- Spatial Reasoning: Visualize movements on a 2D grid
- Ruby Syntax: Learn real Ruby programming syntax
PetCoder takes security seriously when executing user code:
- Docker Isolation: Code runs in isolated containers
- No Network Access:
--network=noneprevents internet access - Memory Limits: Maximum 32MB RAM per execution
- CPU Limits: 0.5 CPU cores maximum
- Read-Only Filesystem: No file system modifications allowed
- Timeout Protection: 1-second execution limit
- Capability Dropping: All Linux capabilities removed
- Dangerous Method Removal: Unsafe Ruby methods are disabled
- Lives: Start with 3 ❤️ lives per game
- Points: Earn 100 points for completing each level
- Bonus Points: Collect treats for extra points
- Grid Size: 10x10 grid for pet movement
- Multiple Levels: Progress through increasingly difficult challenges
This is an educational project! Contributions are welcome:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Built with ❤️ for kids learning to code
- Inspired by games like Scratch
- Uses beautiful pet and nature graphics to make learning fun!
Have fun coding and helping your pet reach its goals! 🐾✨