public void LoadPentagrams(char[][] letterSets, string[][] words) { _pentagrams = new SmartPentagram[letterSets.Length]; for (int i = 0; i < _pentagrams.Length; i++) { _pentagrams[i] = new SmartPentagram(letterSets[i], words[i]); } }
public void ChangeScroll(SmartPentagram pentagram) { PrepareScroll(PentagramPosition.Back, pentagram); _scrollPlacements[(int)PentagramPosition.Front] .GetScroll() .GetComponent <Animator>() .SetTrigger("ThrownAway"); _activeScroll = _scrollPlacements[1].GetScroll(); }
public void LoadPentagrams(Crossword[] crosswords) { _pentaCounter = 0; _pentagrams = new SmartPentagram[crosswords.Length]; for (int i = 0; i < _pentagrams.Length; i++) { _pentagrams[i] = new SmartPentagram (crosswords[i].GetLetters(), crosswords[i].GetWords()); } }
private void PrepareScroll(PentagramPosition pentagramPosition, SmartPentagram pentagram) { Scroll scroll = _scrollPlacements[(int)pentagramPosition].GetScroll(); scroll.ReturnLettersToPool(); float scrollWidth = GetComponent <RectTransform>().rect.width; //float screenWidth = Screen.width; Debug.Log("ScreenWidth " + screenWidth); float radius = scrollWidth * _pentagramRelativeRadius; float letterSize = scrollWidth * _letterRelativeSize; Debug.Log("letterSize " + letterSize); scroll.Load(pentagram, radius, letterSize); }
public void Load(SmartPentagram pentagram, float radius, float letterSize) { Debug.Log("Scroll: Load. Pentagram is null: " + (pentagram == null)); _pentagram = pentagram; int nLetters = pentagram.Letters().Length; float turningAngle = 2 * Mathf.PI / nLetters; float stepVectorLength = 2 * radius * Mathf.Sin(turningAngle / 2); Debug.Log("Radius: " + radius + "\nStep: " + stepVectorLength); Vector2 letterPosition = new Vector2(0, radius); Vector2 stepVector = new Vector2(0, -stepVectorLength); VectorService.RotateVector(ref stepVector, (turningAngle - Mathf.PI) / 2); Debug.Log("Going to place " + nLetters + "letters."); _pentaLetters = new PentaLetter[nLetters]; for (int i = 0; i < nLetters; i++) { Debug.Log("Placing letter №" + i + ": " + pentagram.Letters()[i]); _pentaLetters[i] = _pool.GetLetter(); _pentaLetters[i].Construct(pentagram.Letters()[i], nLetters); RectTransform rt = _pentaLetters[i].GetComponent <RectTransform>(); rt.SetParent(this.transform); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, letterSize); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, letterSize); rt.anchoredPosition3D = new Vector3(letterPosition.x, letterPosition.y, _letterZ); letterPosition = letterPosition + stepVector; _pentaLetters[i].AddDragEndedCallback(TryActivate); _pentaLetters[i].AddLetterSelectedCallback(SelectLetter); VectorService.RotateVector(ref stepVector, turningAngle); } }
public void NextScroll() { Debug.Log("PuzzleManager: NextScroll"); SmartPentagram newPentagram = _pentaLoader.GetNextPentagram(); _scrollManager.ChangeScroll(newPentagram); if (_pentaLoader.OutOfPentagrams()) { _changeScrollButton.SetActive(false); } _wordsSelectedText = _scrollManager.GetActiveScroll().GetWordsSelectedCounter(); _pentagramsLeftText.text = _pentaLoader.PentagramsLeft() + " свитков осталось."; _maxWords = newPentagram.GetSelectableWords().Count; _wordsSelected = 0; _wordsSelectedText.text = "0 / " + _maxWords + " слов найдено."; _nextScrollCallback(); }
public void LoadPentagrams() { TextAsset textAsset = Resources.Load <TextAsset>(_pentagramsFilePath); StringReader sr = new StringReader(textAsset.text); string[] lineSeparators = { "\n\r", "\n" }; // UNNECESSARY READING OF THE WHOLE FILE HERE. string[] wordSeparators = { ", " }; // THINK OF ANOTHER SOLUTION! string[] lines = sr.ReadToEnd().Split(lineSeparators, System.StringSplitOptions.RemoveEmptyEntries); int n = lines.Length; _pentagrams = new SmartPentagram[n]; string[] row; int nLetters; char[] letters; string[] words; for (int i = 0; i < n; i++) { // LINE IS SPLIT IN TOO MANY STRINGS. SOLUTION CAN BE WAY MORE ELEGANT! row = lines[i].Split(wordSeparators, System.StringSplitOptions.RemoveEmptyEntries); nLetters = int.Parse(row[0]); letters = new char[nLetters]; for (int j = 0; j < nLetters; j++) { letters[j] = row[j + 1][0]; } int nWords = row.Length - nLetters - 1; words = new string[nWords]; for (int j = 0; j < nWords; j++) { words[j] = row[j + nLetters + 1]; } _pentagrams[i] = new SmartPentagram(letters, words); } }