PokemonGameLib 8.1.0

dotnet add package PokemonGameLib --version 8.1.0                
NuGet\Install-Package PokemonGameLib -Version 8.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PokemonGameLib" Version="8.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PokemonGameLib --version 8.1.0                
#r "nuget: PokemonGameLib, 8.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PokemonGameLib as a Cake Addin
#addin nuget:?package=PokemonGameLib&version=8.1.0

// Install PokemonGameLib as a Cake Tool
#tool nuget:?package=PokemonGameLib&version=8.1.0                

PokemonGameLib

Overview

PokemonGameLib is a robust C# library designed to simulate Pokémon battles. It provides a comprehensive set of interfaces, classes, and services that model the core elements of a Pokémon game, including trainers, Pokémon, moves, items, and battle mechanics. This library is highly extensible, allowing developers to create complex battle systems, custom trainers, and unique game mechanics.

Table of Contents

Features

  • Battle Simulation: Fully functional battle system with support for player and AI-controlled trainers.
  • Command Pattern: Encapsulate actions like attacking, switching Pokémon, and using items as commands.
  • Comprehensive Pokémon Models: Define Pokémon with detailed attributes, including type, stats, moves, and evolutions.
  • Item Usage: Implement items that can heal, revive, or otherwise affect Pokémon during battles.
  • Type Effectiveness: Built-in type effectiveness calculator for accurate battle damage simulation.
  • Status Conditions: Handle status effects like paralysis, burn, sleep, and more, with detailed behavior.
  • Evolution System: Manage Pokémon evolution based on conditions like level or items.
  • Advanced Logging: Integrated logging system for detailed tracking of battle events.
  • Custom Exceptions: Rich set of custom exceptions for precise error handling.

Installation

  1. Clone the Repository

    git clone https://github.com/Kuzziv/PokemonLib
    
  2. Build the Project

    • Open the solution in Visual Studio or your preferred C# IDE.
    • Build the solution to generate the PokemonGameLib.dll file.
  3. Include in Your Project or use the NuGet package

Getting Started

Creating Pokémon and Moves

Start by creating Pokémon and their associated moves:

using PokemonGameLib.Models.Pokemons;
using PokemonGameLib.Models.Pokemons.Moves;

var pikachu = new Pokemon(
    name: "Pikachu", 
    type: PokemonType.Electric, 
    level: 10, 
    maxHp: 35, 
    attack: 55, 
    defense: 40
);
pikachu.AddMove(new Move("Thunder Shock", PokemonType.Electric, power: 40, level: 1));

var charmander = new Pokemon(
    name: "Charmander", 
    type: PokemonType.Fire, 
    level: 10, 
    maxHp: 39, 
    attack: 52, 
    defense: 43
);
charmander.AddMove(new Move("Ember", PokemonType.Fire, power: 40, level: 1));

Setting Up a Battle

With your Pokémon ready, set up a battle between two trainers:

using PokemonGameLib.Models.Trainers;
using PokemonGameLib.Models.Battles;

var playerTrainer = new PlayerTrainer("Ash");
playerTrainer.AddPokemon(pikachu);
playerTrainer.CurrentPokemon = pikachu;

var aiTrainer = new AITrainer("Brock");
aiTrainer.AddPokemon(charmander);
aiTrainer.CurrentPokemon = charmander;

var battle = new Battle(playerTrainer, aiTrainer);

Executing Commands

Commands like attacking, switching Pokémon, or using items can be executed using the command pattern:

using PokemonGameLib.Commands;

// Perform an attack
var attackCommand = new AttackCommand(battle, pikachu.Moves.First());
attackCommand.Execute();

// Switch Pokémon
var switchCommand = new SwitchCommand(battle, playerTrainer, charmander);
switchCommand.Execute();

// Use an item
var potion = new Potion("Potion", "Heals 20 HP", 20);
var useItemCommand = new UseItemCommand(battle, playerTrainer, potion, pikachu);
useItemCommand.Execute();

