Build Your Own Garden (BYOG) is an interactive, procedurally generated 2D world exploration game built in Java. The game features a unique dual-avatar system where players control both a gardener and a duck character, explore randomly generated worlds, and interact with a special "carrot world" dimension.
This project was developed as part of the Data Structures course at UC Berkeley, demonstrating advanced programming concepts including procedural generation, dual-avatar systems, dimensional gameplay, and persistent state management.
- Procedural World Generation: Each world is uniquely generated based on a user-provided seed
- Dual Avatar System: Control both a gardener (WASD keys) and a duck (IJKL keys) simultaneously
- Interactive World: Explore rooms, hallways, and outdoor areas with different tile types
- Carrot Collection: Gardener avatar can collect carrots to access a special dimension
- Save/Load System: Persistent game state with automatic saving and loading capabilities
- Room Generation: Randomly sized rooms (13x13 to 30x30 tiles) with flower walls
- Hallway System: Connected hallways ensure all rooms are accessible
- Terrain Variety: Multiple tile types including dirt floors, grass, and decorative elements
- Deterministic: Same seed always produces identical world layout
- Carrot World: A unique picnic table dimension accessible when collecting carrots
- Visual Effects: Beautiful rose pattern menu screen with animated elements
- HUD Display: Real-time tile information and carrot counter
- Collision Detection: Proper movement restrictions and wall interactions
proj3/
├── src/
│ ├── core/ # Main game logic and classes
│ ├── tileengine/ # Rendering engine and tile system
│ └── utils/ # Utility classes for file I/O and randomness
├── tests/ # JUnit test suite
├── out/ # Compiled bytecode
└── README.md # This documentation
- Entry point for the application
- Initializes the game and title screen
- Main game controller and state manager
- Handles keyboard input processing
- Manages game flow and rendering
- Implements save/load functionality
- Renders beautiful menu screens
- Procedural world generation engine
- Room placement and hallway connection algorithms
- Terrain generation and tile management
- Carrot placement system
- Movement logic for both gardener and duck avatars
- Collision detection and valid move validation
- Avatar spawning and positioning
- Special movement system for carrot world dimension
- Carrot collection mechanics
- Avatar positioning in picnic table environment
- Picnic table dimension generation
- Table setting creation (plates, forks, napkins)
- Triangular carrot generation with mathematical precision
- Coordinate system for 2D positioning
- Unique identifier system for tracking objects
- Data structure for room center storage
- Ensures proper room spacing and connectivity
- 2D tile rendering system
- Window management and display scaling
- Efficient frame rendering with double buffering
- Individual tile representation
- Support for both character and image-based tiles
- Color management and variant generation
- Predefined tile constants
- Visual assets for game elements
- Color scheme definitions
- File I/O operations for save/load functionality
- Error handling and exception management
- Comprehensive random number generation library
- Multiple distribution types (uniform, gaussian, poisson, etc.)
- Array shuffling and permutation utilities
- Run
Main.main()to launch the application - Press
Nfor a new game - Enter a random seed (any sequence of numbers)
- Press
Sto start the game
W- Move upA- Move leftS- Move downD- Move right
I- Move upJ- Move leftK- Move downL- Move right
:- Access command menuN- New gameQ- Save and quitL- Load saved game
- Navigate through procedurally generated rooms and hallways
- Avoid walls (flower tiles) and stay within walkable areas
- Discover carrots scattered throughout the world
- When the gardener avatar moves over a carrot, they're transported to "carrot world"
- Carrot world is a picnic table environment with a triangular carrot to eat
- After eating the carrot, return to the main world after a brief timer
- Carrots respawn after collection
- Game automatically saves avatar positions and remaining carrots
- Use
:Qto save and quit - Use
Lto load from the last save point
- Background Filling: Initialize world with grass tiles
- Room Generation: Randomly place rooms with size constraints
- Room Validation: Ensure rooms don't overlap or touch edges
- Hallway Connection: Connect room centers using L-shaped paths
- Wall Generation: Add decorative walls around hallways
- Carrot Placement: Randomly distribute carrots in walkable areas
- Tile-Based Graphics: 16x16 pixel tiles for consistent visual style
- Double Buffering: Smooth animation and rendering
- Coordinate System: Y-axis inverted for proper screen positioning
- Image Support: PNG files for enhanced visual elements
- File Format: CSV-style text file with coordinates and state
- Persistence: Maintains game state between sessions
- Error Handling: Graceful fallback for missing save files
# Compile the project
javac -cp "lib/*" src/**/*.java
# Run the main class
java -cp "src:lib/*" core.Main- JUnit test suite included in
tests/directory - Test world generation with different seeds
- Validate save/load functionality
- Interactive testing with visual output
- Princeton Standard Library: Core algorithms and data structures
- JUnit 5: Testing framework
- Google Truth: Assertion library for tests
- World Size: 100x60 tiles (6,000 total tiles)
- Tile Storage: Efficient 2D array representation
- Coordinate System: Optimized for quick lookups
- Frame Rate: 10 FPS (100ms pause between frames)
- Tile Updates: Only modified tiles are re-rendered
- Memory Management: Efficient tile object reuse
- World Creation: Sub-second generation for most seeds
- Room Placement: Intelligent collision detection
- Hallway Algorithm: Efficient connectivity algorithm
- Scrolling World: Larger world sizes with camera movement
- More Tile Types: Additional terrain and decorative elements
- Sound Effects: Audio feedback for interactions
- Animation System: Smooth character movement
- Multiplayer Support: Cooperative or competitive play
- Level Progression: Increasing difficulty and complexity
- Spatial Partitioning: Improved collision detection
- Lazy Loading: Dynamic world generation
- Memory Pooling: Reduced object allocation
- Parallel Generation: Multi-threaded world creation
- Game Won't Start: Ensure Java 8+ is installed
- Save File Errors: Check file permissions in project directory
- Rendering Issues: Verify image files are in correct locations
- Performance Problems: Reduce world size or increase frame delay
- Enable console output for detailed generation information
- Use test suite for isolated functionality testing
- Validate world generation with known seeds
This project was developed as an educational exercise in procedural generation, game development, and software architecture. The codebase demonstrates advanced Java programming concepts including:
- Object-oriented design principles
- Algorithm implementation and optimization
- User interface development
- File I/O and persistence
- Testing and debugging methodologies
For questions about the implementation or suggestions for improvements, please refer to the code comments and documentation within each class file. The project serves as an excellent example of how to build complex, interactive applications with proper software engineering practices.