|
@@ -1,4 +1,5 @@
|
|
|
use bevy::{
|
|
|
+ app::AppExit,
|
|
|
prelude::*,
|
|
|
};
|
|
|
use bevy_mod_picking::*;
|
|
@@ -91,6 +92,7 @@ fn select_square(
|
|
|
mut selected_square: ResMut<SelectedSquare>,
|
|
|
mut selected_piece: ResMut<SelectedPiece>,
|
|
|
mut turn: ResMut<PlayerTurn>,
|
|
|
+ mut app_exit_events: EventWriter<AppExit>,
|
|
|
camera_query: Query<&PickingCamera>,
|
|
|
squares_query: Query<&Square>,
|
|
|
mut pieces_query: Query<(Entity, &mut Piece, &Children)>,
|
|
@@ -129,6 +131,18 @@ fn select_square(
|
|
|
&& other_piece.y == square.y
|
|
|
&& other_piece.color != piece.color
|
|
|
{
|
|
|
+ // if the king is taken, exit
|
|
|
+ if other_piece.piece_type == PieceType::King {
|
|
|
+ println!(
|
|
|
+ "{} won! Thanks for playing!",
|
|
|
+ match turn.0 {
|
|
|
+ PieceColor::White => "White",
|
|
|
+ PieceColor::Black => "Black",
|
|
|
+ }
|
|
|
+ );
|
|
|
+ app_exit_events.send(AppExit);
|
|
|
+ }
|
|
|
+
|
|
|
// despawn the piece and its children
|
|
|
commands.entity(other_entity).despawn();
|
|
|
for child in other_children {
|