//Todo: make sure the first two words don't spawn on the same line. void GenerateNewCell(int index = -1) { SimpleWord word = GetNextWord(); if (EmptyCells.Count > 0 && word != null) { shownWords++; int newCellIndex = index; //if we don't specify a position, generate one randomly if (index == -1) { newCellIndex = UnityEngine.Random.Range(0, EmptyCells.Count); } //random // int randomNum = UnityEngine.Random.Range(0, 10); //0-9 // if(randomNum == 0) // EmptyCells[newNumberIndex].Number = 2; EmptyCells[newCellIndex].SetText(word, 2); // EmptyCells[newCellIndex].PlayAppearAnimation(); Debug.Log("Adding " + word.Word + " on the board."); EmptyCells.RemoveAt(newCellIndex); } if (word == null && GetActiveCellCount() == 0) { //You won GameOver("You won!"); } }
public void SetText(SimpleWord word, int style) { cellStyle = style; this.Word = word; if (cellStyle == 0) { SetHidden(); } else { ApplyStyle(cellStyle); SetVisible(); } }
SimpleWord GetNextWord() { //Reset the list if we're at the end and in infinity mode if ((Mode == PlayMode.Infinity || Mode == PlayMode.TimeAttack) && wordIndex >= wordStream.Count) { wordIndex = 0; currentSet.Clear(); } //Working in smaller sets makes sure that when dealing with large lists of words, a related word will be spawned soon. if (currentSet.Count == 0) { //Take 4 (SetCount public variable) starting at the right position currentSet = wordStream.Skip(wordIndex).Take(SetCount).ToList(); wordIndex += SetCount; if (wordIndex >= wordStream.Count) { return(null); } //randomize System.Random rnd = new System.Random(); currentSet.OrderBy((item) => rnd.Next()).ToList(); string debugline = "New set: "; foreach (SimpleWord item in currentSet) { debugline += item.Word + ". "; } Debug.Log(debugline); } SimpleWord w = currentSet[0]; currentSet.RemoveAt(0); return(w); }
public void Setup() { instance = CreateSimpleWord(); }