private void OnPossibleMoveFound(GemController sender, GemController[] participants, GemController key, Line direction) { foreach (PossibleMove pm in PossibleMoves) { if (pm.GetHashCode() == MatchUtils.CalculateHash(new int[] { key.Position.x, key.Position.y, sender.Position.x, sender.Position.y })) { return; } } List <GemController> participantsList = new List <GemController>(); foreach (GemController participant in participants) { PossibleMatch participantPossibleMatch = participant.GetPossibleMatchByDirection(direction); if (participantPossibleMatch != null && !participantPossibleMatch.IsMatch()) { participantsList.AddRange(participantPossibleMatch.MatchedGems); } else { participantsList.Add(participant); } } PossibleMove possibleMove = new PossibleMove(participantsList, key, sender.Position, direction); possibleMove.OnOver += PossibleMove_OnOver; possibleMoves.Add(possibleMove); if (OnPossibleMoveCreate != null) { OnPossibleMoveCreate(possibleMove); } }
public PossibleMove(List <GemController> participants, GemController key, Position matchablePosition, Line direction) { Key = key; MatchablePosition = matchablePosition; Direction = direction; hash = MatchUtils.CalculateHash(new int[] { Key.Position.x, Key.Position.y, MatchablePosition.x, MatchablePosition.y }); Key.AddPossibleMove(this, Role.Key); foreach (GemController participant in participants) { participant.AddPossibleMove(this, Role.Participant); Participants.Add(participant); } }