private GridItemFX CreateGridItemMatchedFX(GridItemView gridItem, int points, float seconds) { var fx = PrefabPool.Get <GridItemFX>(_playfieldFxItems); fx.Configure(gridItem.Index.x, gridItem.Index.y, gridItem.ID, gridItem.transform.localPosition, _tileSize); fx.Show(points, seconds); return(fx); }
private bool CanSelectGridItem(GridItemView gridItem) { if (gridItem == null || gridItem.IsEmpty) { return(false); // invalid } if (_selectedGridItems.Count == 0) { return(true); // first selection } var itemConfig = GameConfig.GetGridItem(gridItem.ID); if (itemConfig.MatchType == GridItemMatchType.None) { return(false); } var previousItemConfig = _selectedGridItems[_selectedGridItems.Count - 1].GridItemConfig; if (itemConfig.MatchType == GridItemMatchType.Category || previousItemConfig.MatchType == GridItemMatchType.Category) { if (itemConfig.Category != previousItemConfig.Category) { return(false); } } else if (itemConfig.MatchType == GridItemMatchType.Exact) { if (itemConfig.ID != previousItemConfig.ID) { return(false); } } if (_selectedGridItems.Contains(gridItem)) { return(false); // already selected } var matchRules = GameConfig.GetMatchRules(_levelConfig.matchRules); if (matchRules.MaxSelection > matchRules.MinSelection && _selectedGridItems.Count > matchRules.MaxSelection) { return(false); } if (GridIndex.IsNeighbor(gridItem.Index, _selectedGridItems[_selectedGridItems.Count - 1].Index)) { return(true); // must neighbor the last selected item } return(false); }
private bool CanDeselectGridItems(GridItemView gridItem) { if (gridItem == null) { return(false); // invalid } if (_selectedGridItems.Count < 2) { return(false); // not enough items selected } if (!_selectedGridItems.Contains(gridItem)) { return(false); // not selected } if (gridItem == _selectedGridItems[_selectedGridItems.Count - 2]) { return(true); // take one step back } if (!GridIndex.IsNeighbor(gridItem.Index, _selectedGridItems[_selectedGridItems.Count - 1].Index)) { return(true); // must NOT neighbor the last selected item to trace back further (else it's annoying) } return(false); }
private void DestroyGridItemView(GridItemView gridItem) { gridItem.Invalidate(); _gridItemInstances.Remove(gridItem); PrefabPool.Return(gridItem); }