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