public void OnOreClicked(Ore ore) { if (_gameOver) { return; } var oreCluster = _board.FindOreClusterCoordinates(ore); if (oreCluster.Count <= 1) { return; } _board.ClearOresAt(oreCluster); var clusterScore = (int)Math.Pow(oreCluster.Count, 2); IncreaseScore(clusterScore); _view.ClearOresAt(oreCluster, clusterScore); var emptyColumns = _board.FindEmptyColumns(); _board.RemoveColumns(emptyColumns); _board.ApplyGravity(); _view.RemoveColumns(emptyColumns); _view.ApplyGravity(); }
public List <int2> FindOreClusterCoordinates(Ore ore) { var visitedOres = new List <int2>(); if (ore == null) { return(visitedOres); } var oreCoords = FindOreCoords(ore); visitedOres.Add(oreCoords); VisitAllNeighbours(oreCoords.x, oreCoords.y, ore.type, visitedOres); return(visitedOres); }
private int2 FindOreCoords(Ore ore) { for (var i = 0; i < OreColumns.Count; i++) { var oreColumn = OreColumns[i]; for (int j = 0; j < oreColumn.Count; j++) { if (oreColumn.Get(j) == ore) { return(new int2(i, j)); } } } return(new int2(-1, -1)); }
private void Push(Ore ore) { _ores[_oreCount++] = ore; }