Battle Flow

To run the battle, simply call StartBattle() on the Battle instance. This will automatically handle turn-taking, Pokémon fainting, and determining the winner.

battle.StartBattle();

Logging and Debugging

PokemonGameLib includes an integrated logging system. Configure logging at the start of your application:

using PokemonGameLib.Utilities;

LoggingService.Configure("path/to/logfile.yml");

// Retrieve and use the logger
var logger = LoggingService.GetLogger();
logger.LogInfo("Battle started!");

Logs will be written in YAML format, making it easy to trace and debug the flow of battles.

Exception Handling

The library provides several custom exceptions to handle common issues in Pokémon battles:

  • InvalidMoveException: Thrown when a Pokémon tries to use a move it cannot perform.
  • InvalidPokemonSwitchException: Thrown when an invalid Pokémon switch is attempted.
  • ItemNotFoundException: Thrown when an item is not found in a trainer's inventory.
  • PokemonFaintedException: Thrown when trying to use a fainted Pokémon.

Example of handling exceptions:

try
{
    var invalidMove = new Move("InvalidMove", PokemonType.Fire, power: -1, level: 1);
    pikachu.AddMove(invalidMove);
}
catch (InvalidMoveException ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}

Extending the Library

PokemonGameLib is designed to be easily extendable. You can add new Pokémon, moves, items, and even modify battle mechanics to suit your needs.

Custom Pokémon

Create a new Pokémon by extending the Pokemon class or implementing the IPokemon interface:

var bulbasaur = new Pokemon(
    name: "Bulbasaur", 
    type: PokemonType.Grass, 
    level: 5, 
    maxHp: 45, 
    attack: 49, 
    defense: 49
);

Custom Moves

Define new moves by extending the Move class or implementing the IMove interface:

var solarBeam = new Move(
    name: "Solar Beam", 
    type: PokemonType.Grass, 
    power: 120, 
    level: 50, 
    maxHits: 1
);

Custom Items

Create new items by extending the Item class or implementing the IItem interface:

using PokemonGameLib.Models.Items;

var maxPotion = new Potion("Max Potion", "Fully restores HP", healingAmount: 100);

Custom Battle Mechanics

To implement custom battle mechanics, extend or modify the Battle class. Override methods like PerformAttack or SwitchTurns to introduce new logic.

using PokemonGameLib.Models.Battles;

public class CustomBattle : Battle
{
    public CustomBattle(ITrainer trainer1, ITrainer trainer2) : base(trainer1, trainer2)
    {
    }

    protected override void PerformAttack(IMove move)
    {
        // Custom attack logic
    }
}

Contributing

We welcome contributions! Whether it's new features, bug fixes, or improvements, your input is valuable.

How to Contribute

  1. Fork the Repository: Create a personal fork of the repository.
  2. Create a Branch: Make your changes in a new branch.
  3. Implement Changes: Write and test your code.
  4. Submit a Pull Request: Propose your changes to be merged into the main repository.

Please follow our code of conduct and contributing guidelines.

License

PokemonGameLib is licensed under the MIT License. See the LICENSE file for details.


This README provides a comprehensive guide to using and extending PokemonGameLib. Dive into the code, experiment with the API, and create your own Pokémon battles! For more detailed examples and API documentation, refer to the inline code comments and explore the provided interfaces and classes. Enjoy building your Pokémon adventure!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.1.0 116 8/19/2024
8.1.0-release 109 8/19/2024
8.0.0-Release 95 8/11/2024
8.0.0-alpha 76 8/4/2024
1.0.0-beta.1.3.0 48 8/2/2024
1.0.0-beta.1.2.1 53 7/25/2024
1.0.0-beta.1.2 49 7/25/2024
1.0.0-beta.1.1 55 7/22/2024
1.0.0-beta.1 56 7/20/2024