단어 찾기
방대한 양의 단어들을 찾기 위하여, K-ICT 빅데이터센터에서 형태소 사전을 가져왔다. 초기 단어는 100만개로 그 중 3,4,5 음절인 단어를 추출하기 위하여,
단어를 “우리말샘”이라는 국립국어원의 자식 사이트에서 크롤링을 통해 검색하고, 북한말이거나 방언인 것을 모두 걸러내었다. 그렇게 생성된 단어가 19만개이다.
이 부분부터는 모두 수기로 추출해야 하며, 추출하는 사람에 따라 난이도가 결정되어 쉽사리 진행하지 못하고 있다. (5음절의 단어는 사용 x)
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
string line;
static void LineChanger(string newText, string fileName, int line_to_edit)
{
string[] arrLine = File.ReadAllLines(fileName, Encoding.Default);
arrLine[line_to_edit ] = newText;
File.WriteAllLines(fileName, arrLine, Encoding.Default);
}
bool IsElementPresent(IWebDriver _driver, By _by)
{
try
{
_driver.FindElement(_by);
return true;
}
catch(NoSuchElementException)
{
return false;
}
}
using (IWebDriver driver = new ChromeDriver())
{
var tntwk=86040;
var file = new StreamReader(File.OpenRead(@"word3.csv"));
for(int i=0;i<+tntwk;i++)
{
line =file.ReadLine();
}
int index=tntwk;
while((line=file.ReadLine())!=null)
{
driver.Url = "https://opendic.korean.go.kr/search/searchResult?query="+ line +"&dicType=1&wordMatch=Y&searchType=¤tPage=1&cateCode=&fieldCode=&spCode=&divSearch=search&infoType=confirm&rowsperPage=10&sort=W&side_data=0%7C1285415";
var options = new ChromeOptions(); //계속해서 크롤링을 할 경우 사이트에서 해킹 공격으로 판단하여 ip가 차단
options.AddArgument("--test-type");
options.AddArgument("--disable-extensions");
options.AddArguments("disable-infobars");
options.AddArguments("--disable-notifications");
options.AddArguments("enable-automation");
options.AddArguments("--disable-popup-blocking");
options.AddArguments("start-maximized");
// find 할때 찾을때까지 기다리는 seconds 설정
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0.1);
// id="content" 라는 element에 있는 li tag 를 모두 가져옴
var elements = driver.FindElements(By.CssSelector("#content li"));
int mean_ =2;
foreach(var el in elements)
{
// 각각의 li 에서 원하는 데이터를 찾는다. span tag 중 class 명이 main_title 인 element
string meaning = el.FindElement(By.CssSelector("a.tab_tit")).Text.Trim();
if(meaning=="어휘 0")
{
mean_=0;
break;
}
else if(meaning=="어휘 1")
{
mean_=1;
break;
}
else
{
break;
}
}
var elements2 = driver.FindElements(By.CssSelector("#searchPaging dd"));
if(mean_==1)
{
foreach(var el2 in elements2)
{
if(IsElementPresent(driver,By.ClassName("word_att_type3"))==true)
{
Console.WriteLine((index+1)+" " +line + " 삭제 " );
break;
}
else
{
Console.WriteLine((index+1)+" " +line );
}
if(IsElementPresent(driver,By.ClassName("word_att_type2"))==true)
{
LineChanger(line+","+el2.FindElement(By.CssSelector("span.word_att_type2")).Text, "word3_ver1.csv", index);
index++;
break;
}
else
{
LineChanger(line+", ", "word3_ver1.csv", index);
break;
}
}
}
else if(mean_==0)
{
Console.WriteLine(line + " 삭제 " + (index+1));
}
else
{
LineChanger(line +", 2", "word3_ver1.csv", index);
index++;
}
}
}
단어를 csv 파일로 저장
단어를 한개의 csv 파일로 저장했을 때 while문을 19만개인 line을 30번이상 실행하다 보니 게임 한판 만들어지는데
소모 시간이 수십분이 걸렸다. 현재에는 csv 파일을 2만개로 쪼개서 while문을 돌다 보니 최대 10초로 줄어들었다.
csv 파일을 읽는 데에 csv reader도 필요로 하다.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class CSVReader
{
static string SPLIT_RE = @",(?=(?:[^""]*""[^""]*"")*(?![^""]*""))";
static string LINE_SPLIT_RE = @"\r\n|\n\r|\n|\r";
static char[] TRIM_CHARS = { '\"' };
public static List<Dictionary<string, object>> Read(string file)
{
var list = new List<Dictionary<string, object>>();
TextAsset data = Resources.Load(file) as TextAsset;
var lines = Regex.Split(data.text, LINE_SPLIT_RE);
if (lines.Length <= 1) return list;
var header = Regex.Split(lines[0], SPLIT_RE);
for (var i = 1; i < lines.Length; i++)
{
var values = Regex.Split(lines[i], SPLIT_RE);
if (values.Length == 0 || values[0] == "") continue;
var entry = new Dictionary<string, object>();
for (var j = 0; j < header.Length && j < values.Length; j++)
{
string value = values[j];
value = value.TrimStart(TRIM_CHARS).TrimEnd(TRIM_CHARS).Replace("\\", "");
object finalvalue = value;
int n;
float f;
if (int.TryParse(value, out n))
{
finalvalue = n;
}
else if (float.TryParse(value, out f))
{
finalvalue = f;
}
entry[header[j]] = finalvalue;
}
list.Add(entry);
}
return list;
}
}
Dontdestroy
BGM은 메인메뉴 -> 인게임 부분이 이어지게
private GameObject[] musics;
private AudioSource audiosource;
void Awake()
{
musics = GameObject.FindGameObjectsWithTag("Music");
if(musics.Length>=2)
{
Destroy(this.gameObject);
}
DontDestroyOnLoad(transform.gameObject);
audiosource = GetComponent<AudioSource>();
}
public void PlayMusic()
{
if (audiosource.isPlaying) return;
audiosource.Play();
}
public void StopMusic()
{
audiosource.Stop();
}
배경화면 움직임
게임 플레이를 보면 메인화면의 배경이 흐르는 것처럼 보인다.
private MeshRenderer render;
public float speed;
private float offset;
// Start is called before the first frame update
void Start()
{
render = GetComponent<MeshRenderer>();
}
// Update is called once per frame
void Update()
{
offset += Time.deltaTime * speed;
render.material.mainTextureOffset = new Vector2(offset, offset);
}
Pause
게임 중 일시정지로 일시정지 창이 뜨며 일시정지 중 단어를 맞출 수 없게 게임 주요화면이 Active false가 된다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Pause : MonoBehaviour
{
bool IsPause;
public GameObject pause_pannel;
public GameObject backboard;
public GameObject touchboard;
// Use this for initialization
void Start()
{
IsPause = false;
}
// Update is called once per frame
public void btn_on()
{
/*일시정지 활성화*/
if (IsPause == false)
{
pause_pannel.transform.gameObject.SetActive(true);
touchboard.SetActive(false);
backboard.transform.gameObject.SetActive(false);
IsPause = true;
return;
}
/*일시정지 비활성화*/
if (IsPause == true)
{
backboard.transform.gameObject.SetActive(true);
touchboard.SetActive(true);
pause_pannel.transform.gameObject.SetActive(false);
IsPause = false;
return;
}
}
}
어플리케이션 종료
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Quit : MonoBehaviour
{
public void OnClickExit(){
Application.Quit();
Debug.Log("Button Click");
}
}
PlayerPrefs
게임의 스테이지 정보를 저장한다.
볼륨 조절
슬라이드 바로 볼륨 조절
- BGM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Audio;
public class SetBGM : MonoBehaviour
{
public AudioMixer mixer;
public Slider slider;
// Start is called before the first frame update
void Start()
{
slider.value = PlayerPrefs.GetFloat("BGM_VOLUME", 0.75f);
}
// Update is called once per frame
public void SetLevel(float sliderValue)
{
mixer.SetFloat("BGM_VOLUME", Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat("BGM_VOLUME", sliderValue);
}
}
- SFX
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Audio;
public class SetSFX : MonoBehaviour
{
public AudioMixer mixer;
public Slider slider;
// Start is called before the first frame update
void Start()
{
slider.value = PlayerPrefs.GetFloat("SFX_VOLUME", 0.75f);
}
// Update is called once per frame
public void SetLevel(float sliderValue)
{
mixer.SetFloat("SFX_VOLUME", Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat("SFX_VOLUME", sliderValue);
}
}
인게임
- 디자인
- 코드
시작 단어 위치 정하기
void Start()
{
if (Tile[0].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[0].gameObject.transform.position;
curcurname = Tile[0];
}
else if (Tile[1].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[1].gameObject.transform.position;
curcurname = Tile[1];
}
else if (Tile[2].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[2].gameObject.transform.position;
curcurname = Tile[2];
}
else if (Tile[10].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[10].gameObject.transform.position;
curcurname = Tile[10];
}
else if (Tile[11].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[11].gameObject.transform.position;
curcurname = Tile[11];
}
else if (Tile[12].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[12].gameObject.transform.position;
curcurname = Tile[12];
}
else if (Tile[20].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[20].gameObject.transform.position;
curcurname = Tile[20];
}
else if (Tile[21].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[21].gameObject.transform.position;
curcurname = Tile[21];
}
else if (Tile[22].GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
this.transform.position = Tile[22].gameObject.transform.position;
curcurname = Tile[22];
}
}
- 터치 이벤트 관리
if (Input.touchCount > 0)
{
Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.zero);
if (hit)
{
if (hit.transform.position == curcurname.transform.position)
{
if (curcurname.transform.Find("Text").GetComponent<Text>().text != "" && hit.transform.GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1")
{
for (int i = 0; i < (N - 2) * 5; i++)
{
if (Touchtile[i].activeSelf == false)
{
if (Touchtile[i].transform.Find("Text").GetComponent<Text>().text == curcurname.transform.Find("Text").GetComponent<Text>().text)
{
Touchtile[i].SetActive(true);
audio.GetComponent<AudioSource>().Play();
break;
}
}
}
curcurname.transform.Find("Text").GetComponent<Text>().text = "";
}
}
if (hit.transform.gameObject.GetComponent<SpriteRenderer>().sprite.name.Substring(0, 5) == "tile1"&&curcurname!=hit.transform.gameObject)
{
this.transform.position = hit.transform.position;
curcurname = hit.transform.gameObject;
audio.GetComponent<AudioSource>().Play();
}
}
}
- 클리어 이벤트
for (int i = 0; i < Cntword(); i++)
{
if (word[i].clear_word == true)
{
if (i == Cntword() - 1)
{
clear_pannel.SetActive(true);
txt_clear.GetComponent<Text>().text = PlayerPrefs.GetInt("stage_num").ToString() + "단계 클리어!";
PlayerPrefs.SetInt("stage_num", PlayerPrefs.GetInt("stage_num") + 1);
PlayerPrefs.Save();
btn_hint.SetActive(false);
btn_pause.SetActive(false);
backboard.SetActive(false);
touchboard.SetActive(false);
this.GetComponent<Stage100_1>().enabled = false;
}
}
else
{
break;
}
}
- 단어 섞기
void ShuffleArray<T>(T[] array)
{
int random1;
int random2;
int cnt = Cntsyllable();
T tmp;
for (int index = 0; index < cnt; ++index)
{
random1 = UnityEngine.Random.Range(0, cnt);
random2 = UnityEngine.Random.Range(0, cnt);
tmp = array[random1];
array[random1] = array[random2];
array[random2] = tmp;
}
}
- 빈 칸 선택하기
void Chooseeraseword()
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
int lucky = Random.Range(0, 4);
if (Wordarray[i, j] != "-1" && Wordarray[i, j] != "0")
{
if (lucky != 0)
{
for (int k = 0; k < N * N; k++)
{
if (Syllablearray[k] == "0")
{
Syllablearray[k] = Wordarray[i, j];
Wordarray[i, j] = "1";
break;
}
}
}
}
}
}
}
- 다음 단어의 가능한 길이, 위치 정하기
//가능한 길이, 좌표 정하기
void Chooselength(int _word)
{
int cnt = 0;
int nowpositionX = 0;
int nowpositionY = 0;
while (true)
{
if (_word == cnt)
{
Finished();
break;
}
int cntfive = 0;
//이전 단어에서 받아온 인덱스 값을 이용하여 세로일 경우 y 좌표값, 가로일 경우 x 좌표값을 고정
int index = Choosesyllable(_word - cnt);
//세로 (x좌표 고정)
if (word[_word - 1 - cnt].worddirection == true)
{
nowpositionX = word[_word - 1 - cnt].startpositionX + index;
nowpositionY = word[_word - 1 - cnt].startpositionY;
}
//가로 (y좌표 고정)
else
{
nowpositionX = word[_word - 1 - cnt].startpositionX;
nowpositionY = word[_word - 1 - cnt].startpositionY + index;
}
//5음절인 단어 찾기
for (int i = 0; i < 100; i++)
{
if (word[i].wordlen == 5)
{
cntfive++;
}
}
//이전 단어가 세로일 경우
if (word[_word - 1 - cnt].worddirection == true)
{
//단어가 들어 갈 수 없다면(합이 2보다 작을 경우) X
if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] < 2)
{
cnt++;
Checksyllableonbeforeword();
continue;
//불가능
}
//불가능한 경우가 많아 배제 X
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 1 && possiblesyllable[_word - 1 - cnt, 1, index] == 1)
{
cnt++;
Checksyllableonbeforeword();
continue;
//불가능
}
//왼쪽이 2 오른쪽 0
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 2 && possiblesyllable[_word - 1 - cnt, 1, index] == 0)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = 3;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 2;
break;
}
//왼쪽이 0 오른쪽 2
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 0 && possiblesyllable[_word - 1 - cnt, 1, index] == 2)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = 3;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY;
break;
}
//좌우합 3
else if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] == 3)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = 4;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - possiblesyllable[_word - 1 - cnt, 0, index];
break;
}
//좌우합 4, 현재 라운드의 5음절 단어의 갯수가 1개 이하라면
/*else if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] == 4 && cntfive < 1)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = 5;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - possiblesyllable[_word - 1 - cnt, 0, index];
break;
}*/
//왼쪽이 1, 오른쪽은 3보다크거나 같다면
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 1 && possiblesyllable[_word - 1 - cnt, 1, index] >= 3)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = 4;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 1;
break;
}
//왼쪽이 3보다 크거나 같고, 오른쪽이 1
else if (possiblesyllable[_word - 1 - cnt, 0, index] >= 3 && possiblesyllable[_word - 1 - cnt, 1, index] == 1)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = 4;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 2;
break;
}
//나머지 경우
else if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] >= 4)
{
//왼쪽이 오른쪽보다 클 경우
if (possiblesyllable[_word - 1 - cnt, 0, index] > possiblesyllable[_word - 1 - cnt, 1, index])
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 2;
break;
}
//4일 경우
else
{
if (possiblesyllable[_word - 1 - cnt, 1, index] == 0)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 3;
break;
}
else if (possiblesyllable[_word - 1 - cnt, 1, index] == 2)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - Random.Range(1, 4);
break;
}
else
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - Random.Range(0, 4);
break;
}
}
}
//왼쪽이 오른쪽보다 작을 경우
else if (possiblesyllable[_word - 1 - cnt, 0, index] < possiblesyllable[_word - 1 - cnt, 1, index])
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY;
break;
}
//4일 경우
else
{
if (possiblesyllable[_word - 1 - cnt, 0, index] == 0)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY;
break;
}
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 2)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - Random.Range(0, 3);
break;
}
else
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - Random.Range(0, 4);
break;
}
}
}
//왼쪽과 오른쪽의 길이가 같을 경우
else
{
//왼2 오른2
if (possiblesyllable[_word - 1 - cnt, 0, index] == 2 && possiblesyllable[_word - 1 - cnt, 1, index] == 2)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 2 * Random.Range(0, 2);
break;
}
//4일 경우
else
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - Random.Range(1, 3);
break;
}
}
else
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = false;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - 2 * Random.Range(0, 2);
break;
}
//4일 경우
else
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY - Random.Range(0, 4);
break;
}
}
}
}
}
//이전 단어가 가로일 경우
else
{
//단어가 들어 갈 수 없다면(합이 2보다 작을 경우) X
if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] < 2)
{
cnt++;
Checksyllableonbeforeword();
continue;
//불가능
}
//불가능한 경우가 많아 배제 X
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 1 && possiblesyllable[_word - 1 - cnt, 1, index] == 1)
{
cnt++;
Checksyllableonbeforeword();
continue;
//불가능
}
//위쪽이 2 아래쪽 0
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 2 && possiblesyllable[_word - 1 - cnt, 1, index] == 0)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = 3;
word[_word].startpositionX = nowpositionX - 2;
word[_word].startpositionY = nowpositionY;
break;
}
//위쪽이 0 아래쪽 2
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 0 && possiblesyllable[_word - 1 - cnt, 1, index] == 2)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = 3;
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY;
break;
}
//위아래합 3
else if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] == 3)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = 4;
word[_word].startpositionX = nowpositionX - possiblesyllable[_word - cnt - 1, 0, index];
word[_word].startpositionY = nowpositionY;
break;
}
//위아래합 4, 현재 라운드의 5음절 단어의 갯수가 1개 이하라면
/*else if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] == 4 && cntfive < 1)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = 5;
word[_word].startpositionX = nowpositionX - possiblesyllable[_word - 1 - cnt, 0, index];
word[_word].startpositionY = nowpositionY;
break;
}*/
//위쪽이 1, 아래쪽은 3보다크거나 같다면
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 1 && possiblesyllable[_word - 1 - cnt, 1, index] >= 3)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = 4;
word[_word].startpositionX = nowpositionX - 1;
word[_word].startpositionY = nowpositionY;
break;
}
//위쪽이 3보다 크거나 같고, 아래쪽이 1
else if (possiblesyllable[_word - 1 - cnt, 0, index] >= 3 && possiblesyllable[_word - 1 - cnt, 1, index] == 1)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = 4;
word[_word].startpositionX = nowpositionX - 2;
word[_word].startpositionY = nowpositionY;
break;
}
//나머지 경우
else if (possiblesyllable[_word - 1 - cnt, 0, index] + possiblesyllable[_word - 1 - cnt, 1, index] >= 4)
{
//위쪽이 아래쪽보다 클경우
if (possiblesyllable[_word - 1 - cnt, 0, index] > possiblesyllable[_word - cnt - 1, 1, index])
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX - 2;
word[_word].startpositionY = nowpositionY;
break;
}
//4일 경우
else
{
if (possiblesyllable[_word - 1 - cnt, 1, index] == 0)
{
word[_word].startpositionX = nowpositionX - 3;
word[_word].startpositionY = nowpositionY;
break;
}
else if (possiblesyllable[_word - 1 - cnt, 1, index] == 2)
{
word[_word].startpositionX = nowpositionX - Random.Range(1, 4);
word[_word].startpositionY = nowpositionY;
break;
}
else if (possiblesyllable[_word - 1 - cnt, 1, index] >= 3)
{
word[_word].startpositionX = nowpositionX - Random.Range(0, 4);
word[_word].startpositionY = nowpositionY;
break;
}
}
}
//위쪽이 아래쪽보다 작을 경우
else if (possiblesyllable[_word - 1 - cnt, 0, index] < possiblesyllable[_word - 1 - cnt, 1, index])
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY;
break;
}
//4일 경우
else
{
if (possiblesyllable[_word - 1 - cnt, 0, index] == 0)
{
word[_word].startpositionX = nowpositionX;
word[_word].startpositionY = nowpositionY;
break;
}
else if (possiblesyllable[_word - 1 - cnt, 0, index] == 2)
{
word[_word].startpositionX = nowpositionX - Random.Range(0, 2);
word[_word].startpositionY = nowpositionY;
break;
}
else if (possiblesyllable[_word - 1 - cnt, 0, index] > 2)
{
word[_word].startpositionX = nowpositionX - Random.Range(0, 4);
word[_word].startpositionY = nowpositionY;
break;
}
}
}
//위쪽과 아래쪽의 길이가 같을 경우
else
{
//왼2 오른2
if (possiblesyllable[_word - 1 - cnt, 0, index] == 2 && possiblesyllable[_word - 1 - cnt, 1, index] == 2)
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX - 2 * Random.Range(0, 2);
word[_word].startpositionY = nowpositionY;
break;
}
//4일 경우
else
{
word[_word].startpositionX = nowpositionX - Random.Range(1, 3);
word[_word].startpositionY = nowpositionY;
break;
}
}
else
{
word[_word] = new wordsheet();
word[_word].wordname = "";
word[_word].worddirection = true;
word[_word].wordlen = Random.Range(3, 5);
//3일 경우
if (word[_word].wordlen == 3)
{
word[_word].startpositionX = nowpositionX - 2 * Random.Range(0, 2);
word[_word].startpositionY = nowpositionY;
break;
}
//4일 경우
else
{
word[_word].startpositionX = nowpositionX - Random.Range(0, 4);
word[_word].startpositionY = nowpositionY;
break;
}
}
}
}
}
}
}
- 단어를 넣은 다음 단어가 들어올 수 없는 곳 지우기
int Eraseimpossiblearray()
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (Wordarray[i, j] == "0")
{
if (i == 0)
{
if (j == 0)
{
if (Wordarray[i, j + 1] == "1")
{
if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i, j + 1] == "-1")
{
if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i + 1, j] == "-1")
{
if (Wordarray[i, j + 1] == "1")
{
Wordarray[i, j] = "-1";
}
}
}
else if (j == N - 1)
{
if (Wordarray[i, j - 1] == "1")
{
if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i, j - 1] == "-1")
{
if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i + 1, j] == "-1")
{
if (Wordarray[i, j - 1] == "1")
{
Wordarray[i, j] = "-1";
}
}
}
else
{
if (Wordarray[i + 1, j] == "1")
{
if (Wordarray[i, j - 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i + 2, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
}
else if (i == N - 1)
{
if (j == 0)
{
if (Wordarray[i, j + 1] == "1")
{
if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i - 1, j] == "-1")
{
if (Wordarray[i, j + 1] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i, j + 1] == "-1")
{
if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
}
else if (j == N - 1)
{
if (Wordarray[i, j - 1] == "1")
{
if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i, j - 1] == "-1")
{
if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
else if (Wordarray[i - 1, j] == "-1")
{
if (Wordarray[i, j - 1] == "1")
{
Wordarray[i, j] = "-1";
}
}
}
else
{
if (Wordarray[i - 1, j] == "1")
{
if (Wordarray[i, j - 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i - 2, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
}
else if (j == 0)
{
if (Wordarray[i, j + 1] == "1")
{
if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 2] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
else if (j == N - 1)
{
if (Wordarray[i, j - 1] == "1")
{
if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j - 2] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
else
{
if (Wordarray[i - 1, j] == "1")
{
if (Wordarray[i, j - 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i + 1, j] == "1" && Wordarray[i, j - 1] == "-1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i + 1, j] == "1" && Wordarray[i, j + 1] == "-1")
{
Wordarray[i, j] = "-1";
}
}
if (Wordarray[i + 1, j] == "1")
{
if (Wordarray[i, j - 1] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 1] == "1")
{
Wordarray[i, j] = "-1";
}
}
if (Wordarray[i, j - 1] == "1")
{
if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 1] == "1" && Wordarray[i + 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i, j + 1] == "1" && Wordarray[i - 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
if (Wordarray[i, j + 1] == "1")
{
if (Wordarray[i + 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
else if (Wordarray[i - 1, j] == "1")
{
Wordarray[i, j] = "-1";
}
}
if (i > 1)
{
if (Wordarray[i - 1, j] == "1")
{
if (Wordarray[i - 2, j] == "-1" && Wordarray[i + 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (i < N - 2)
{
if (Wordarray[i + 1, j] == "1")
{
if (Wordarray[i + 2, j] == "-1" && Wordarray[i - 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (j > 1)
{
if (Wordarray[i, j - 1] == "1")
{
if (Wordarray[i, j - 2] == "-1" && Wordarray[i, j + 1] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (j < N - 2)
{
if (Wordarray[i, j + 1] == "1")
{
if (Wordarray[i, j + 2] == "-1" && Wordarray[i, j - 1] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (i == 1)
{
if (Wordarray[i - 1, j] == "1")
{
if (Wordarray[i + 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (i == N - 2)
{
if (Wordarray[i + 1, j] == "1")
{
if (Wordarray[i - 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (j == 1)
{
if (Wordarray[i, j - 1] == "1")
{
if (Wordarray[i, j + 1] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
if (j == N - 2)
{
if (Wordarray[i + 1, j] == "1")
{
if (Wordarray[i - 1, j] == "-1")
{
Wordarray[i, j] = "-1";
}
}
}
}
}
}
}
return 0;
}
- array에 저장되어 있는 정보를 Tile object로 옮기기
int Sheet2object()
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (Wordarray[i, j] == "0")
{
GameObject tile = Tile[i * 10 + j];
Text text = tile.transform.Find("Text").GetComponent<Text>();
text.text = "";
int random_num = Random.Range(0, 5);
tile.GetComponent<SpriteRenderer>().sprite =Resources.Load<Sprite>("tile3-"+random_num.ToString());
}
else if (Wordarray[i, j] == "-1")
{
GameObject tile = Tile[i * 10 + j];
Text text = tile.transform.Find("Text").GetComponent<Text>();
text.text = "";
int random_num = Random.Range(0, 5);
tile.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("tile3-" + random_num.ToString());
}
else if (Wordarray[i, j] == "1")
{
GameObject tile = Tile[i * 10 + j];
Text text = tile.transform.Find("Text").GetComponent<Text>();
text.text = "";
int random_num = Random.Range(0, 5);
tile.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("tile1-" + random_num.ToString());
}
else
{
GameObject tile = Tile[i * 10 + j];
Text text = tile.transform.Find("Text").GetComponent<Text>();
text.text = Wordarray[i, j];
int random_num = Random.Range(0, 5);
tile.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("tile2-"+random_num.ToString());
}
}
}
return 0;
}
- 단어 찾기
void Chooseword()
{
for (int i = 0; i < Cntword(); i++)
{
int flag = 0;
int[] temp = { -1, -1, -1 };
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
if (Wordarray[word[i].startpositionX + j, word[i].startpositionY] != "1")
{
flag++;
temp[flag - 1] = j;
}
}
else
{
if (Wordarray[word[i].startpositionX, word[i].startpositionY + j] != "1")
{
flag++;
temp[flag - 1] = j;
}
}
}
if (word[i].wordlen == 3)
{
List<Dictionary<string, object>> data_Dialog = CSVReader.Read("word3_"+Random.Range(1,7).ToString());
if (flag == 0)
{
word[i].wordname = data_Dialog[Random.Range(0, data_Dialog.Count)]["name"].ToString();
}
else if (flag == 1)
{
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX + temp[0], word[i].startpositionY] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Random.Range(0, 2) == 1 && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
else
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX, word[i].startpositionY + temp[0]] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Random.Range(0, 2) == 1 && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
}
}
else if (flag == 2)
{
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX + temp[0], word[i].startpositionY] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Wordarray[word[i].startpositionX + temp[1], word[i].startpositionY] == data_Dialog[k]["name"].ToString().Substring(temp[1], 1) && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
else
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX, word[i].startpositionY + temp[0]] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Wordarray[word[i].startpositionX, word[i].startpositionY + temp[1]] == data_Dialog[k]["name"].ToString().Substring(temp[1], 1) && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
}
}
if (word[i].wordname == "")
{
erasebofore(i-1);
i=i-2;
}
else
{
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
Wordarray[word[i].startpositionX + j, word[i].startpositionY] = word[i].wordname.Substring(j, 1);
}
else
{
Wordarray[word[i].startpositionX, word[i].startpositionY + j] = word[i].wordname.Substring(j, 1);
}
}
}
}
else if (word[i].wordlen == 4)
{
List<Dictionary<string, object>> data_Dialog = CSVReader.Read("word4_"+Random.Range(1,5).ToString());
if (flag == 0)
{
word[i].wordname = data_Dialog[Random.Range(0, data_Dialog.Count)]["name"].ToString();
}
else if (flag == 1)
{
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX + temp[0], word[i].startpositionY] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Random.Range(0, 2) == 1 && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
else
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX, word[i].startpositionY + temp[0]] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Random.Range(0, 2) == 1 && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
}
}
else if (flag == 2)
{
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX + temp[0], word[i].startpositionY] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Wordarray[word[i].startpositionX + temp[1], word[i].startpositionY] == data_Dialog[k]["name"].ToString().Substring(temp[1], 1) && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
else
{
for (int k = 0; k < data_Dialog.Count; k++)
{
if (Wordarray[word[i].startpositionX, word[i].startpositionY + temp[0]] == data_Dialog[k]["name"].ToString().Substring(temp[0], 1) && Wordarray[word[i].startpositionX, word[i].startpositionY + temp[1]] == data_Dialog[k]["name"].ToString().Substring(temp[1], 1) && Checkword(data_Dialog[k]["name"].ToString()) == 0)
{
word[i].wordname = data_Dialog[k]["name"].ToString();
break;
}
}
}
}
}
if (word[i].wordname == "")
{
erasebofore(i-1);
i=i-2;
}
else
{
for (int j = 0; j < word[i].wordlen; j++)
{
if (word[i].worddirection == true)
{
Wordarray[word[i].startpositionX + j, word[i].startpositionY] = word[i].wordname.Substring(j, 1);
}
else
{
Wordarray[word[i].startpositionX, word[i].startpositionY + j] = word[i].wordname.Substring(j, 1);
}
}
}
}
}
}