private static ScoringSet CreateScoreHelperHoriz(int start, int end, int y, PuzzleNode p) { ScoringSet s = new ScoringSet(); s.start = start; s.end = end; s.drawX = p.screenX; s.drawY = p.screenY; s.color = p.color; s.x = -1; s.y = y; if (start < boxOffset) { s.drawX -= 50; } else { s.drawX += 50; } return(s); }
public static void DrawScoreBonus(ScoringSet set) { set.CalculateScore(); Game.spriteBatch.DrawString(Game.menuFont, "+" + set.score, new Vector2(set.drawX, set.drawY), Color.Black, 0, Vector2.Zero, 1f, SpriteEffects.None, 0); Game.spriteBatch.DrawString(Game.menuFont, "+" + set.score, new Vector2(set.drawX, set.drawY), set.color, 0, Vector2.Zero, .96f, SpriteEffects.None, 0); }
//Identifies all scoring matches and marks them. public static List <ScoringSet> Solve(PuzzleBox box, MasterGrid grid) { Matcher.AddBoxToGrid(box, grid); List <ScoringSet> scoringSets = new List <ScoringSet>(); // Marking orbs #region InitialOrbMarking // Marking vertical lines for (int x = boxOffset; x < boxOffset + boxSize; x++) { int start_index = 0; int end_index = 0; PuzzleNode lastNode = new PuzzleNode(Color.Black); for (int y = 0; y < gridSize; y++) { if (grid[x, y] == null) { continue; } if (PuzzleNode.Match(lastNode, grid[x, y])) { lastNode = grid[x, y]; end_index++; } else { lastNode = grid[x, y]; if (StartEndHelper(start_index, end_index)) { ScoringSet s; if (start_index < boxOffset) { s = CreateScoreHelperVert(start_index, end_index, x, grid[x, start_index]); } else { s = CreateScoreHelperVert(start_index, end_index, x, grid[x, y]); } for (int i = start_index; i < end_index; i++) { s.multiplier *= grid[x, i].bonus; MarkHelperVert(start_index, end_index, i, grid[x, i]); } scoringSets.Add(s); } start_index = y; end_index = y + 1; } } if (StartEndHelper(start_index, end_index)) { ScoringSet s = CreateScoreHelperVert(start_index, end_index, x, grid[x, end_index - 1]); for (int i = start_index; i < end_index; i++) { s.multiplier *= grid[x, i].bonus; MarkHelperVert(start_index, end_index, i, grid[x, i]); } scoringSets.Add(s); } } // Marking horizontal lines for (int y = boxOffset; y < boxOffset + boxSize; y++) { int start_index = 0; int end_index = 0; PuzzleNode lastNode = new PuzzleNode(Color.Black); for (int x = 0; x < gridSize; x++) { if (grid[x, y] == null) { continue; } if (PuzzleNode.Match(lastNode, grid[x, y])) { lastNode = grid[x, y]; end_index++; } else { lastNode = grid[x, y]; if (StartEndHelper(start_index, end_index)) { ScoringSet s; if (start_index < boxOffset) { s = CreateScoreHelperHoriz(start_index, end_index, y, grid[start_index, y]); } else { s = CreateScoreHelperHoriz(start_index, end_index, y, grid[x, y]); } for (int i = start_index; i < end_index; i++) { s.multiplier *= grid[i, y].bonus; MarkHelperHoriz(start_index, end_index, i, grid[i, y]); } scoringSets.Add(s); } start_index = x; end_index = x + 1; } } if (StartEndHelper(start_index, end_index)) { ScoringSet s = CreateScoreHelperHoriz(start_index, end_index, y, grid[end_index - 1, y]); for (int i = start_index; i < end_index; i++) { s.multiplier *= grid[i, y].bonus; MarkHelperHoriz(start_index, end_index, i, grid[i, y]); } scoringSets.Add(s); } } #endregion // Extend wildcard markings #region ExtendWildcardMarkings for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { if (IsWildCard(grid[x, y])) { for (int i = x + 1; i < gridSize; i++) { if (grid[i, y].marked) { grid[i, y].replace_right = true; } else { break; } } for (int i = x - 1; i >= 0; i--) { if (grid[i, y].marked) { grid[i, y].replace_left = true; } else { break; } } for (int i = y + 1; i < gridSize; i++) { if (grid[x, i].marked) { grid[x, i].replace_bottom = true; } else { break; } } for (int i = y - 1; i >= 0; i--) { if (grid[x, i].marked) { grid[x, i].replace_top = true; } else { break; } } } } } #endregion // Mark non-scoring orbs as needing to be replaced #region MarkNonScoringOrbsForReplacement for (int x = boxOffset; x < boxOffset + boxSize; x++) { for (int y = 0; y < gridSize; y++) { if (grid[x, y].replace_bottom && !IsWildCard(grid[x, y])) { for (int i = y; i < gridSize; i++) { grid[x, i].marked = true; grid[x, i].replace_bottom = true; grid[x, i].replace_distance = grid[x, y].replace_distance; } break; } } for (int y = gridSize - 1; y >= 0; y--) { if (grid[x, y].replace_top && !IsWildCard(grid[x, y])) { for (int i = y; i >= 0; i--) { grid[x, i].marked = true; grid[x, i].replace_top = true; grid[x, i].replace_distance = grid[x, y].replace_distance; } break; } } } for (int y = boxOffset; y < boxOffset + boxSize; y++) { for (int x = 0; x < gridSize; x++) { if (grid[x, y].replace_right && !IsWildCard(grid[x, y])) { for (int i = x; i < gridSize; i++) { grid[i, y].marked = true; grid[i, y].replace_right = true; grid[i, y].replace_distance = grid[x, y].replace_distance; } break; } } for (int x = gridSize - 1; x >= 0; x--) { if (grid[x, y].replace_left && !IsWildCard(grid[x, y])) { for (int i = x; i >= 0; i--) { grid[i, y].marked = true; grid[i, y].replace_left = true; grid[i, y].replace_distance = grid[x, y].replace_distance; } break; } } } #endregion // fix replace distances #region FixReplaceDistances for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { if (IsWildCard(grid[x, y])) { if (grid[x, y].replace_right) { for (int i = x; i < gridSize; i++) { if (grid[i, y].marked) { grid[i, y].replace_distance--; } else { break; } } } if (grid[x, y].replace_left) { for (int i = x; i >= 0; i--) { if (grid[i, y].marked) { grid[i, y].replace_distance--; } else { break; } } } if (grid[x, y].replace_bottom) { for (int i = y; i < gridSize; i++) { if (grid[x, i].marked) { grid[x, i].replace_distance--; } else { break; } } } if (grid[x, y].replace_top) { for (int i = y; i >= 0; i--) { if (grid[x, i].marked) { grid[x, i].replace_distance--; } else { break; } } } } } } #endregion Matcher.SetBoxFromGrid(box, grid); return(scoringSets); }
private static ScoringSet CreateScoreHelperVert(int start, int end, int x, PuzzleNode p) { ScoringSet s = new ScoringSet(); s.start = start; s.end = end; s.drawX = p.screenX; s.drawY = p.screenY; s.color = p.color; s.x = x; s.y = -1; if (start < boxOffset) s.drawY -= 50; else s.drawY += 50; return s; }