public static void PruneCell(DVector cell) { GameState.Instance.FoodSources.Remove(cell); GameState.Instance.FoodSpenders.Remove(cell); GameState.Instance.ActualGrid.SetCell( cell, GameState.Instance.InitialGrid.GetCell(cell)); foreach (var neighbor in cell.Get4Neighbours()) { if (!TileTypesHelper.IsActive((TileType)GameState.Instance.ActualGrid.GetCell(neighbor))) { continue; } bool hasFilledNeigbor = neighbor.Get4Neighbours() .Select(GameState.Instance.ActualGrid.GetCell) .Cast <TileType>() .Any(TileTypesHelper.IsFilled); if (hasFilledNeigbor) { continue; } GameState.Instance.ActualGrid.SetCell( neighbor, (int)TileTypesHelper.ToInactive((TileType)GameState.Instance.ActualGrid.GetCell(neighbor))); } }
public static bool ProcessCellClick(DVector position) { if (GameState.Instance.RevealInAction) { if (GameState.Instance.Energy >= GameState.Instance.CurrentRevealCost) { RevealCellsAround(position, GameConstants.RevealRadius); GameState.Instance.AddToEnergy(-GameState.Instance.CurrentRevealCost); GameState.Instance.CurrentRevealCost = IncrementCost(GameState.Instance.CurrentRevealCost); Sounds.Instance.PlaySound(Sounds.RevealSound); } else { // should not happen now // play some sound or show message } GameState.Instance.RevealInAction = false; return(true); } if (GameState.Instance.PruneEdgesInAction) { if (!TileTypesHelper.IsFilled((TileType)GameState.Instance.ActualGrid.GetCell(position))) { return(false); } if (GameState.Instance.Energy >= GameState.Instance.CurrentPruneCost) { if (!position.Equals(new DVector(0, 0))) { if (GameState.Instance.ActualGrid.IsConnectedWithout(position)) { PruneCell(position); GameState.Instance.AddToEnergy(-GameState.Instance.CurrentPruneCost); GameState.Instance.CurrentPruneCost = IncrementCost(GameState.Instance.CurrentPruneCost); Sounds.Instance.PlaySound(Sounds.PruneSound); } else { GameState.Instance.CurentInstructions = GameConstants.PruneNotConnectedMessage; Sounds.Instance.PlaySound(Sounds.NopeSound); } } else { GameState.Instance.CurentInstructions = GameConstants.PruneRootMessage; Sounds.Instance.PlaySound(Sounds.NopeSound); } } else { // should not happen now // play some sound or show message } GameState.Instance.PruneEdgesInAction = false; return(true); } TileType posType = (TileType)GameState.Instance.ActualGrid.GetCell(position); if (!TileTypesHelper.IsActive(posType)) { return(false); } switch (posType) { case TileType.ActiveBaseNode: GameState.Instance.ActualGrid.SetCell(position, (int)TileType.FilledBaseNode); GameState.Instance.FoodSpenders.Add(position); RevealCellsAround(position, GameState.Instance.CurrentStepVisionRadius); ExpandAreaAround(position); Sounds.Instance.PlaySound(Sounds.GrowSound); ProcessTurn(); return(true); case TileType.ActiveFoodNode: GameState.Instance.ActualGrid.SetCell(position, (int)TileType.FilledFoodNode); GameState.Instance.FoodSpenders.Add(position); GameState.Instance.OneTimeSources.Enqueue(position); GameState.Instance.InitialGrid.SetCell(position, (int)TileType.ActiveBaseNode); GameState.Instance.AddToEnergy(GameConstants.FoodNodeIncome); RevealCellsAround(position, GameState.Instance.CurrentStepVisionRadius); ExpandAreaAround(position); Sounds.Instance.PlaySound(Sounds.FoodSound); ProcessTurn(); return(true); case TileType.ActiveWaterNode: GameState.Instance.ActualGrid.SetCell(position, (int)TileType.FilledWaterNode); GameState.Instance.FoodSources.Add(position); RevealCellsAround(position, GameState.Instance.CurrentStepVisionRadius); ExpandAreaAround(position); Sounds.Instance.PlaySound(Sounds.WaterSound); ProcessTurn(); return(true); case TileType.ActiveRockNode: if (!GameState.Instance.CanGrowRocks) { return(false); } GameState.Instance.ActualGrid.SetCell(position, (int)TileType.FilledRockNode); GameState.Instance.FoodSpenders.Add(position); RevealCellsAround(position, GameState.Instance.CurrentStepVisionRadius); ExpandAreaAround(position); Sounds.Instance.PlaySound(Sounds.RockSound); ProcessTurn(); return(true); } return(false); }