/* When you click on the game board, this method is called */ public void OnClick(MouseEventArgs mouseArgs) { bool anyoneSelected = false; BaseChecker previouslySelectedChecker = null; BaseChecker currentSelectedChecker = null; // Trying to find the selected checker anyoneSelected = TryFindSelectedCheckers(mouseArgs, ref previouslySelectedChecker, ref currentSelectedChecker); // If the checker was not selected if (!anyoneSelected) { // If the checker was selected at the last step if (previouslySelectedChecker != null) { // Attempt to move to a given position Point toBoardPosition = new Point() { X = mouseArgs.X / cellSize.Width, Y = mouseArgs.Y / cellSize.Height }; DoMovement(previouslySelectedChecker, toBoardPosition); // Checking the conditions of victory and defeat CheckVictoryConditions(); } else { // Clicked on an empty field DeselectAllCheckers(); state.ActiveChecker = null; state.ActiveCheckerPathPoint = null; } } else { // The checker is selected // Prevent the move by another checker (other than the selected one) if (state.ActiveChecker != null) { if (state.ActiveChecker != currentSelectedChecker) { currentSelectedChecker = null; return; } } List <BaseChecker> turnList = new List <BaseChecker>(); bool aggressive = false; bool turnFound = false; foreach (BaseChecker checker in currentSelectedChecker.Side == CheckerSide.White ? state.WhiteCheckers : state.BlackCheckers) { PathPoint turns = checker.GetPossibleTurns(); if (turns.IsDeadEnd()) { continue; } if (turns.TryGetAggresiveDirections().Count > 0) { turnList.Add(checker); aggressive = true; } } // Filtering moves (if you can eat something, block "inedible" moves) if (!aggressive) { ClearHighlighting(); HighlightPossibleTurns(currentSelectedChecker); // Highlight it } else { foreach (BaseChecker checker in turnList) { if (checker == currentSelectedChecker) { turnFound = true; } } ClearHighlighting(); if (turnFound) { HighlightPossibleTurns(currentSelectedChecker); } else { DeselectAllCheckers(); } } } // Redraw the scene Game.drawingController.PrioritizedDraw(); // Clearing memory from objects generated by active computation of edible options GC.Collect(); }