You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
3.8 KiB
Rust
148 lines
3.8 KiB
Rust
use crate::prelude::*;
|
|
|
|
pub struct GamePlugin;
|
|
|
|
impl Plugin for GamePlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(Startup, setup_board);
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Component)]
|
|
pub(crate) enum Piece {
|
|
Pawn,
|
|
Drone,
|
|
Queen,
|
|
}
|
|
|
|
// manually for the type.
|
|
impl std::fmt::Display for Piece {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
match self {
|
|
Piece::Queen => write!(f, "@"),
|
|
Piece::Drone => write!(f, "^"),
|
|
Piece::Pawn => write!(f, "*"),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The board is setup like this:
|
|
/// ```text
|
|
/// 0 1 2 3 4 5 6 7
|
|
/// +--+--+--+--+--+--+--+--+
|
|
/// a | | | | I | d| Q| Q|
|
|
/// +--+--+--+--+--+--+--+--+
|
|
/// b |d |p |p | I | p| d| Q|
|
|
/// +--+--+--+--+--+--+--+--+
|
|
/// c |Q |d |p | I | p| p| d|
|
|
/// +--+--+--+--+--+--+--+--+
|
|
/// d |Q |Q |d | I | | | |
|
|
/// +--+--+--+--+--+--+--+--+
|
|
/// ````
|
|
#[derive(Debug, Resource)]
|
|
pub(crate) struct Board {
|
|
pub inner: Vec<Vec<Option<Entity>>>,
|
|
}
|
|
|
|
fn setup_board(mut commands: Commands) {
|
|
let a5d = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
|
.id();
|
|
let a6q = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
|
.id();
|
|
let a7q = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
|
.id();
|
|
let b0d = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
|
.id();
|
|
let b1p = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
|
.id();
|
|
let b2p = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
|
.id();
|
|
let c5p = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
|
.id();
|
|
let b5p = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
|
.id();
|
|
let b6d = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
|
.id();
|
|
let b7q = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
|
.id();
|
|
let c0q = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
|
.id();
|
|
let c1d = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
|
.id();
|
|
let c2p = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
|
.id();
|
|
let c6p = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Pawn))
|
|
.id();
|
|
let c7d = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
|
.id();
|
|
let d0q = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
|
.id();
|
|
let d1q = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Queen))
|
|
.id();
|
|
let d2d = commands
|
|
.spawn((SpatialBundle { ..default() }, Piece::Drone))
|
|
.id();
|
|
|
|
commands.insert_resource(Board {
|
|
inner: vec![
|
|
vec![
|
|
None,
|
|
None,
|
|
None,
|
|
None,
|
|
None,
|
|
Some(a5d),
|
|
Some(a6q),
|
|
Some(a7q),
|
|
],
|
|
vec![
|
|
Some(b0d),
|
|
Some(b1p),
|
|
Some(b2p),
|
|
None,
|
|
None,
|
|
Some(b5p),
|
|
Some(b6d),
|
|
Some(b7q),
|
|
],
|
|
vec![
|
|
Some(c0q),
|
|
Some(c1d),
|
|
Some(c2p),
|
|
None,
|
|
None,
|
|
Some(c5p),
|
|
Some(c6p),
|
|
Some(c7d),
|
|
],
|
|
vec![
|
|
Some(d0q),
|
|
Some(d1q),
|
|
Some(d2d),
|
|
None,
|
|
None,
|
|
None,
|
|
None,
|
|
None,
|
|
],
|
|
],
|
|
});
|
|
}
|