From c33a5683e7c11f1ac127d76718f930827a0b065d Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 24 Jul 2020 18:00:23 -0400 Subject: [PATCH] Finish 3.1 Colored boxes --- src/components.rs | 1 + src/systems/gameplay_state_sytem.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) 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;