1个不稳定版本

0.1.3 2021年9月24日
0.1.2 2021年9月18日
0.1.1 2021年9月18日
0.1.0 2021年9月18日

#311模板引擎

MIT 许可证

26KB
753

TBG (回合制游戏)

提供易于使用的模板来构建回合制游戏逻辑。您只需实现3个函数并提供一些枚举。虽然主要的“实体”称为Card,但卡片可以是任何东西。

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) {
        ...
    }
}

依赖关系

~0.6–1.3MB
~27K SLoC