tbg

Crates.iotbg
lib.rstbg
version0.1.3
sourcesrc
created_at2021-09-18 04:11:48.902457
updated_at2021-09-24 04:46:19.005721
descriptionA library for implementing turn based games logic
homepage
repository
max_upload_size
id453190
size25,479
(ZacharyKamerling)

documentation

README

TBG (Turn Based Game)

Provides an easy to use template for turn based games logic. You just need to implement 3 functions and provide some enums. While the main "entity" is called Card, a Card can be anything.

type MyMsg = ...

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
enum MyEvent {
    GameStart,
    CardPlayed(CardID),
    PlayerTurnedBlue(PlayerID),
    GameEnd,
    ...
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
enum MyTrigger {
    YouHaveWonTheGame(PlayerID),
    FlipTheTable(PlayerID),
    ...
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
enum MyEffect {
    PlusOneAllStats(CardID),
    TurnPlayerBlue(PlayerID),
    ...
}

// Similar effect layers to Magic The Gathering
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum MyEffectLayer {
    AttBase,
    Control,
    Mimic,
    Text,
    Flag,
    Ability,
    AttSet,
    AttAdd,
    AttMul,
    AttDiv,
    AttSub,
    AttSwap,
    React,
    ...
}

#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum MyAttName {
    PlayerColor,
    Wealth,
    Health,
    ...
}

#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum MyDeckType {
    Hand,
    Discard,
    Remove,
    Sideboard,
    Main,
    ...
}

#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum MyCardType {
    PocketSand,
    AntsOnFire,
    QueenOfDarts,
    ...
}

#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum MyPhaseType {
    Untap,
    Upkeep,
    Draw,
    Main,
    Fight,
    Die,
    ...
}

type MyGame = TBG<MyMsg,MyEvent,MyTrigger,MyEffect,MyEffectLayer,MyAttName,MyDeckType,MyCardType,MyPhaseType>;

impl TurnBasedGame<MyTrigger, MyEvent, MyEffect, MyEffectLayer, MyMsg> for MyGame {
    fn handle_trigger(&mut self, event: &Event, trigger: &Trigger) -> bool {
        ...
    }
    fn handle_effect(&mut self, effect: &LayeredEffect<Effect, EffectLayer>) {
        ...
    }
    fn handle_msg(&mut self, msg: &Msg) {
        ...
    }
}

Commit count: 0

cargo fmt