Exemple #1
0
    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;
            }
        }
    }
Exemple #2
0
    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);
    }
Exemple #3
0
    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);
    }
Exemple #4
0
	public GemCell RetrieveGemCell()
	{
		GemCell.GridCell = null;
		GemCell gemCell = GemCell;
		GemCell = null;
		return gemCell;
	}
Exemple #5
0
    public GemCell RetrieveGemCell()
    {
        GemCell.GridCell = null;
        GemCell gemCell = GemCell;

        GemCell = null;
        return(gemCell);
    }
Exemple #6
0
	public void ClearGemCell()
	{
		if (GemCell != null)
		{
			GemCell.GridCell = null;
		}
		GemCell = null;
	}
Exemple #7
0
 // 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;
 }
Exemple #8
0
	// 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;
	}
Exemple #9
0
 public void ClearGemCell()
 {
     if (GemCell != null)
     {
         GemCell.GridCell = null;
     }
     GemCell = null;
 }
Exemple #10
0
 private bool IsCellMatchable(GemCell gemCell)
 {
     if (gemCell == null || gemCell.IsBusy)
     {
         return(false);
     }
     return(true);
 }
Exemple #11
0
    public void OnGemCellRemoved(GemCell gemCell)
    {
        var handler = GemCellRemoved;

        if (handler != null)
        {
            handler(gemCell, new EventArgs());
        }
    }
Exemple #12
0
 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);
 }
Exemple #13
0
    private void RaiseSwappedEvent(GemCell cell1, GemCell cell2)
    {
        var handler = Swapped;

        if (handler != null)
        {
            handler(this, new GemSwapEventArgs(cell1.GridCell.Index, cell2.GridCell.Index, true));
        }
    }
Exemple #14
0
	private void SetSelectedGemCell(GemCell gemCell)
	{
		if (selectedGemCell != null)
		{
			selectedGemCell.SetStateIdle();
		}
		selectedGemCell = gemCell;
		if (selectedGemCell != null)
			gemCell.SetStateSelected();
	}
Exemple #15
0
    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);
    }
Exemple #16
0
    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);
    }
Exemple #17
0
    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);
    }
Exemple #18
0
 private void SetSelectedGemCell(GemCell gemCell)
 {
     if (selectedGemCell != null)
     {
         selectedGemCell.SetStateIdle();
     }
     selectedGemCell = gemCell;
     if (selectedGemCell != null)
     {
         gemCell.SetStateSelected();
     }
 }
Exemple #19
0
	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;
	}
Exemple #20
0
 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;
 }
Exemple #21
0
	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);
	}
Exemple #22
0
    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);
    }
Exemple #23
0
    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);
    }
Exemple #24
0
    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);
    }
Exemple #25
0
    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;
    }
Exemple #26
0
	public void RemoveOneGem(GemCell gem)
	{
		Debug.LogError("Do this!");
	}
	private bool IsCellMatchable(GemCell gemCell)
	{
		if (gemCell == null || gemCell.IsBusy)
			return false;
		return true;
	}
Exemple #28
0
	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;
	}
Exemple #30
0
	private void RaiseSwappedEvent(GemCell cell1, GemCell cell2)
	{
		var handler = Swapped;
		if (handler != null)
		{
			handler(this, new GemSwapEventArgs(cell1.GridCell.Index, cell2.GridCell.Index, true));
		}
	}
Exemple #31
0
	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;
	}
Exemple #32
0
 public void RemoveOneGem(GemCell gem)
 {
     Debug.LogError("Do this!");
 }
Exemple #33
0
	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;
	}
Exemple #34
0
	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);
	}
Exemple #35
0
	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);
	}
Exemple #36
0
	public void ChangeGemCellAtPos(int x, int y, GemCell gemCell)
	{
		ChangeGemCellAtIndex(boardConfig.GetIndex(x, y), gemCell);
	}
Exemple #37
0
	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);
	}
Exemple #38
0
	public void OnGemCellRemoved(GemCell gemCell)
	{
		var handler = GemCellRemoved;
		if (handler != null)
		{
			handler(gemCell, new EventArgs());
		}
	}
	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;
	}
Exemple #40
0
 public void ChangeGemCellAtPos(int x, int y, GemCell gemCell)
 {
     ChangeGemCellAtIndex(boardConfig.GetIndex(x, y), gemCell);
 }