Esempio n. 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;
            }
        }
    }
Esempio n. 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);
    }
Esempio n. 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);
    }
Esempio n. 4
0
	public GemCell RetrieveGemCell()
	{
		GemCell.GridCell = null;
		GemCell gemCell = GemCell;
		GemCell = null;
		return gemCell;
	}
Esempio n. 5
0
    public GemCell RetrieveGemCell()
    {
        GemCell.GridCell = null;
        GemCell gemCell = GemCell;

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

        if (handler != null)
        {
            handler(gemCell, new EventArgs());
        }
    }
Esempio n. 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);
 }
Esempio n. 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));
        }
    }
Esempio n. 14
0
	private void SetSelectedGemCell(GemCell gemCell)
	{
		if (selectedGemCell != null)
		{
			selectedGemCell.SetStateIdle();
		}
		selectedGemCell = gemCell;
		if (selectedGemCell != null)
			gemCell.SetStateSelected();
	}
Esempio n. 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);
    }
Esempio n. 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);
    }
Esempio n. 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);
    }
Esempio n. 18
0
 private void SetSelectedGemCell(GemCell gemCell)
 {
     if (selectedGemCell != null)
     {
         selectedGemCell.SetStateIdle();
     }
     selectedGemCell = gemCell;
     if (selectedGemCell != null)
     {
         gemCell.SetStateSelected();
     }
 }
Esempio n. 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;
	}
Esempio n. 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;
 }
Esempio n. 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);
	}
Esempio n. 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);
    }
Esempio n. 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);
    }
Esempio n. 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);
    }
Esempio n. 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;
    }
Esempio n. 26
0
	public void RemoveOneGem(GemCell gem)
	{
		Debug.LogError("Do this!");
	}
Esempio n. 27
0
	private bool IsCellMatchable(GemCell gemCell)
	{
		if (gemCell == null || gemCell.IsBusy)
			return false;
		return true;
	}
Esempio n. 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;
			}
		}
	}
Esempio n. 29
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;
	}
Esempio n. 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));
		}
	}
Esempio n. 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;
	}
Esempio n. 32
0
 public void RemoveOneGem(GemCell gem)
 {
     Debug.LogError("Do this!");
 }
Esempio n. 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;
	}
Esempio n. 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);
	}
Esempio n. 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);
	}
Esempio n. 36
0
	public void ChangeGemCellAtPos(int x, int y, GemCell gemCell)
	{
		ChangeGemCellAtIndex(boardConfig.GetIndex(x, y), gemCell);
	}
Esempio n. 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);
	}
Esempio n. 38
0
	public void OnGemCellRemoved(GemCell gemCell)
	{
		var handler = GemCellRemoved;
		if (handler != null)
		{
			handler(gemCell, new EventArgs());
		}
	}
Esempio n. 39
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;
	}
Esempio n. 40
0
 public void ChangeGemCellAtPos(int x, int y, GemCell gemCell)
 {
     ChangeGemCellAtIndex(boardConfig.GetIndex(x, y), gemCell);
 }