diff --git a/src/components.rs b/src/components.rs index b456249..395bc30 100644 --- a/src/components.rs +++ b/src/components.rs @@ -2,6 +2,7 @@ use specs::{Component, NullStorage, VecStorage, World, WorldExt}; use std::fmt; use std::fmt::Display; +#[derive(PartialEq)] pub enum BoxColor { Red, Blue, diff --git a/src/systems/gameplay_state_sytem.rs b/src/systems/gameplay_state_sytem.rs index 737ec51..b6afd48 100644 --- a/src/systems/gameplay_state_sytem.rs +++ b/src/systems/gameplay_state_sytem.rs @@ -30,10 +30,17 @@ impl<'a> System<'a> for GameplayStateSystem { .collect(); // loop through all box spots and check if there is a corresponding - // box at that position - for (_box_spot, position) in (&box_spots, &positions).join() { - if boxes_by_position.contains_key(&(position.x, position.y)) { - // continue + // box at that position. since we now have different types of boxes + // we need to make sure the right type of box is on the right + // type of spot. + for (box_spot, position) in (&box_spots, &positions).join() { + if let Some(the_box) = boxes_by_position.get(&(position.x, position.y)) { + if the_box.color == box_spot.color { + // continue + } else { + // return, haven't won yet + return; + } } else { gameplay_state.state = GameplayState::Playing; return;