//Handling special cases when collision detection is made on an InterventionContainer internal override bool HandleSpecialCollisions(Pin fixedPin) { //Those special cases occur when the border just got drawn but it went out of bouds left or right or at the bottom bool handled = false; if (this.getX() < (this.Width / 2)) //Left { interventionPin.setPinPosition(this.Width / 2, interventionPin.getY()); //Move it right handled = true; } if ((Canvas_map.ActualWidth - (this.Width / 2)) < this.getX()) //Right { interventionPin.setPinPosition(Canvas_map.ActualWidth - (this.Width / 2), interventionPin.getY()); //Move it left handled = true; } if ((Canvas_map.ActualHeight - (this.Height / 2)) < this.getY()) //Bottom { interventionPin.setPinPosition(interventionPin.getX(), Canvas_map.ActualHeight - this.Height + (interventionPin.Height / 2)); handled = true; } if (handled) { PlaceAll(); //Replace all the team and border in accordance with the new intervention pin position CollisionDetectionAndResolution(false); //Recursive call to make sure that it does not collide with anything even the things it previously found no collision with return(true); } //Ignore collision with all pins related to it if (fixedPin == interventionPin || interventionPin.getInterveningTeamsPin().Contains(fixedPin)) { return(true); } return(false); }
//Change the status to what the user has chosen private void ChangeStatus_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; team.setStatus(getMenuItemStatus(menuItem)); //Clearing the arrow if the team got to where they are going if (getMenuItemStatus(menuItem).Equals("available") || getMenuItemStatus(menuItem).Equals("intervening")) { RemoveArrow(); } //Handling the case when the user sets the status of a team to intervening if (getMenuItemStatus(menuItem).Equals("intervening")) { //Handling the case of when the user sets a team to intervening but it is not assigned to an intervention yet. Create the new intervention and assign the team to it. if (interventionPin == null) { Intervention intervention = new Intervention(); //Getting references to the new team and intervention pins TeamPin teamPin = null; //Need to get a reference to the new teamPin and not use "this" because the map has been redrawn upon the intervention creation, i.e. this TeamPin is outdated InterventionPin relatedInterventionPin = null; foreach (Pin pin in pinList) { if (pin.relatedObject == team) { teamPin = (TeamPin)pin; } if (pin.relatedObject == intervention) { relatedInterventionPin = (InterventionPin)pin; break; } } //Setting the position of the intervention to be the position of the team and calling collision detection on the teamPin for the team to be added to the intervention relatedInterventionPin.setPinPosition(teamPin.getX(), teamPin.getY()); teamPin.CollisionDetectionAndResolution(false); relatedInterventionPin.getIntervention().InterveningTeamArrived(team); } else { //Set team as "In position" on the intervention interventionPin.getIntervention().InterveningTeamArrived(team); } } }