-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from evanofslack/joker
Start of joker concepts
- Loading branch information
Showing
10 changed files
with
392 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,53 @@ | ||
use crate::core::game::Game; | ||
use crate::core::joker::{Joker, Jokers}; | ||
use std::sync::Arc; | ||
|
||
pub trait Effect { | ||
fn apply(&self, game: &mut Game); | ||
#[derive(Debug, Clone)] | ||
pub struct EffectRegistry { | ||
pub on_play: Vec<Effects>, | ||
pub on_discard: Vec<Effects>, | ||
pub on_score: Vec<Effects>, | ||
pub on_handrank: Vec<Effects>, | ||
} | ||
|
||
pub struct Joker { | ||
pub name: String, | ||
impl EffectRegistry { | ||
pub fn new() -> Self { | ||
return Self { | ||
on_play: Vec::new(), | ||
on_discard: Vec::new(), | ||
on_score: Vec::new(), | ||
on_handrank: Vec::new(), | ||
}; | ||
} | ||
pub fn register_jokers(&mut self, jokers: Vec<Jokers>, game: &Game) { | ||
for j in jokers.clone() { | ||
for e in j.effects(game) { | ||
match e { | ||
Effects::OnPlay(_) => self.on_play.push(e), | ||
Effects::OnDiscard(_) => self.on_discard.push(e), | ||
Effects::OnScore(_) => self.on_score.push(e), | ||
Effects::OnHandRank(_) => self.on_handrank.push(e), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub enum Effects { | ||
OnPlay(Arc<dyn Fn(&mut Game)>), | ||
OnDiscard(Arc<dyn Fn(&mut Game)>), | ||
OnScore(Arc<dyn Fn(&mut Game)>), | ||
OnHandRank(Arc<dyn Fn(&mut Game)>), | ||
} | ||
|
||
impl Effect for Joker { | ||
fn apply(&self, game: &mut Game) { | ||
game.mult += 4; | ||
impl std::fmt::Debug for Effects { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
Self::OnPlay(_) => write!(f, "OnPlay"), | ||
Self::OnDiscard(_) => write!(f, "OnDiscard"), | ||
Self::OnScore(_) => write!(f, "OnScore"), | ||
Self::OnHandRank(_) => write!(f, "OnHandRank"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.