#![allow(unused)]fnmain() {
// map.rspubfninitialize_level(world: &mut World) {
const MAP: &str = "
N N W W W W W W
W W W . . . . W
W . . . BB . . W
W . . RB . . . W
W . P . . . . W
W . . . . RS . W
W . . BS . . . W
W . . . . . . W
W W W W W W W W
";
load_map(world, MAP.to_string());
}
}
#![allow(unused)]fnmain() {
// gameplay.rsuse crate::components::*;
use hecs::World;
use std::collections::HashMap;
pubfnrun_gameplay_state(world: &World) {
// get all boxes indexed by positionletmut query = world.query::<(&Position, &Box)>();
let boxes_by_position: HashMap<(u8, u8), &Box> = query
.iter()
.map(|(_, t)| ((t.0.x, t.0.y), t.1))
.collect::<HashMap<_, _>>();
// loop through all box spots and check if there is a corresponding// box at that positionlet boxes_out_of_position: usize = world
.query::<(&Position, &BoxSpot)>()
.iter()
.map(|(_, (position, box_spot))| {
ifletSome(the_box) = boxes_by_position.get(&(position.x, position.y)) {
if box_spot.colour == the_box.colour {
0
} else {
1
}
} else {
1
}
})
.collect::<Vec<usize>>()
.into_iter()
.sum();
// If we made it this far, then all box spots have boxes on them, and the// game has been wonif boxes_out_of_position == 0 {
letmut query = world.query::<&mut Gameplay>();
let gameplay = query.iter().next().unwrap().1;
gameplay.state = GameplayState::Won;
}
}
}