using UnityEngine; using System.Collections; using System.Collections.Generic; public class Board : MonoBehaviour { public List gems = new List(); public int GridWidth; public int GridHeight; public GameObject gemPrefab; public Gem lastGem; // Animation public Vector3 gem1Start, gem1End, gem2Start, gem2End; public bool isSwapping = false; public Gem gem1, gem2; public float startTime; public float swapRate = 0.5f; public int AmountToMatch = 3; public bool isMatched = false; int topLine = 6; // Use this for initialization void Start () { for (int h = 0; h < GridHeight; h++) { for (int w = 0; w < GridWidth; w++){ GameObject g = Instantiate(gemPrefab, new Vector3(h,w,0), Quaternion.identity) as GameObject; g.transform.parent = gameObject.transform; gems.Add(g.GetComponent()); } } } // Update is called once per frame void Update () { if (isMatched) { for (int i =0; i topLine) { return true; } if (gems[i].GetComponent().velocity.y > 0.1f){ return true; } } return false; } public void CheckForNearbyMatches (Gem g){ List gemList = new List (); ConstructMatchList (g.color, g, g.XCoord, g.YCoord, ref gemList); FixMatchList (g, gemList); } public void ConstructMatchList(string color, Gem gem, int XCoord, int YCoord, ref List MatchList){ if (gem == null || gem.color != color || MatchList.Contains(gem)){ return; } MatchList.Add (gem); if (XCoord == gem.XCoord || YCoord == gem.YCoord){ foreach(Gem g in gem.Neighbors){ ConstructMatchList(color, g, XCoord, YCoord, ref MatchList); } } } public void CheckMatch(){ List gem1List = new List (); List gem2List = new List (); ConstructMatchList (gem1.color, gem1, gem1.XCoord, gem1.YCoord, ref gem1List); FixMatchList (gem1, gem1List); ConstructMatchList (gem2.color, gem2, gem2.XCoord, gem2.YCoord, ref gem2List); FixMatchList (gem2, gem2List); } public void FixMatchList(Gem gem, List ListToFix){ List rows = new List (); List columns = new List (); for (int i=0; i = AmountToMatch) { isMatched = true; for (int i=0;i= AmountToMatch) { isMatched = true; for (int i=0;i().isKinematic = isOn; } } }