GridLetter CreateGridLetter(Vector2 position) { GridLetter gl = Instantiate(gridLetterPrefab, Vector3.zero, Quaternion.identity) as GridLetter; gl.gameObject.transform.SetParent(gameObject.transform, false); RectTransform glRectTransform = (RectTransform)gl.gameObject.transform; glRectTransform.anchoredPosition = new Vector3(position.x, position.y, 0); return(gl); }
// corruption 0-1, void RenderGridLetter(GridLetter gl, System.Char letter, float corruption, bool target) { // UN-corruption % chance to get properly colorized if (target && Random.value > corruption) { gl.LetterStyle(style.highlights[0]); // TODO: pick a SPECIFIC highlight for codeword } // % chance a non-target gets colorized else if (Random.value > (1 - percentFalsePositives)) { gl.LetterStyle(style.highlights[0]); // TODO: random highlights for false positives } else { gl.LetterStyle(style.primary); } // corruption % chance will randomly replace with symbol float clarity = Random.value; if (clarity > corruption) { gl.Unglitch(); gl.SetLetter(letter); } // corruption is low enough to show symbol else if (clarity < percentThresholdGlitch) { gl.Unglitch(); gl.SetLetter( corruptedSymbol[Random.Range(0, corruptedSymbol.Length)] ); } // glitch else { gl.Glitch(); } }
public void addLetter(GridLetter letter) { Letters.Add(letter); }
private bool tryToAddWordToGrid(string word) { int randomDirectionIndex = (int)Math.Floor(UnityEngine.Random.Range(0f, Directions.Count - 1)); //randomDirectionIndex = indexTestCount; //indexTestCount++; Vector2 direction = Directions[randomDirectionIndex]; int xMin = direction.x == -1 ? word.Length - 1 : 0; // 1 or word.Length int xMax = direction.x == 1 ? gridWidth - word.Length : gridWidth - 1; //gridWidth or GridWidth - word.Length int yMin = direction.y == -1 ? word.Length - 1 : 0; //1 or word.Length int yMax = direction.y == 1 ? gridHeight - word.Length + 1 : gridHeight - 1; //gridHeight or GridHeight - word.Length GameObject checkLetter; bool wordPlaced = false; int gridX = 0; int gridY = 0; int foundX = 0; int foundY = 0; for (int x = xMin; x <= xMax; x++) { for (int y = yMin; y <= yMax; y++) { if (!wordPlaced) { gridX = x; gridY = y; wordPlaced = true; for (int li = 0; li < word.Length; li++) { if (gridY < GridLetters.Count && gridX < GridLetters[gridY].Count) { checkLetter = GridLetters[gridY][gridX]; GridLetter gridLetter = checkLetter.GetComponent <GridLetter>(); if (gridLetter.isRandomLetter || gridLetter.letter == word[li]) { //wordPlaced = true; } else { wordPlaced = false; } gridX += (int)direction.x; gridY += (int)direction.y; } else { wordPlaced = false; } } if (wordPlaced) { foundX = x; foundY = y; } } } } int wordPlaceX = 0; int wordPlaceY = 0; if (wordPlaced) { wordPlaceX = foundX; wordPlaceY = foundY; GridWord gridWord = new GridWord(word, foundX, foundY, direction); for (int li = 0; li < word.Length; li++) { GridLetter gridLetter = GridLetters[wordPlaceY][wordPlaceX].GetComponent <GridLetter>(); gridLetter.letter = word[li]; gridLetter.displayLetter.GetComponent <Text>().text = word[li].ToString().ToUpper(); gridLetter.isRandomLetter = false; if (li == 0 || li == word.Length - 1) { gridLetter.isEndLetter = true; } gridWord.addLetter(gridLetter); gridLetter.addWord(gridWord); wordPlaceX += (int)direction.x; wordPlaceY += (int)direction.y; } GridWords.Add(gridWord); } return(wordPlaced); }