private void ChallengeSetup() { int k = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Vector2 tempPos = new Vector2(i * xSpacer, j * ySpacer); //GameObject g = Instantiate(tilePrefab, tempPos, Quaternion.identity); //g.transform.parent = this.transform; //set parent to be board; //g.name = "( " + i + ", " + j + " )"; //also make the actual dots: //GameObject dot = Instantiate(dotToSpawn, tempPos, Quaternion.identity, this.transform); GameObject dot = Instantiate(dotToSpawn, transform, false); dot.transform.localPosition = new Vector2(tempPos.x, tempPos.y + gemOffset); Gem thisGem = dot.GetComponent <Gem>(); //print(GetComponentInParent<Board>().NextNumber()); thisGem.targetPos = tempPos; thisGem.brd = this; thisGem.matchMaker = GetComponent <FindMatches>(); thisGem.SetCoordinates(i, j); thisGem.SetColor(GameManager.GM.challengeBoard[k]); //int maxIterations = 0; //if (GameManager.GM.noMatchesInitial) //{ // //not sure if we really want a while incrementing the NextNumber() // while (MatchesAt(i, j, thisGem) && maxIterations < 100) // { // thisGem.SetColor(GameManager.GM.colorsToSpawn[NextNumber()]); // maxIterations++; // } // maxIterations = 0; //} thisGem.CheckMyBuffHints(); //dot.transform.parent = this.transform; dot.name = "( " + i + ", " + j + " )"; allDots[i, j] = dot; k++; } } GameManager.GM.ChallengeIndex(0); }
private void RefillBoard() { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (allDots[i, j] == null) { Vector2 tempPos = new Vector2(i * xSpacer, j * ySpacer); GameObject g = Instantiate(dotToSpawn, this.transform, false); Gem thisGem = g.GetComponent <Gem>(); thisGem.SetColor(GameManager.GM.colorsToSpawn[NextNumber()]); int maxIterations = 0; while (MatchesAt(i, j, thisGem) && maxIterations < 100) { thisGem.SetColor(GameManager.GM.colorsToSpawn[NextNumber()]); maxIterations++; } maxIterations = 0; g.transform.localPosition = new Vector2(tempPos.x, tempPos.y + gemOffset); g.GetComponent <Gem>().targetPos = tempPos; g.GetComponent <Gem>().brd = this; g.GetComponent <Gem>().matchMaker = GetComponent <FindMatches>(); g.GetComponent <Gem>().SetCoordinates(i, j); thisGem.CheckMyBuffHints(); allDots[i, j] = g; } } } //!swap gem issue here?: matchMaker.FindAllMatches(); }