public void SetStatusMove(int status) //hàm set Status không trùng với hàm dùng trong BlockManage { if (Status == BlockObjStatus.HasFigure) // khi prj nằm ở vị trí không thể triệu hồi được quân cờ, { status = 3; Status = (BlockObjStatus)((int)Status | status); // khi dùng lệnh Status = (BlockObjStatus)((int)Status ^ status); thì Status=0, làm prj có thể triệu hồi quân cờ được //nhưng prj đó nằm ở vị trí không thể triệu hồi cờ, nên statu=3, đổi phép tính sang | để Status=3, tức là không thể triệu hồi cờ } else { Status = (BlockObjStatus)((int)Status ^ status); } }
//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 } }
// mod end nnvu // add start nnvu set Status as create Block public void SetStatus(int status) { Status = (BlockObjStatus)((int)Status | status); }