|
|
|
@ -1,4 +1,8 @@
|
|
|
|
|
use crate::{events, game::Throw, ui};
|
|
|
|
|
use crate::{
|
|
|
|
|
events,
|
|
|
|
|
game::{Outcome, Throw},
|
|
|
|
|
ui,
|
|
|
|
|
};
|
|
|
|
|
use bevy::ecs::system::EntityCommand;
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
|
use bevy::text::DEFAULT_FONT_HANDLE;
|
|
|
|
@ -39,11 +43,6 @@ impl Board {
|
|
|
|
|
|
|
|
|
|
pub struct Play {}
|
|
|
|
|
|
|
|
|
|
pub(crate) enum GameEvent {
|
|
|
|
|
RoundBegin,
|
|
|
|
|
RoundEnd,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Component, Debug)]
|
|
|
|
|
struct Action {
|
|
|
|
|
throw: Throw,
|
|
|
|
@ -53,6 +52,7 @@ fn advance_game_state(
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
mut board: ResMut<Board>,
|
|
|
|
|
mut finished: EventWriter<events::GameFinished>,
|
|
|
|
|
commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// add some stuff here
|
|
|
|
|
match &mut board.phase {
|
|
|
|
@ -70,14 +70,12 @@ fn advance_game_state(
|
|
|
|
|
board.phase = Phase::Reveal(Timer::new(Duration::from_secs(3), TimerMode::Once));
|
|
|
|
|
info!("Player threw: {throw:?}", throw = board.p1_throw);
|
|
|
|
|
info!("Computer threw: {throw:?}", throw = board.p2_throw);
|
|
|
|
|
info!(
|
|
|
|
|
"Outcome: {outcome:?}",
|
|
|
|
|
outcome = board
|
|
|
|
|
let outcome = board
|
|
|
|
|
.p1_throw
|
|
|
|
|
.as_ref()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.against(board.p2_throw.as_ref().unwrap())
|
|
|
|
|
);
|
|
|
|
|
.against(board.p2_throw.as_ref().unwrap());
|
|
|
|
|
finished.send(events::GameFinished { outcome });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Phase::Reveal(timer) => {
|
|
|
|
@ -85,13 +83,26 @@ fn advance_game_state(
|
|
|
|
|
if timer.just_finished() {
|
|
|
|
|
info!("Reveal timer finished");
|
|
|
|
|
board.phase = Phase::AfterPlay;
|
|
|
|
|
finished.send_default();
|
|
|
|
|
// finished.send_default();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Phase::AfterPlay => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn spawn_outcome_display(mut commands: Commands, outcome: &Outcome) {
|
|
|
|
|
let text = match outcome {
|
|
|
|
|
Outcome::Win => "You Win!",
|
|
|
|
|
Outcome::Tie => "Tie.",
|
|
|
|
|
Outcome::Loss => "You Lose...",
|
|
|
|
|
};
|
|
|
|
|
commands
|
|
|
|
|
.spawn((Name::new("Outcome"), crate::ui::column()))
|
|
|
|
|
.add(ui::Label {
|
|
|
|
|
text: String::from(text),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_actions(
|
|
|
|
|
actions: Query<(&Interaction, &Action), (Changed<Interaction>, With<Action>)>,
|
|
|
|
|
mut board: ResMut<Board>,
|
|
|
|
@ -187,10 +198,13 @@ fn handle_game_finished(
|
|
|
|
|
if events.is_empty() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
events.clear();
|
|
|
|
|
for e in q.iter() {
|
|
|
|
|
commands.entity(e).despawn_recursive();
|
|
|
|
|
}
|
|
|
|
|
let finish = events.iter().next().unwrap().to_owned();
|
|
|
|
|
info!("Round finished with outcome: {finish:?}");
|
|
|
|
|
spawn_outcome_display(commands, &finish.outcome);
|
|
|
|
|
events.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_play(
|
|
|
|
|