IEnumerator GenerateHexagons(List <int> columns, List <List <Color> > colorSeed = null) { Vector3 startPosition; float positionX, positionY; float startX = GetGridStartCoordinateX(); foreach (int i in columns) { positionX = startX + ((HEX_DISTANCE_HORIZONTAL)*i); positionY = ((HEX_DISTANCE_VERTICAL)*grid[i].Count * 2) + GRID_VERTICAL_OFFSET + (i % 2 == 0 ? HEX_DISTANCE_VERTICAL : ZERO); startPosition = new Vector3(positionX, positionY, ZERO); GameObject newHex = Instantiate(hexagonPrefab, HEX_START_POSITION, Quaternion.identity, hexPool); Hexagon hex = newHex.GetComponent <Hexagon>(); if (colorSeed == null) { hex.SetColor(colorList[(int)(Random.value * RANDOM_SEED) % colorList.Count]); } else { hex.SetColor(colorSeed[i][grid[i].Count]); } yield return(new WaitForSeconds(DELAY_TO_PRODUCE_HEXAGON)); hex.ChangeGridPosition(new Vector2(i, grid[i].Count)); hex.ChangeWorldPosition(startPosition); grid[i].Add(hex); } }
/* Produces new hexagons on given columns */ private IEnumerator ProduceHexagons(List <int> columns, List <List <Color> > colorSeed = null) { Vector3 startPosition; float positionX, positionY; float startX = GetGridStartCoordinateX(); bool stepperStatus; /* Indication for the beginning of hexagon production */ hexagonProductionStatus = true; /* Produce new hexagon, set variables */ foreach (int i in columns) { /* Instantiate new hexagon and give a little delay */ stepperStatus = OnStepper(i); positionX = startX + (HEX_DISTANCE_HORIZONTAL * i); positionY = (HEX_DISTANCE_VERTICAL * gameGrid[i].Count * 2) + GRID_VERTICAL_OFFSET + (stepperStatus ? HEX_DISTANCE_VERTICAL : ZERO); startPosition = new Vector3(positionX, positionY, ZERO); GameObject newObj = Instantiate(hexPrefab, HEX_START_POSITION, Quaternion.identity, hexParent.transform); Hexagon newHex = newObj.GetComponent <Hexagon>(); yield return(new WaitForSeconds(DELAY_TO_PRODUCE_HEXAGON)); /* Set bomb if production signal has arrived */ if (bombProduction) { newHex.SetBomb(); bombs.Add(newHex); bombProduction = false; } /* Set world and grid positions of hexagon */ if (colorSeed == null) { newHex.SetColor(colorList[(int)(Random.value * RANDOM_SEED) % colorList.Count]); } else { newHex.SetColor(colorSeed[i][gameGrid[i].Count]); } newHex.ChangeGridPosition(new Vector2(i, gameGrid[i].Count)); newHex.ChangeWorldPosition(startPosition); gameGrid[i].Add(newHex); } /* Indication for the end of hexagon production */ hexagonProductionStatus = false; }
/* Verilen kolonlara yeni hesagonların yerleşmesi */ private IEnumerator ProduceHexagons(List <int> columns, List <List <Color> > colorSeed = null) { Vector3 startPosition; float positionX, positionY; float startX = GetGridStartCoordinateX(); bool stepperStatus; hexagonProductionStatus = true; foreach (int i in columns) { /*Yeni hesagonların klonlanması */ stepperStatus = OnStepper(i); positionX = startX + (HEX_DISTANCE_HORIZONTAL * i); positionY = (HEX_DISTANCE_VERTICAL * gameGrid[i].Count * 2) + GRID_VERTICAL_OFFSET + (stepperStatus ? HEX_DISTANCE_VERTICAL : ZERO); startPosition = new Vector3(positionX, positionY, ZERO); GameObject newObj = Instantiate(hexPrefab, HEX_START_POSITION, Quaternion.identity, hexParent.transform); Hexagon newHex = newObj.GetComponent <Hexagon>(); yield return(new WaitForSeconds(DELAY_TO_PRODUCE_HEXAGON)); /* bombanın gelmesi */ if (bombProduction) { newHex.SetBomb(); bombs.Add(newHex); bombProduction = false; } /* hexagon için grid ve pozisyon ayarlama */ if (colorSeed == null) { newHex.SetColor(colorList[(int)(Random.value * RANDOM_SEED) % colorList.Count]); } else { newHex.SetColor(colorSeed[i][gameGrid[i].Count]); } newHex.ChangeGridPosition(new Vector2(i, gameGrid[i].Count)); newHex.ChangeWorldPosition(startPosition); gameGrid[i].Add(newHex); } hexagonProductionStatus = false; }
//Produces new hexagons private IEnumerator ProduceHexagons(List <int> columns, List <List <Color> > colorSeed = null) { Vector3 posToBeMoved; float positionX, positionY; hexProduction = true; //Produce a new hexagon,and set its variables foreach (int i in columns) { positionX = (0.8f * i); positionY = (0.885f * grid[i].Count) + (IsEven(i) ? 0.885f * 0.5f : 0); posToBeMoved = new Vector3(positionX, positionY, 0); GameObject newObj = Instantiate(hexPrefab, new Vector3(5f, 45f, 0f), Quaternion.Euler(0f, 0f, 90f), transform); newObj.name = "Hex (" + i + " ," + grid[i].Count + ")"; Hexagon newHex = newObj.GetComponent <Hexagon>(); yield return(new WaitForSeconds(0.025f)); //Seting a bomb if condition is met if (bombProduction) { soundManager.PlayBombAlert(); newHex.SetBomb(); bombs.Add(newHex); StartCoroutine(newHex.PlayBombAlertAnimCoroutine()); bombProduction = false; } if (colorSeed == null) { newHex.SetColor(hexColorList[Random.Range(0, hexColorList.Count)]); } else { newHex.SetColor(colorSeed[i][grid[i].Count]); } newHex.ChangeGridPosition(new Vector2(i, grid[i].Count)); newHex.ChangeWorldPosition(posToBeMoved); grid[i].Add(newHex); } hexProduction = false; }
/// <summary> /// Change grid and world position of a Hexagon /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="pos"></param> /// <param name="a"></param> void Rotate(int x, int y, Vector2 pos, Hexagon a) { a.ChangeGridPosition(x, y); a.ChangeWorldPosition(pos); }
/// <summary> /// This method will remove matched hexagons from game and open place in logical grid for missing hexagons /// </summary> /// <param name="matchList"></param> /// <returns></returns> public IEnumerator HandleMatch(List <Hexagon> matchList) { if (matchList.Count > 0 && state == States.ExplosionState) { // Sound and score delegates for listeners PlaySound?.Invoke(SoundTypes.Explosion); OnPlayerScore?.Invoke(HexMetrics.SCORE_MULTIPLIER * matchList.Count); foreach (var item in matchList) { if (item.GetType() != typeof(Bomb)) { BombTick?.Invoke(); } //Removing every hex from game logic RemoveHexFromGame(item); yield return(new WaitForSeconds(HexMetrics.EXPLOSION_DELAY)); } yield return(new WaitForSeconds(HexMetrics.AFTER_EXPLOSION_DELAY)); //this loop rearrange all hexes in correct positions for (int x = 0; x < logicalGrid.GetLength(0); x++) { bool space = false; int spaceY = 0; var y = 0; while (y <= logicalGrid.GetLength(1) - 1) { Hexagon h = hexagons[x, y]; if (space) { if (!Helpers.CheckNull(h)) { h.ChangeGridPosition(x, spaceY); logicalGrid[x, spaceY] = false; hexagons[x, y] = null; logicalGrid[x, y] = true; h.ChangeWorldPosition(Helpers.HexOffset(x, spaceY, Helpers.GetGridStartX(gridWidth))); space = false; y = spaceY; spaceY = 0; } } else if (Helpers.CheckNull(h)) { space = true; if (spaceY == 0) { spaceY = y; } } y++; } } SetState(States.PlacingState); StartCoroutine(PlaceCellsOnGrid(logicalGrid, false)); } }