// Use this for initialization void Start() { TxtController.getInstance().readTxt(); //ms.setChoosenMap(1); map = new Map(21, 21); //Debug.Log(ms.getChoosenMap()); if (ms.getChoosenMap() == 0) { map = new Prim(21, 21).createPrim(); } else if (ms.getChoosenMap() == 1) { map = new BSP(21, 21).createBSP(); generateTreasure(); } else if (ms.getChoosenMap() == 2) { map = new Map(21, 21); scanMap("Assets/Resources/Map1.txt"); if (ms.getToPlay() == true) { generateEnemy(); generateTreasure(); } } else if (ms.getChoosenMap() == 3) { map = new Map(21, 21); scanMap("Assets/Resources/Map2.txt"); if (ms.getToPlay() == true) { generateEnemy(); generateTreasure(); } } else if (ms.getChoosenMap() == 4) { map = new Map(21, 21); scanMap("Assets/Resources/Map3.txt"); if (ms.getToPlay() == true) { generateEnemy(); generateTreasure(); } } // map.printMap(); }
// Update is called once per frame void Update() { if (Enemy.count <= 0 && isGameFinish == false) { //Debug.Log("Count = 0 " + Enemy.count); int temp = (ms.getChoosenMap() == 1) ? 0 : ms.getChoosenMap(); Debug.Log("Temp: " + temp); ms.setChoosenMap(temp); TxtController.getInstance().updateText(); timer = Time.time; isGameFinish = true; //Debug.Log(timer); } if (PlayerCode.isDeath == true && isGameFinish == false) { //Debug.Log("Count = 0 " + Enemy.count); int temp = (ms.getChoosenMap() == 1) ? 0 : ms.getChoosenMap(); Debug.Log("Temp: " + temp); ms.setChoosenMap(temp); TxtController.getInstance().updateText(); timer = Time.time; isGameFinish = true; //Debug.Log(timer); } if (isGameFinish) { lastTimer = Time.time; blackScreen.GetComponent <Image>().enabled = true; status.SetActive(true); UnityEngine.UI.Text textStatus = status.GetComponent <UnityEngine.UI.Text>(); textStatus.text = Enemy.count <= 0 ? "You Win" : "You Lose"; //Debug.Log("Last Timer : " + lastTimer + "timer : " + timer); //Debug.Log(lastTimer - timer); } if ((lastTimer - timer) >= 3f && isGameFinish == true) { DisplayMap.removeEnemy(DisplayMap.xRand, DisplayMap.yRand); ms.setToPlay(false); SceneManager.LoadScene("MenuScene"); } }
public void WriteTxt() { string path = ""; string db = "Map"; if (MapStatus.getInstance().isAvailable(1) == false) { path = "Assets/Resources/Map1.txt"; db = db + "1.txt"; MapStatus.getInstance().setStatus(1); MapStatus.getInstance().setChoosenMap(2); } else if (MapStatus.getInstance().isAvailable(2) == false) { path = "Assets/Resources/Map2.txt"; db = db + "2.txt"; MapStatus.getInstance().setStatus(2); MapStatus.getInstance().setChoosenMap(3); } else if (MapStatus.getInstance().isAvailable(3) == false) { path = "Assets/Resources/Map3.txt"; db = db + "3.txt"; MapStatus.getInstance().setStatus(3); MapStatus.getInstance().setChoosenMap(4); } else { path = "Assets/Resources/Map1.txt"; db = db + "1.txt"; MapStatus.getInstance().setStatus(1); MapStatus.getInstance().setChoosenMap(2); } TxtController.getInstance().updateText(); StreamWriter writer = new StreamWriter(path, false); for (int i = 0; i < 21; i++) { writer.WriteLine(mapstr[i]); } writer.Close(); //AssetDatabase.ImportAsset(path); //TextAsset asset = Resources.Load<TextAsset>(db); }
// Update is called once per frame void Update() { if (isRotate == true) { checkText(); rotateBoxes(); } if (Input.GetKeyDown(KeyCode.UpArrow) && !isRotate) { // Debug.Log("Key Up " + index); index = plusIndex(index); // Debug.Log("Update : "+ index); changeColor(index, minIndex(index)); } if (Input.GetKeyDown(KeyCode.DownArrow) && !isRotate) { // Debug.Log("Key Up " + index); index = minIndex(index); // Debug.Log("Update : " + index); changeColor(index, plusIndex(index)); } if (Input.GetKeyDown(KeyCode.Return) && !isRotate) { if (index == 9) { // play index = 4; changeColor(index, 9); resetFinish(); isRotate = true; //changeCanvasTo(0); indexing = new Indexing(0, 4); } else if (index == 8) { // design map ms.setIndex(2); SceneManager.LoadScene("LoadingScreen"); } else if (index == 5) { //exit Debug.Log("Exit"); Application.Quit(); } else if (index == 4) { //play game ms.setChoosenMap(1); TxtController.getInstance().updateText(); ms.setIndex(1); SceneManager.LoadScene("LoadingScreen"); } else if (index == 3 || index == 2 || index == 1) { //play game int temp = (index != 2 && index == 3) ? 1 : 3; if (index == 2) { temp = 2; } //Debug.Log(temp); //Debug.Log(ms.getStatus()); //Debug.Log(ms.isAvailable(temp)); if (ms.isAvailable(temp)) { ms.setToPlay(true); ms.setChoosenMap(temp + 1); TxtController.getInstance().updateText(); ms.setIndex(1); SceneManager.LoadScene("LoadingScreen"); } } else if (index == 0) { //back index = 9; changeColor(index, 0); resetFinish(); isRotate = true; //changeCanvasTo(1); indexing = new Indexing(5, 9); } } if (Input.GetKeyDown(KeyCode.RightArrow)) { //Debug.Log("Right"); if (index == 7) { //resol plusResol(); //Debug.Log(idxR); Screen.SetResolution(resol[idxR].width, resol[idxR].height, true); changeText(7, resol[idxR].text); } else if (index == 6) { //quality plusQuality(); QualitySettings.SetQualityLevel(idxQ, true); changeText(6, quality[idxQ]); } } if (Input.GetKeyDown(KeyCode.LeftArrow)) { //Debug.Log("Left"); if (index == 7) { //change resol minResol(); Screen.SetResolution(resol[idxR].width, resol[idxR].height, true); //Debug.Log(idxR); changeText(7, resol[idxR].text); } else if (index == 6) { minQuality(); QualitySettings.SetQualityLevel(idxQ, true); changeText(6, quality[idxQ]); } } }
void Update() { DisplayMap.map.coor[playerRow, playerCol].value = DesignController.FLOOR; playerRow = Mathf.RoundToInt(transform.position.x); playerCol = Mathf.RoundToInt(transform.position.z); //Debug.Log(playerX + "dan y : " + playerY); DisplayMap.map.coor[playerRow, playerCol].value = DesignController.PLAYER; //Debug.Log(DisplayMap.map.coor[2, 9].value); //Map.getSpot(playerY, playerX)= DesignController.PLAYER; UnityEngine.UI.Text change = txt.GetComponent <UnityEngine.UI.Text>(); change.text = "Health : " + health; if (health <= 0) { isDeath = true; } moveY += 2 * Input.GetAxis("Mouse X"); moveX -= 2 * Input.GetAxis("Mouse Y"); transform.eulerAngles = new Vector3(moveX, moveY, 0); if (Input.GetKey(KeyCode.W)) { //animator.SetBool("isWalk", true); if (Input.GetKey(KeyCode.LeftShift)) { transform.Translate(new Vector3(0, 0, Time.deltaTime * 2f)); } transform.Translate(new Vector3(0, 0, Time.deltaTime * 4f)); } if (Input.GetKey(KeyCode.A)) { //animator.SetBool("isWalk", true); if (Input.GetKey(KeyCode.LeftShift)) { transform.Translate(new Vector3(Time.deltaTime * -2f, 0, 0)); } transform.Translate(new Vector3(Time.deltaTime * -4f, 0, 0)); } if (Input.GetKey(KeyCode.S)) { //animator.SetBool("isWalk", true); if (Input.GetKey(KeyCode.LeftShift)) { transform.Translate(new Vector3(0, 0, Time.deltaTime * -2f)); } transform.Translate(new Vector3(0, 0, Time.deltaTime * -4f)); } if (Input.GetKey(KeyCode.D)) { //animator.SetBool("isWalk", true); if (Input.GetKey(KeyCode.LeftShift)) { transform.Translate(new Vector3(Time.deltaTime * 2f, 0, 0)); } transform.Translate(new Vector3(Time.deltaTime * 4f, 0, 0)); } if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.D)) { //animator.SetBool("isWalk", false); } if (Input.GetKey(KeyCode.Space)) { transform.Translate(new Vector3(0, Time.deltaTime * 4f, 0)); } if (Input.GetKey(KeyCode.Escape)) { DisplayMap.removeEnemy(DisplayMap.xRand, DisplayMap.yRand); DisplayMap.removeTreasure(DisplayMap.xTRand, DisplayMap.yTRand); MapStatus.getInstance().setToPlay(false); if (MapStatus.getInstance().getChoosenMap() == 1) { MapStatus.getInstance().setChoosenMap(0); } TxtController.getInstance().updateText(); SceneManager.LoadScene("MenuScene"); } }