bool IControllerInterface.click(Vector2Int position) { if (currentPickupChess != null && !isVectorEqualToLocation(position, currentPickupChess.location)) { Location moveTo = new Location(position.x, position.y); if (game.canMoveChess(currentPickupChess, moveTo)) { IPointInterface p1 = findFirstPointResponder(points[currentPickupChess.location.x][currentPickupChess.location.y]); IPointInterface p2 = findFirstPointResponder(points[position.x][position.y]); if (p1 != null && p2 != null) { p1.ChessMoveOut(); game.moveChess(currentPickupChess, moveTo); Debug.Log(game.getChess(currentPickupChess.location)); Debug.Log(game.getChess(new Location(moveTo.x, moveTo.y))); p2.ChessMoveIn(game.getChess(new Location(moveTo.x, moveTo.y))); currentPickupChess = null; } } return(true); } else { return(false); } }
// Use this for initialization void Start() { game = new ChineseChessLogic(); for (int i = 0; i < kGenNums.x; i++) { points[i] = new GameObject[kGenNums.y]; for (int j = 0; j < kGenNums.y; j++) { Vector2Int indexVec = new Vector2Int(i, j); points[i][j] = Instantiate(kClickObject); points[i][j].transform.position = new Vector3( kDatumPoint.x + indexVec.x * kStepDistance.x, // 楚河汉界宽度如果与格子不同需单独处理 kDatumPoint.y + indexVec.y * kStepDistance.y + (indexVec.y >= 5 ? kBorderOffset : 0), -1); // 设置IPointInterface信息 IPointInterface p = findFirstPointResponder(points[i][j]); if (p != null) { p.setPointLocation(new Vector2Int(i, j)); p.setChess(game.getChess(new Location(i, j))); p.setCenter(this); } } } }