public bool AddGem(GemController gem) { if (!IsPossibleToAdd(gem)) { return(false); } if (matchedGems.Count == 1 && !isContainer) { if (matchedGems[0].Position.x == gem.Position.x) { MatchDirection = Line.Vertical; } else if (matchedGems[0].Position.y == gem.Position.y) { MatchDirection = Line.Horizontal; } } Logger.Instance.Message(ToString() + ": " + gem.ToString() + " was added"); matchedGems.Add(gem); if (!IsContainer) { gem.PossibleMatches.Add(this); } return(true); }
public void SetGemSwipeResult(GemController gem, bool isMatched) { Logger.Instance.Message(gem.ToString() + " is " + (isMatched ? "matched" : "not matched")); for (int i = 0; i < swipingGems.Count; i++) { if (swipingGems[i].gem == gem) { swipingGems[i].isMatched = isMatched; swipingGems[i].isOver = true; break; } } CheckGemsSwipeEnded(); }
public void RemoveGem(GemController gem) { Logger.Instance.Message(ToString() + ": " + gem.ToString() + " was removed"); if (MatchInitiator == gem) { MatchInitiator = null; } matchedGems.Remove(gem); if (!IsContainer) { gem.PossibleMatches.Remove(this); } if (matchedGems.Count == 1) { Over(); } }
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); }
private void OnSpecialGemMatch(GemController sender, GemSpecialType type) { Logger.Instance.Message("Special " + sender.ToString() + " matched"); List <GemController> hitGems = new List <GemController>(); int bombsize = type == GemSpecialType.DoubleBomb ? 5 : 3; switch (type) { case GemSpecialType.Horizontal: hitGems.AddRange(GetGemsByRowIndex(sender.Position.y)); break; case GemSpecialType.Vertical: hitGems.AddRange(GetGemsByColumnIndex(sender.Position.x)); break; case GemSpecialType.Vertical | GemSpecialType.Horizontal: hitGems.AddRange(GetGemsByRowIndex(sender.Position.y)); hitGems.AddRange(GetGemsByColumnIndex(sender.Position.x)); break; case GemSpecialType.Vertical | GemSpecialType.Bomb: if (sender.Position.x - 1 >= 0) { hitGems.AddRange(GetGemsByColumnIndex(sender.Position.x - 1)); } hitGems.AddRange(GetGemsByColumnIndex(sender.Position.x)); if (sender.Position.x + 1 < columnCount) { hitGems.AddRange(GetGemsByColumnIndex(sender.Position.x + 1)); } break; case GemSpecialType.Horizontal | GemSpecialType.Bomb: if (sender.Position.y - 1 >= 0) { hitGems.AddRange(GetGemsByRowIndex(sender.Position.y - 1)); } hitGems.AddRange(GetGemsByRowIndex(sender.Position.y)); if (sender.Position.y + 1 < rowCount) { hitGems.AddRange(GetGemsByRowIndex(sender.Position.y + 1)); } break; case GemSpecialType.DoubleBomb: case GemSpecialType.Bomb: for (int x = sender.Position.x - (bombsize / 2); x <= sender.Position.x + (bombsize / 2); x++) { for (int y = sender.Position.y - (bombsize / 2); y <= sender.Position.y + (bombsize / 2); y++) { if (y < 0 || x < 0 || y >= rowCount || x >= columnCount) { continue; } GemController gem = gems[x][y]; if (gem == null) { continue; } hitGems.Add(gem); } } break; case GemSpecialType.HitType: break; default: Logger.Instance.Error("unknown special type " + type + " of " + sender.ToString()); break; } foreach (GemController gem in hitGems) { if (gem == sender) { continue; } MatchGem(gem); } }
public SwipeAction(GemController gem1, GemController gem2) { Logger.Instance.Message("SwipeAction was created with " + gem1.ToString() + " and " + gem2.ToString()); swipingGems.Add(new SwipeInfo(gem1, false, false)); swipingGems.Add(new SwipeInfo(gem2, false, false)); }