public Chuzzle CreateBomb(Cell cell) { int colorsNumber = NumberOfColors == -1 ? ChuzzlePrefabs.Length : NumberOfColors; GameObject prefab = BombChuzzlePrefabs[Random.Range(0, colorsNumber)]; Chuzzle ch = CreateChuzzle(cell, prefab); return ch; }
private static Cell GetTopCell(IEnumerable<Cell> activeCells, Cell targetCell, Chuzzle c) { if (targetCell == null || targetCell.IsTemporary) { targetCell = GamefieldUtility.CellAt(activeCells, c.Current.X, activeCells.Where(x => !x.IsTemporary).Min(x => x.Y)); if (targetCell.Type == CellTypes.Block) { targetCell = targetCell.GetTopWithType(); } } else { targetCell = targetCell.GetTopWithType(); if (targetCell == null) { targetCell = GamefieldUtility.CellAt(activeCells, c.Current.X, activeCells.Where(x => !x.IsTemporary).Min(x => x.Y)); if (targetCell.Type == CellTypes.Block) { targetCell = targetCell.GetTopWithType(); } } } return targetCell; }
private static Cell GetRightCell(IEnumerable<Cell> activeCells, Cell targetCell, Chuzzle c) { //if border if (targetCell == null) { targetCell = GamefieldUtility.CellAt(activeCells, activeCells.Min(x => x.X), c.Current.Y); if (targetCell.Type == CellTypes.Block) { targetCell = targetCell.GetRightWithType(); } } else { targetCell = targetCell.GetRightWithType(); if (targetCell == null) { targetCell = GamefieldUtility.CellAt(activeCells, activeCells.Min(x => x.X), c.Current.Y); if (targetCell.Type == CellTypes.Block) { targetCell = targetCell.GetRightWithType(); } } } return targetCell; }
public Chuzzle CreateChuzzle(Cell cell, GameObject prefab) { Type type = prefab.GetComponent<Chuzzle>().GetType(); var color = prefab.GetComponent<Chuzzle>().Color; var chuzzle = Instance.ChuzzlePool.Get(color, type).GetComponent<Chuzzle>(); //((GameObject) Instantiate(prefab)).GetComponent<Chuzzle>(); chuzzle.Real = chuzzle.MoveTo = chuzzle.Current = cell; if (!chuzzle.Explosion) { chuzzle.Explosion = Explosion; } if (!chuzzle.ShineParticlePrefab) { chuzzle.ShineParticlePrefab = ShineParticle; } chuzzle.gameObject.transform.parent = Gamefield.transform; chuzzle.gameObject.transform.position = cell.Position; Gamefield.Level.Chuzzles.Add(chuzzle); chuzzle.Died += Gamefield.Level.Chuzzles.OnChuzzleDeath; chuzzle.PointerDown += Gamefield.OnPointerDown; chuzzle.PointerUp += Gamefield.OnPointerUp; //Debug.Log("Chuzzle created: " + chuzzle); return chuzzle; }
public Chuzzle CreateChuzzle(Cell cell, ChuzzleColor color) { return CreateChuzzle(cell, PrefabOfColor(color)); }
private GameObject GetUniqRandomPrefabForCell(Cell cell, List<GameObject> possiblePrefabs) { // GameObject prefab; Cell leftCell = cell.Left; Cell rightCell = cell.Right; Cell topCell = cell.Top; Cell bottomCell = cell.Bottom; RemoveColorFromPossible(leftCell, possiblePrefabs); RemoveColorFromPossible(rightCell, possiblePrefabs); RemoveColorFromPossible(topCell, possiblePrefabs); RemoveColorFromPossible(bottomCell, possiblePrefabs); return possiblePrefabs[Random.Range(0, possiblePrefabs.Count)]; }
private void RemoveColorFromPossible(Cell cell, List<GameObject> possiblePrefabs) { if (cell != null) { Chuzzle chuzzle = GamefieldUtility.GetChuzzleInCell(cell, Gamefield.Level.Chuzzles); if (chuzzle == null) return; GameObject possible = possiblePrefabs.FirstOrDefault(x => x.GetComponent<Chuzzle>().Color == chuzzle.Color); if (possible != null) { possiblePrefabs.Remove(possible); } } }
public Chuzzle CreateTwoTimeChuzzle(Cell cell, bool isUniq) { int colorsNumber = NumberOfColors == -1 ? ChuzzlePrefabs.Length : NumberOfColors; GameObject prefab = isUniq ? GetUniqRandomPrefabForCell(cell, new List<GameObject>(ChuzzleTwoTimesPrefabs)) : ChuzzleTwoTimesPrefabs[Random.Range(0, colorsNumber)]; Chuzzle c = CreateChuzzle(cell, prefab); return c; }
public Chuzzle CreateInvader(Cell cell) { return CreateChuzzle(cell, InvaderPrefab); }
public Chuzzle CreateCounterChuzzle(Cell cell, bool isUniq) { int colorsNumber = NumberOfColors == -1 ? ChuzzlePrefabs.Length : NumberOfColors; GameObject prefab = isUniq ? GetUniqRandomPrefabForCell(cell, new List<GameObject>(ChuzzleCounterPrefabs)) : ChuzzleCounterPrefabs[Random.Range(0, colorsNumber)]; Chuzzle c = CreateChuzzle(cell, prefab); var chuzzle = c as CounterChuzzle; if (chuzzle == null) { Debug.LogError("Incorrect prefabs for counters"); } else { ((TargetChuzzleGameMode) Gamefield.GameMode).UpdateCounter(); } cell.CreationType = CreationType.Usual; return c; }
public Chuzzle CreateChuzzle(Cell cell, bool isUniq = false) { if (cell.Type == CellTypes.Usual) { switch (cell.CreationType) { case CreationType.Usual: case CreationType.Place: cell.CreationType = CreationType.Usual; return CreateRandomChuzzle(cell, isUniq); case CreationType.Counter: cell.CreationType = CreationType.Usual; if (Gamefield.GameMode is TargetChuzzleGameMode) { return CreateCounterChuzzle(cell, isUniq); } return CreateRandomChuzzle(cell, isUniq); case CreationType.Lock: cell.CreationType = CreationType.Usual; return CreateLockChuzzle(cell, isUniq); case CreationType.TwoTimes: cell.CreationType = CreationType.Usual; return CreateTwoTimeChuzzle(cell, isUniq); case CreationType.Invader: cell.CreationType = CreationType.Usual; return CreateInvader(cell); default: throw new ArgumentOutOfRangeException(); } } return null; }
public static Chuzzle GetChuzzleInCell(Cell cell, IEnumerable<Chuzzle> chuzzles) { return chuzzles.FirstOrDefault(x => x.Current == cell); }