/// <summary> /// Listener for left clicks on the list of units to select. /// Updates the current selected unit. /// </summary> /// <param name="sender">The sender of the notification, the object clicked.</param> /// <param name="e">The event.</param> private void MouseLeftUnitSelecter(object sender, MouseEventArgs e) { IRound round = this.game.Round; Border border = sender as Border; int column = Grid.GetColumn(this.selectedTile); int row = Grid.GetRow(this.selectedTile); IPoint position = new Point(row, column); if(!multipleSelection) { //clear old selection foreach(Border borderUnit in selectedUnitBorder) { borderUnit.BorderBrush = Brushes.Transparent; } selectedUnitBorder.Clear(); } if(!this.selectedUnitBorder.Contains(border)) { border.BorderBrush = unitSelecterBrush; selectedUnitBorder.Add(border); } else { border.BorderBrush = defaultBrush; selectedUnitBorder.Remove(border); } List<IUnit> selectedUnits = new List<IUnit>(); if(multipleSelection) { foreach (Border borderUnit in this.selectedUnitBorder) { selectedUnits.Add(this.unitSelecterCollec[borderUnit]); } } else { selectedUnits.Add(this.unitSelecterCollec[border]); } round.SelectUnits(selectedUnits); ClearAdvisedDestination(); this.DisplayAdvisedDestination(round.GetAdvisedDestinations(this.unitSelecterCollec[border], position)); e.Handled = true; }
/// <summary> /// Listener for left clicks on a rectangle. /// Moves the currently selected unit to the rectangle clicked if possible. /// </summary> /// <param name="sender">The rectangle sender of the notification.</param> /// <param name="e">The event.</param> private void MouseRightMapRectangle(object sender, MouseEventArgs e) { var rectangle = sender as Rectangle; int column = Grid.GetColumn(rectangle); int row = Grid.GetRow(rectangle); IPoint position = new Point(row, column); IRound round = this.game.Round; if(round.SetDestination(position)) { round.ExecuteMove(); this.selectedTile.Stroke = Brushes.Black; this.DisplayUnitsOnMap(); this.unitSelecterCollec.Clear(); this.unitSelecter.Children.Clear(); this.ClearAdvisedDestination(); this.selectedUnitBorder.Clear(); Tuple<IUnit, IPoint> idleUnit = this.game.Map.GetIdleUnit(this.game.CurrentPlayer); if(idleUnit == null) { this.DisplayInfoPlayer(); this.endRound(); } } this.DisplayInfoPlayer(); e.Handled = true; }
/// <summary> /// Listener for left clicks on a rectangle. /// Updates the current selected tile (and units). /// </summary> /// <param name="sender">The rectangle sender of the notification.</param> /// <param name="e">The event.</param> private void MouseLeftMapRectangle(object sender, MouseEventArgs e) { var rectangle = sender as Rectangle; int column = Grid.GetColumn(rectangle); int row = Grid.GetRow(rectangle); IPoint position = new Point(row, column); // Clear old selection this.unitSelecterCollec.Clear(); this.unitSelecter.Children.Clear(); this.selectedUnitBorder.Clear(); ClearAdvisedDestination(); if(this.selectedTile != null) { this.selectedTile.Stroke = Brushes.Transparent; } IRound round = game.Round; if(round.IsCurrentPlayerPosition(position)) { List<IUnit> units = round.GetUnits(position); List<IUnit> selectedUnits = new List<IUnit>(); if(this.multipleSelection) { foreach(IUnit unit in units) { selectedUnits.Add(unit); } } else { selectedUnits.Add(units[0]); } round.SelectUnits(selectedUnits, position); this.DisplayUnitSelecter(units, selectedUnits); this.DisplayAdvisedDestination(round.GetAdvisedDestinations(units[0], position)); rectangle.Stroke = selectedBrush; selectedTile = rectangle; } else { round.UnselectUnit(); } e.Handled = true; }