// HORIZONTAL void HorizontalRule() { int random_index = Random.Range(0, m_WordList.Count); WordList.Word Temp_word = m_WordList.GetWord(random_index); Debug.Log(Temp_word.Answer + " Horizontal 단어를 생성합니다."); int x = 0; int y = 0; bool m_Random = false; try { while (!m_Random) { Rand(ref x, ref y); // Rule // y >= 0, Length + y < GridSize if (y >= 0 && Temp_word.Answer.Length + y < GridSize) { if (CheckHorizontal(x, y, random_index)) { m_Random = true; } } } } catch (System.Exception ex) { Debug.LogError(ex.Message); } SetHorizontal(x, y, random_index); }
// HORIZONTAL void HorizontalRule() { int random_index = Random.Range(0, m_WordList.Count); WordList.Word Temp_word = m_WordList.GetWord(random_index); Debug.Log(Temp_word.Answer + " Horizontal 단어를 생성합니다."); int x = 0; int y = 0; Rand(ref x, ref y); // Rule // y >= 0, Length + y < GridSize if (y >= 0 && Temp_word.Answer.Length + y < GridSize) { // 양 옆에 공백이 있는지 확인 if (!CheckHorizontal(x, y, random_index)) { HorizontalRule(); } SetHorizontal(x, y, random_index); } else { HorizontalRule(); } }
// VERTICAL void VerticalRule() { int random_index = Random.Range(0, m_WordList.Count); WordList.Word Temp_word = m_WordList.GetWord(random_index); Debug.Log(Temp_word.Answer + " Vertical 단어를 생성합니다."); int x = 0; int y = 0; Rand(ref x, ref y); // Rule // x >= 0, Length + x < GridSize if (x >= 0 && Temp_word.Answer.Length + x < GridSize) { // 위, 아래에 공백 있는지 확인 if (!CheckVertical(x, y, random_index)) { VerticalRule(); } if (CheckVertical(x, y) <= 0) { VerticalRule(); } SetVertical(x, y, random_index); } else { VerticalRule(); } }
void SetCrossHorizontal() { Debug.Log(m_TempWord.Answer + " Crossed 단어를 생성합니다."); for (int i = 0; i < m_WordList.GetAnswer(m_WordList.FindWord(m_TempWord.Answer)).Length; i++) { SetGrid((int)m_TempWordLoc.x, (int)m_TempWordLoc.y + i, m_WordList.GetAnswer(m_WordList.FindWord(m_TempWord.Answer)), i); } m_WordList.UseIndex(m_WordList.FindWord(m_TempWord.Answer)); m_TempWord = null; print(); }
// Random Setting void DoRandom() { while (true) { // Vertical if (0 == m_WordList.Count) { break; } if (m_TempWord != null) { if (!SetCrossVertical()) { m_TempWord = null; VerticalRule(); } } else { if (!VerticalCrossRule()) { VerticalRule(); } } // Horizontal if (0 == m_WordList.Count) { break; } if (m_TempWord != null) { if (!SetCrossHorizontal()) { m_TempWord = null; HorizontalRule(); } } else { if (!HorizontalCrossRule()) { HorizontalRule(); } } } }
void GridDelete() { if (m_Grid != null) { for (int i = 0; i < GridSize; i++) { for (int j = 0; j < GridSize; j++) { Destroy(m_Grid[i, j]); } } } m_TempWord = null; }
bool SetCrossHorizontal() { if (CheckHorizontal((int)m_TempWordLoc.x, (int)m_TempWordLoc.y, m_WordList.FindWord(m_TempWord.Answer))) { Debug.Log(m_TempWord.Answer + " Crossed 단어를 생성합니다."); for (int i = 0; i < m_WordList.GetAnswer(m_WordList.FindWord(m_TempWord.Answer)).Length; i++) { SetGrid((int)m_TempWordLoc.x, (int)m_TempWordLoc.y + i, m_WordList.GetAnswer(m_WordList.FindWord(m_TempWord.Answer))[i]); } m_WordList.UseIndex(m_WordList.FindWord(m_TempWord.Answer)); m_TempWord = null; print(); return(true); } else { return(false); } }
void MakeGrid(WordList.Word word) { for (int j = 0; j < 3; j++) { int x = Random.Range(0, 10); int y = Random.Range(0, 10); if (CheckVertical(x, y) > 0) { for (int i = 0; i < word.WordInfo.m_CrossWordList.Count; i++) { if (CheckHorizontal(x, y) <= word.WordInfo.m_CrossWordList[i].Length) { SetVertical(x, y, word.ToString().ToUpper()); SetHorizontal(x, y, word.WordInfo.m_CrossWordList[i].ToString().ToUpper()); return; } } } } MakeGrid(word); }
bool HorizontalCrossRule() { int random_index = Random.Range(0, m_WordList.Count); WordList.Word Temp_word = m_WordList.GetWord(random_index); Debug.Log(Temp_word.Answer + " Horizontal Cross 단어를 생성합니다."); // 겹치는 단어가 존재함. if (Temp_word.WordInfo.m_CrossWordList.Count > 0) { int x = 0; int y = 0; bool m_Random = false; int index = 0; int cross_Index = 0; WordList.Word cross_word = new WordList.Word(); string cross_char = ""; try { while (!m_Random) { if (Temp_word.WordInfo.m_CrossWordList.Count > index) { cross_word = Temp_word.WordInfo.m_CrossWordList[index]; cross_char = Temp_word.WordInfo.m_CrossChar[index]; cross_Index = cross_word.FindChar(cross_char); index++; } else { // 10번 검색 실패시 Debug.Log("Cross 단어 생성 실패"); return(false); } for (int i = 0; i < 20; i++) { if (m_Random) { break; } // 겹치는 단어가 아직 생성되지 X if (m_WordList.SearchWord(cross_word.Answer)) { // 겹치는 단어를 저장하고 겹치는 단어의 생성 위치를 고려해준다. Rand(ref x, ref y); // Rule // y - crossword의 앞글자 >= 0, crossword의 뒷글자 + y < GridSize if (x - cross_Index >= 0 && cross_word.Length - cross_Index + x < GridSize && y >= 0 && Temp_word.Answer.Length + y < GridSize) { if (CheckHorizontal(x, y, random_index)) { Debug.Log("성공"); m_TempWord = cross_word; int temp = Temp_word.FindChar(cross_char); m_TempWordLoc = new Vector2(x - temp, y); SetHorizontal(x, y, random_index); print(); return(true); } Debug.Log("겹치는 단어 검출!"); } else { Debug.Log("notyet cross 실패"); } } // 겹치는 단어가 이미 생성되었을때 else { // 겹치는 단어의 위치를 검색해서 해당 위치에 생성할 수 있을때만 생성 Vector2 temp_index = GetGrid(cross_word.Answer, cross_char); // temp_index = 겹치는 위치 if (temp_index != new Vector2(-1, -1)) { x = (int)temp_index.x; y = (int)temp_index.y; // Rule // y - crossword의 앞글자 >= 0, crossword의 뒷글자 + y < GridSize if (x - cross_Index >= 0 && cross_word.Length - cross_Index + x < GridSize) { if (CheckHorizontal(x, y, random_index)) { Debug.Log("성공"); SetVertical(x, y, random_index); m_TempWord = null; print(); return(true); } } else { Debug.Log("already cross 실패"); } } } } } } catch (System.Exception ex) { Debug.LogError(ex.Message); } } return(false); }