discard a tile
This commit is contained in:
parent
0c5fc38649
commit
02b40ef344
10 changed files with 315 additions and 210 deletions
|
|
@ -3,9 +3,23 @@ use strum::{EnumCount, FromRepr};
|
|||
|
||||
use crate::{
|
||||
EnumNextCycle,
|
||||
game::{GameState, hand::DrawnTile, wall::Wall},
|
||||
game::{
|
||||
GameMessage, GameState,
|
||||
hand::{DrawnTile, Hand},
|
||||
player::Player,
|
||||
wall::Wall,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct CurrentPlayer(pub Entity);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct MatchSettings {
|
||||
pub(crate) starting_points: isize,
|
||||
pub(crate) player_count: u8,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Dice(u8, u8);
|
||||
|
||||
|
|
@ -18,33 +32,6 @@ pub(crate) struct Compass {
|
|||
pub(crate) honba: usize,
|
||||
}
|
||||
|
||||
impl Default for Compass {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prevalent_wind: Wind::Ton,
|
||||
round: 1,
|
||||
dealer_wind: Wind::Ton,
|
||||
riichi: 0,
|
||||
honba: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct MatchSettings {
|
||||
pub(crate) starting_points: isize,
|
||||
pub(crate) player_count: u8,
|
||||
}
|
||||
|
||||
impl Default for MatchSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
starting_points: 25000,
|
||||
player_count: 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Copy, FromRepr, EnumCount, PartialEq)]
|
||||
pub enum Wind {
|
||||
Ton,
|
||||
|
|
@ -59,6 +46,42 @@ pub enum WindRelation {
|
|||
Kamicha,
|
||||
}
|
||||
|
||||
#[derive(SubStates, Default, Clone, Copy, PartialEq, Eq, Hash, Debug, FromRepr, EnumCount)]
|
||||
#[source(GameState = GameState::Play)]
|
||||
pub(crate) enum TurnState {
|
||||
#[default]
|
||||
Tsumo,
|
||||
Menzen,
|
||||
RiichiKan,
|
||||
Discard,
|
||||
RonChiiPonKan,
|
||||
End,
|
||||
}
|
||||
|
||||
#[derive(EntityEvent)]
|
||||
pub struct Discard(pub Entity);
|
||||
|
||||
impl Default for MatchSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
starting_points: 25000,
|
||||
player_count: 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Compass {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prevalent_wind: Wind::Ton,
|
||||
round: 1,
|
||||
dealer_wind: Wind::Ton,
|
||||
riichi: 0,
|
||||
honba: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EnumNextCycle for Wind {
|
||||
fn next(&self) -> Self {
|
||||
if (*self as usize + 1) >= Self::COUNT {
|
||||
|
|
@ -81,21 +104,6 @@ impl Wind {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct CurrentPlayer(pub Entity);
|
||||
|
||||
#[derive(SubStates, Default, Clone, Copy, PartialEq, Eq, Hash, Debug, FromRepr, EnumCount)]
|
||||
#[source(GameState = GameState::Play)]
|
||||
pub(crate) enum TurnState {
|
||||
#[default]
|
||||
Tsumo,
|
||||
Menzen,
|
||||
RiichiKan,
|
||||
Discard,
|
||||
RonChiiPonKan,
|
||||
End,
|
||||
}
|
||||
|
||||
impl EnumNextCycle for TurnState {
|
||||
fn next(&self) -> Self {
|
||||
if (*self as usize + 1) >= Self::COUNT {
|
||||
|
|
@ -125,3 +133,44 @@ pub(crate) fn tsumo(
|
|||
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
||||
pub(crate) fn menzen(
|
||||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
||||
pub(crate) fn riichi_kan(
|
||||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
||||
pub(crate) fn discard(
|
||||
mut reader: MessageReader<GameMessage>,
|
||||
|
||||
currplayer: Res<CurrentPlayer>,
|
||||
drawntile: Single<Entity, With<DrawnTile>>,
|
||||
player_hands: Populated<(&Player, &Children), With<Hand>>,
|
||||
hands: Populated<&Children, (With<Hand>, Without<Player>)>,
|
||||
|
||||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
let curr = currplayer.0;
|
||||
let hand_ent = player_hands.get(curr).unwrap().1.iter().next().unwrap();
|
||||
let hand = hands.get(hand_ent).unwrap();
|
||||
|
||||
while let Some(message) = reader.read().next() {
|
||||
if let GameMessage::Discarded(entity) = message {
|
||||
if *entity == *drawntile {
|
||||
} else if hand.contains(entity) {
|
||||
} else {
|
||||
panic!("discarded illegal player tile?")
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue