private void OnPossibleMatchOver(PossibleMatch sender) { Logger.Instance.Message(sender.ToString() + " is over"); sender.OnMatch -= OnGemsMatch; sender.OnOver -= OnPossibleMatchOver; possibleMatches.Remove(sender); }
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); } }
private void OnGemsMatch(PossibleMatch sender, GemController[] matchGems) { Logger.Instance.Message(sender.ToString() + " was added to matchedMatches"); if (!matchedMatches.Contains(sender)) { matchedMatches.Add(sender); } }
public void Merge(PossibleMatch other) { Logger.Instance.Message(ToString() + " was merged with " + other.ToString()); this.MatchDirection |= other.MatchDirection; foreach (GemController gem in other.matchedGems) { AddGem(gem); } other.Over(); }
private void OnPossibleMatchAdded(GemController sender, PossibleMatch possibleMatch) { if (null == possibleMatch) { Logger.Instance.Error("possibleMatch is null"); return; } Logger.Instance.Message(possibleMatch.ToString() + " was added to possibleMatches"); possibleMatch.OnMatch += OnGemsMatch; possibleMatch.OnOver += OnPossibleMatchOver; possibleMatches.Add(possibleMatch); }
private void BreakByType(GemType type) { if (null == gems) { Logger.Instance.Error("BreakByType(): gems not inited"); } PossibleMatch pm = new PossibleMatch(type, true); for (int x = 0; x < columnCount; x++) { for (int y = 0; y < rowCount; y++) { if (null != gems[x][y] && gems[x][y].CurrentGemType.HasSameFlags(type)) { pm.AddGem(gems[x][y]); } } } matchedMatches.Add(pm); }
private void CheckNeighbor(GemController neighbor, Direction neighborDirection) { if (null == neighbor) { neighborChangedFlag &= (~neighborDirection); return; } if (!neighbor.IsActive) { return; } if (!neighbor.CurrentGemType.HasSameFlags(this.CurrentGemType)) { neighborChangedFlag &= (~neighborDirection); return; } PossibleMatch addedPossibleMatch = null; foreach (PossibleMatch possibleMatch in neighbor.PossibleMatches) { if (possibleMatch.AddGem(this)) { addedPossibleMatch = possibleMatch; } } if (addedPossibleMatch == null) { addedPossibleMatch = new PossibleMatch(this.CurrentGemType.GetSameFlags(neighbor.CurrentGemType)); addedPossibleMatch.AddGem(this); Logger.Instance.Message(this.ToString() + " adding neighbor " + neighbor.ToString() + " to " + addedPossibleMatch.ToString()); addedPossibleMatch.AddGem(neighbor); if (null != OnPossibleMatchAddedEvent) { OnPossibleMatchAddedEvent(this, addedPossibleMatch); } } neighborChangedFlag &= (~neighborDirection); }