Skip to content

πŸ¦€ Educational Rust game project. Pokemon-like battle system with type effectiveness. Learning resource for the Rust Italian community (rust-ita).

License

Notifications You must be signed in to change notification settings

AndreaBozzo/rustmon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rustmon

A Pokemon-like battle simulator written in Rust, demonstrating key Rust programming concepts.

Educational Project: This project follows the Rustmon case study from the Italian Rust documentation. It demonstrates Rust concepts through a familiar gaming domain with extensive documentation.

Disclaimer: Pokemon is a trademark of Nintendo/Game Freak/The Pokemon Company. This project is not affiliated with, endorsed by, or associated with Nintendo. This is a fan project for educational purposes only.

Project Structure

rustmon/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs       # Library root and module organization
β”‚   β”œβ”€β”€ main.rs      # Simple battle example (binary)
β”‚   β”œβ”€β”€ types.rs     # 18 Pokemon types and effectiveness system
β”‚   β”œβ”€β”€ moves.rs     # Move definitions and categories
β”‚   β”œβ”€β”€ traits.rs    # Battler trait for polymorphic behavior
β”‚   β”œβ”€β”€ pokemon.rs   # Pokemon data structures
β”‚   └── battle.rs    # Battle simulation with generic functions
└── examples/
    └── bevy_simulation.rs  # Optional Bevy ECS integration example

Features

  • Complete Type System: All 18 Pokemon types with accurate effectiveness
  • Trait-Based Design: Battler trait enables polymorphic battle functions
  • Generic Programming: Battle functions work with any type implementing Battler
  • Ownership Patterns: Demonstrates immutable/mutable borrowing
  • Pattern Matching: Exhaustive type effectiveness matching
  • Optional Bevy Integration: ECS example (feature-gated)

Build & Run

Run the simple battle example:

cargo run

Run with Bevy ECS simulation:

cargo run --example bevy_simulation --features bevy_integration

Run tests:

cargo test

Build documentation:

cargo doc --open

Educational Goals

This project demonstrates key Rust concepts:

1. Ownership and Borrowing

// Immutable borrow for reading stats
fn print_stats<B: Battler>(battler: &B) { ... }

// Mutable borrow for modifying HP
fn simulate_attack<A: Battler, D: Battler>(
    attacker: &A,      // Read-only
    defender: &mut D,  // Can be modified
    move_used: &Move
) { ... }

2. Enums and Pattern Matching

match (attack_type, defender_type) {
    (Fire, Grass | Ice | Bug | Steel) => 2.0,  // Super effective
    (Electric, Ground) => 0.0,                  // No effect
    _ => 1.0,                                   // Normal
}

3. Traits and Generics

pub trait Battler {
    fn name(&self) -> &str;
    fn current_hp(&self) -> u32;
    // ... required methods

    // Default implementations
    fn can_battle(&self) -> bool { self.current_hp() > 0 }
    fn calculate_damage<D: Battler>(&self, defender: &D, move_used: &Move) -> u32 { ... }
}

Documentation

All modules include comprehensive documentation with examples. View with:

cargo doc --open

License

MIT License - See LICENSE file for details.

This project is not affiliated with, endorsed by, or associated with Nintendo, Game Freak, or The Pokemon Company.

About

πŸ¦€ Educational Rust game project. Pokemon-like battle system with type effectiveness. Learning resource for the Rust Italian community (rust-ita).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages