// Use this for initialization void Start() { //保持棋子 QiziMap.AddGameObject(x.ToString() + y.ToString(), gameObject); //初始化棋子 ChessManager.GetInstant().InitQizi(current, new PointData(x, y, z), transform); }
//电脑走棋 public void DianNaoZouQi() { ResultData data = ChineseChessHandler.GetInstant().GetZoufa(Fen); log.Log(data.result); log.Log(data.caneat); log.Log(data.moves.Count); if (data.result) { Fen.noteatcount++; MoveData move = data.moves[0]; if (data.caneat) { GameObject obj = QiziMap.GetGameObject(move.end.x.ToString() + move.end.y.ToString()); obj.SetActive(false); QiziMap.RemoveGameObject(move.end.x.ToString() + move.end.y.ToString()); Fen.noteatcount = 0; } MoveQizi(move); Fen.moves.Insert(0, move); Fen[move.end] = Fen[move.start]; Fen[move.start] = Qizi.KONGZI; Fen.current = Fen.current ^ 0x0003; Fen.count++; } }
//场景重置 public void ResetQiPan() { //清除棋子位置管理 QiziMap.RemoveAllGameObject(); //重置棋盘 SceneManager.LoadScene(0); }
//移动棋子 public void MoveQizi(MoveData move) { GameObject game = QiziMap.GetGameObject(move.start.x.ToString() + move.start.y.ToString()); if (game == null) { return; } QiziScript qiziobj = game.GetComponent <QiziScript>(); float he = 0.0f; if (qiziobj.current == Constant.RED) { if (move.end.y < 5) { he = heffset; game.transform.localPosition = new Vector3((move.end.x - 4) * xoffset, yoffset, he + (4 - move.end.y) * zoffset); } else { game.transform.localPosition = new Vector3((move.end.x - 4) * xoffset, yoffset, he + (5 - move.end.y) * zoffset); } } else { if (move.end.y > 4) { he = heffset; game.transform.localPosition = new Vector3((move.end.x - 4) * xoffset, yoffset, -he + (5 - move.end.y) * zoffset); } else { game.transform.localPosition = new Vector3((move.end.x - 4) * xoffset, yoffset, he + (4 - move.end.y) * zoffset); } } QiziMap.ReplaceGameObject(move.start.x.ToString() + move.start.y.ToString(), move.end.x.ToString() + move.end.y.ToString(), game); qiziobj.x = move.end.x; qiziobj.y = move.end.y; qiziobj.z = move.end.z; }
public void CheckAndMove(PointData end) { PointData start = Fen.selected; MoveData move = new MoveData(); move.start = start; move.end = end; if (move.end == PointData.NgData) { //恢复坐标 move.end = start; MoveQizi(move); return; } FenData f = GetFenDataClone(); f.moves.Insert(0, move); ResultData data = ChineseChessHandler.GetInstant().CheckZoufa(f); if (data.result) { Fen.noteatcount++; if (data.caneat) { GameObject obj = QiziMap.GetGameObject(move.end.x.ToString() + move.end.y.ToString()); obj.SetActive(false); QiziMap.RemoveGameObject(move.end.x.ToString() + move.end.y.ToString()); Fen.noteatcount = 0; } MoveQizi(move); Fen.moves.Insert(0, move); Fen[move.end] = Fen[move.start]; Fen[move.start] = Qizi.KONGZI; Fen.current = Fen.current ^ 0x0003; Fen.count++; HidenRoad(); } else { //恢复坐标 move.end = start; MoveQizi(move); } }
public void SetSelected(PointData point) { //恢复坐标 if (point.x != Fen.selected.x || point.y != Fen.selected.y) { MoveQizi(new MoveData(Fen.selected, Fen.selected)); GameObject obj = QiziMap.GetGameObject(point.x.ToString() + point.y.ToString()); Vector3 vector = obj.transform.localPosition; obj.transform.localPosition = new Vector3(vector.x, vector.y + 0.5f, vector.z); Fen.selected = point; } else { GameObject obj = QiziMap.GetGameObject(point.x.ToString() + point.y.ToString()); Vector3 vector = obj.transform.localPosition; if (vector.y == 1.0f) { obj.transform.localPosition = new Vector3(vector.x, vector.y + 0.5f, vector.z); } } }