void gem_Touched(object sender, System.EventArgs e) { if (waitRelease) { return; } var gemCell = sender as GemCell; if (selectedGemCell != null) { if (AreGemCellsAdjacent(gemCell, selectedGemCell)) { gemCell.StopAllCoroutines(); selectedGemCell.StopAllCoroutines(); RaiseSwappedEvent(gemCell, selectedGemCell); selectedGemCell = null; waitRelease = true; } else { SetSelectedGemCell(null); waitRelease = true; } } }
private int MatchDownCount(int x, int y, GemCell gemCell) { if (IsCellMatchable(gemCell) == false) { return(0); } int matches = 0; var remaining = GetValidCellsToBottom(y); while (remaining > 0) { y++; var cell = PuzzlePresentation.Instance.GetGemCellAtPos(x, y); if (IsMatch(gemCell, cell)) { matches++; } else { return(matches); } remaining--; } return(matches); }
public GemCell GetOneGemCell(int id) { GemCell gemCellObject = null; var poolItem = GemCellPoolItems.Find(pool => pool.Id == id); if (poolItem != null && poolItem.GemCells.Count > 0) { var gemCell = poolItem.GemCells[0]; gemCellObject = gemCell.GetComponent <GemCell>(); gemCellObject.gameObject.transform.parent = null; gemCellObject.gameObject.transform.localPosition = Vector3.zero; poolItem.GemCells.RemoveAt(0); gemCellObject.gameObject.SetActive(true); } else { var name = GemConverter.GetGemName(id); var prefabItem = PrefabList.Find(a => a.Name.Equals(name)); var gObject = Instantiate(prefabItem.Prefab) as GameObject; gemCellObject = gObject.GetComponent <GemCell>(); gemCellObject.gameObject.transform.parent = null; gemCellObject.gameObject.transform.localPosition = Vector3.zero; } gemCellObject.OnActivate(); return(gemCellObject); }
public GemCell RetrieveGemCell() { GemCell.GridCell = null; GemCell gemCell = GemCell; GemCell = null; return gemCell; }
public GemCell RetrieveGemCell() { GemCell.GridCell = null; GemCell gemCell = GemCell; GemCell = null; return(gemCell); }
public void ClearGemCell() { if (GemCell != null) { GemCell.GridCell = null; } GemCell = null; }
// Use this for initialization void Start() { PuzzleBoard = ComponentContainer.PuzzleBoardController.PuzzleBoard; PuzzlePresentation = ComponentContainer.PuzzlePresentation; PuzzlePresentation.Instance.GemCellAdded += Grid_GemCellAdded; PuzzlePresentation.Instance.GemCellRemoved += Grid_GemCellRemoved; selectedGemCell = null; }
// Use this for initialization void Start () { PuzzleBoard = ComponentContainer.PuzzleBoardController.PuzzleBoard; PuzzlePresentation = ComponentContainer.PuzzlePresentation; PuzzlePresentation.Instance.GemCellAdded += Grid_GemCellAdded; PuzzlePresentation.Instance.GemCellRemoved += Grid_GemCellRemoved; selectedGemCell = null; }
private bool IsCellMatchable(GemCell gemCell) { if (gemCell == null || gemCell.IsBusy) { return(false); } return(true); }
public void OnGemCellRemoved(GemCell gemCell) { var handler = GemCellRemoved; if (handler != null) { handler(gemCell, new EventArgs()); } }
private bool IsMatch(GemCell cell1, GemCell cell2) { if (IsCellMatchable(cell1) == false || IsCellMatchable(cell2) == false) { return(false); } //could do a little more here maybe, but for now this is enough return(cell1.Type == cell2.Type); }
private void RaiseSwappedEvent(GemCell cell1, GemCell cell2) { var handler = Swapped; if (handler != null) { handler(this, new GemSwapEventArgs(cell1.GridCell.Index, cell2.GridCell.Index, true)); } }
private void SetSelectedGemCell(GemCell gemCell) { if (selectedGemCell != null) { selectedGemCell.SetStateIdle(); } selectedGemCell = gemCell; if (selectedGemCell != null) gemCell.SetStateSelected(); }
public void ChangeGemCellAtIndex(int index, GemCell gemCell) { boardConfig.ValidateIndex(index); RemoveGemCellAtIndex(index); var cell = Grid[index]; gemCell.transform.parent = this.gameObject.transform; cell.InitGemCell(gemCell, true); OnGemCellAdded(gemCell); }
public void InitGemCell(int x, int y, GemCell newGemCell) { //need to get the gridcell for this and then var index = boardConfig.GetIndex(x, y); var cell = Grid[index]; newGemCell.transform.parent = this.gameObject.transform; cell.InitGemCell(newGemCell, true); OnGemCellAdded(newGemCell); }
private void DropOneGem(GemCell gemCell, int targetY) { var sGridCell = gemCell.GridCell; var dGridCell = GetGridCellAtPos(sGridCell.BoardX, targetY); sGridCell.ClearGemCell(); dGridCell.ClearGemCell(); dGridCell.InitGemCell(gemCell, false); gemCell.SetGemToDrop(PuzzleGameConfig.GemDropWait, PuzzleGameConfig.GemDropGravity, PuzzleGameConfig.GemMaximumFall); }
private void SetSelectedGemCell(GemCell gemCell) { if (selectedGemCell != null) { selectedGemCell.SetStateIdle(); } selectedGemCell = gemCell; if (selectedGemCell != null) { gemCell.SetStateSelected(); } }
public void InitGemCell(GemCell newCell, bool setPosition=true) { if (GemCell != null) { throw new UnityException("Trying to init a gem when one is already in the cell"); } if (setPosition) { newCell.transform.localPosition = Position; } newCell.GridCell = this; GemCell = newCell; }
public void InitGemCell(GemCell newCell, bool setPosition = true) { if (GemCell != null) { throw new UnityException("Trying to init a gem when one is already in the cell"); } if (setPosition) { newCell.transform.localPosition = Position; } newCell.GridCell = this; GemCell = newCell; }
public void RemoveOneGemCell(GemCell gemCell) { gemCell.OnDeActivate(); var id = gemCell.Type; var poolItem = GemCellPoolItems.Find(pool => pool.Id == id); if (poolItem == null) { poolItem = new GemCellPoolItem { Id = id, GemCells = new List<GameObject>() }; GemCellPoolItems.Add(poolItem); } gemCell.gameObject.transform.parent = transform; gemCell.gameObject.transform.localPosition = Vector3.zero; gemCell.gameObject.SetActive(false); poolItem.GemCells.Add(gemCell.gameObject); }
private bool AreGemCellsAdjacent(GemCell cell1, GemCell cell2) { var xDif = Math.Abs(cell1.GridCell.BoardX - cell2.GridCell.BoardX); var yDif = Math.Abs(cell1.GridCell.BoardY - cell2.GridCell.BoardY); if (xDif == 1 && yDif == 0) { return(true); } if (xDif == 0 && yDif == 1) { return(true); } return(false); }
public void RemoveOneGemCell(GemCell gemCell) { gemCell.OnDeActivate(); var id = gemCell.Type; var poolItem = GemCellPoolItems.Find(pool => pool.Id == id); if (poolItem == null) { poolItem = new GemCellPoolItem { Id = id, GemCells = new List <GameObject>() }; GemCellPoolItems.Add(poolItem); } gemCell.gameObject.transform.parent = transform; gemCell.gameObject.transform.localPosition = Vector3.zero; gemCell.gameObject.SetActive(false); poolItem.GemCells.Add(gemCell.gameObject); }
private GemCell ConvertToGemCell(SpawnItem spawn) { int gem = GemConverter.GetGemInt(spawn.GemName); GemCell newGemCell = GemCellPool.Instance.GetOneGemCell(gem); newGemCell.InitGem(); var thisGem = newGemCell.Gem; if (thisGem.AllowBG) { int bg = GemBGConverter.GetGemInt(spawn.BgName); newGemCell.InitBgGem(bg); } if (thisGem.AllowFG) { int fg = GemFGConverter.GetGemInt(spawn.FgName); newGemCell.InitFgGem(fg); } return(newGemCell); }
void gem_Swiped(object sender, SwipeEventArgs e) { if (waitRelease) { return; } var gemCell = sender as GemCell; GridCell otherCell = null; if (e.swipedDown()) { otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX, gemCell.GridCell.BoardY + 1); } if (e.swipedUp()) { otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX, gemCell.GridCell.BoardY - 1); } if (e.swipedLeft()) { otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX - 1, gemCell.GridCell.BoardY); } if (e.swipedRight()) { otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX + 1, gemCell.GridCell.BoardY); } if (otherCell == null) { return; } var otherGemCell = otherCell.GemCell; if (AreGemCellsAdjacent(gemCell, otherGemCell)) { gemCell.StopAllCoroutines(); otherGemCell.StopAllCoroutines(); RaiseSwappedEvent(gemCell, otherGemCell); selectedGemCell = null; } waitRelease = true; }
public void RemoveOneGem(GemCell gem) { Debug.LogError("Do this!"); }
private bool IsCellMatchable(GemCell gemCell) { if (gemCell == null || gemCell.IsBusy) return false; return true; }
void gem_Touched(object sender, System.EventArgs e) { if (waitRelease) return; var gemCell = sender as GemCell; if (selectedGemCell != null) { if (AreGemCellsAdjacent(gemCell, selectedGemCell)) { gemCell.StopAllCoroutines(); selectedGemCell.StopAllCoroutines(); RaiseSwappedEvent(gemCell, selectedGemCell); selectedGemCell = null; waitRelease = true; } else { SetSelectedGemCell(null); waitRelease = true; } } }
private bool IsMatch(GemCell cell1, GemCell cell2) { if (IsCellMatchable(cell1) == false || IsCellMatchable(cell2) == false) return false; //could do a little more here maybe, but for now this is enough return cell1.Type == cell2.Type; }
private bool AreGemCellsAdjacent(GemCell cell1, GemCell cell2) { var xDif = Math.Abs(cell1.GridCell.BoardX - cell2.GridCell.BoardX); var yDif = Math.Abs(cell1.GridCell.BoardY - cell2.GridCell.BoardY); if (xDif == 1 && yDif == 0) return true; if (xDif == 0 && yDif == 1) return true; return false; }
void gem_Swiped(object sender, SwipeEventArgs e) { if (waitRelease) return; var gemCell = sender as GemCell; GridCell otherCell = null; if (e.swipedDown()) otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX, gemCell.GridCell.BoardY + 1); if (e.swipedUp()) otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX, gemCell.GridCell.BoardY - 1); if (e.swipedLeft()) otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX - 1, gemCell.GridCell.BoardY); if (e.swipedRight()) otherCell = PuzzlePresentation.GetGridCellAtPos(gemCell.GridCell.BoardX + 1, gemCell.GridCell.BoardY); if (otherCell == null) return; var otherGemCell = otherCell.GemCell; if (AreGemCellsAdjacent(gemCell, otherGemCell)) { gemCell.StopAllCoroutines(); otherGemCell.StopAllCoroutines(); RaiseSwappedEvent(gemCell, otherGemCell); selectedGemCell = null; } waitRelease = true; }
public void ChangeGemCellAtPos(int x, int y, GemCell gemCell) { ChangeGemCellAtIndex(boardConfig.GetIndex(x, y), gemCell); }
private int MatchDownCount(int x, int y, GemCell gemCell) { if (IsCellMatchable(gemCell) == false) return 0; int matches = 0; var remaining = GetValidCellsToBottom(y); while (remaining > 0) { y++; var cell = PuzzlePresentation.Instance.GetGemCellAtPos(x, y); if (IsMatch(gemCell, cell)) matches++; else return matches; remaining--; } return matches; }