// del start nnvu Delete amin //Animator anim; // del end nnvu void Start() { //hand = GameObject.Find("1:1"); //for (int i = 0; i < block.Length; i++) //{ // anim =block[i].GetComponent<Animator>(); // anim.SetInteger("Color", 4); //} if (block != null) { // del start nnvu remove SetInvalid //SetValid(); // del end nnvu remve SetInvalid for (int jj = 0; jj < height; jj++) { if ((jj % 2 == 0) && (jj != 0)) { col += xOffset; } for (int ii = 0; ii < width; ii++) { // mod start nnvu Change Block Status Precreate // if (Invalid[jj, ii] == 0) if (Invalid[jj, ii] != 0) // mod end { GameObject hex_go; // mod start nnvu Change How to create Base //if (jj % 2 == 0) //{ // hex_go = (GameObject)Instantiate( // block, // new Vector2(ii * xOffset - 5.5f + col, jj * yOffset - 7*yOffset / 2f), // Quaternion.identity); //} //else //{ // hex_go = (GameObject)Instantiate( // block, // new Vector2(ii * xOffset + xOffset / 2 - 5.5f + col, jj * yOffset - 7*yOffset / 2f), // Quaternion.identity); //} hex_go = (GameObject)Instantiate( block, new Vector2( ii * xOffset - 5.5f + col + (jj % 2) * xOffset / 2f, jj * yOffset + 3f + 0.6f), Quaternion.identity); // mod end nnvu hex_go.name = "Base_" + ii + "_" + jj; hex_go.transform.SetParent(this.transform); // add start nnvu set Status as create Block BlockOj hexScript = (BlockOj)hex_go.GetComponent(typeof(BlockOj)); hexScript.SetStatus(Invalid[jj, ii]); // add end nnvu } } } } }
// Use this for initialization void Start() { #region Block if (block != null) { for (int jj = 0; jj < height; jj++) { if ((jj % 2 == 0) && (jj != 0)) { col += xOffset; } for (int ii = 0; ii < width; ii++) { if (Invalid[jj, ii] != 0) { GameObject hex_go; hex_go = (GameObject)Instantiate( block, new Vector2( ii * xOffset - 5.5f + col + (jj % 2) * xOffset / 2f, jj * yOffset + 3f + 0.6f), Quaternion.identity); hex_go.name = "Base_" + ii + "_" + jj; hex_go.transform.SetParent(this.transform); // add start nnvu set Status as create Block BlockOj hexScript = (BlockOj)hex_go.GetComponent(typeof(BlockOj)); hexScript.SetStatus(Invalid[jj, ii]); } } } } #endregion #region Draw _drawer = Instantiate(Drawer); _drawer.transform.SetParent(this.transform); _drawer.name = "Drawer"; #endregion #region Card _sCard = Card; wid = Card.GetComponent <SpriteRenderer>().bounds.size.x + 0.05f; _sWid = wid; for (int i = 0; i < 5; i++) { _card = Instantiate(Card, new Vector2(-8f + (wid * i), -4f), Quaternion.identity); _card.name = "card_" + i.ToString(); _card.transform.SetParent(this.transform.Find("Drawer")); } CardNumber = 5; #endregion }
//void OnMouseDown() //{ // if ((BlockObjStatus.HasFigure & Status) == 0) // { // Instantiate( // Figure, // GetPosition(), // Quaternion.identity); // Status = Status | BlockObjStatus.HasFigure; // } //} /* Should use OnMouseDown (above) instead? - PrInc3 */ //Mouse Stay in the block private void OnMouseOver() { //Receive left-click if (Input.GetMouseButtonUp(0)) { //Find this block's Invalid value from GameManage // del start nnvu Delete get block Valid from game manager //byte Invalid = Manager.getBlockValid(This_x,This_y); //Debug.Log ("Invalid VALUE = " + Invalid); // del end nnvu //Perform action according to Invalid value // del start nnvu remove Switch case // switch (status){ ////Summon Figure when value is 2 //case : // Instantiate (Figure, // GetPosition (), // Quaternion.identity); // status = 1; //1: Has Figure // break; // //Otherwise // default: //Do something // break; //} // del end nnvu // add start nnvu Add figure Create if ((BlockObjStatus.HasFigure & Status) == 0 && BlockManage.isClick == 0) { fig = (GameObject)Instantiate( Figure, GetPosition(), Quaternion.identity); Status = Status | BlockObjStatus.HasFigure; fig.name = "figure"; fig.transform.SetParent(this.transform); Debug.Log(Status); } else if (Status.ToString() != "3" && BlockManage.isClick == 0) { BlockManage.isClick = 1; anim.SetInteger("Status", 2); //Tìm tọa độ các ô cần thay màu string[] Name = obj.name.Split('_'); SetAffectedBlocks(int.Parse(Name[1]), int.Parse(Name[2]), 3); //Giá trị truyền vào sau là bán kính Debug.Log("So O: " + countAffectedBlocks); //Đổi màu các ô đã chọn ChangeColor(AffectedBlocks, 2); Debug.Log("chon " + obj.name); priBlock = obj; priFigure = fig; } else if ((Status.ToString() == "11" || Status.ToString() == "7" || Status == BlockObjStatus.HasFigure) && BlockManage.isClick == 1) { BlockManage.isClick = 0; returnColor(); anim.SetInteger("Status", 1); //Chỉnh lại màu cho các ô màu đỏ trước đó BlockOj tmpBlkObj = priBlock.GetComponent <BlockOj> (); tmpBlkObj.ChangeColor(tmpBlkObj.AffectedBlocks, 0); Debug.Log("khong the di chuyen " + obj.name); } else if ((Status.ToString() != "11" && Status.ToString() != "7" && Status.ToString() != "1") && BlockManage.isClick == 1) { //Kiểm tra xem có thể di chuyển Figure ơơơđến ô đã chơọn khơông BlockOj tmpBlkObj = priBlock.GetComponent <BlockOj> (); bool CanMove = false; string[] Name = obj.name.Split('_'); for (int i = 0; i < tmpBlkObj.countAffectedBlocks; i++) { if (tmpBlkObj.AffectedBlocks[i] == (int.Parse(Name[1]) * 100 + int.Parse(Name[2]))) { CanMove = true; } } if (!(CanMove)) { Debug.Log("Qua gioi han di chuyen"); return; } returnColor(); priFigure.transform.position = GetPosition(); fig = priFigure; priFigure = null; BlockOj hexScript = (BlockOj)priBlock.GetComponent(typeof(BlockOj)); //set lại status cho prj chọn trước đó, hexScript.SetStatusMove(1); if (Status.ToString() == "3") // trường hợp những ô không nằm trong vùng triệu hồi quân, //có giá trị là 3, thì khi dùng lệnh Status = Status | BlockObjStatus.HasFigure sẽ vẫn có giá trị là 3 //nên ta đổi sang phép tính khác để trả về 1 giá trị khác là 1 { Status = Status & BlockObjStatus.HasFigure; } else { Status = Status | BlockObjStatus.HasFigure; } //Chỉnh lại màu cho các ô màu đỏ trước đó tmpBlkObj.ChangeColor(tmpBlkObj.AffectedBlocks, 0); Debug.Log("di chuyen " + obj.name); BlockManage.isClick = 0; } // add end nnvu } }