public static ChessHeroData HasChessHeroOnPath(FieldRoadPath path) { return(HasChessHeroOnPathPoints(path.ToChessPoints())); }
public static ChessMoveData ChessHeroCanMoveTo(ChessHeroData heroData, ChessPoint point) { ChessMoveData moveData = new ChessMoveData(); FieldRoadStation roadStationS = App.Package.ChessGame.GetFieldRoadStationByPoint(heroData.point); FieldRoadStation roadStationT = App.Package.ChessGame.GetFieldRoadStationByPoint(point); if (ChessHeroCanMove(heroData))//检测棋子本身,地雷、军旗不能走 { //检测目的地是否禁止 /*for(int i = 0; i < roadStationT.forbidChessHeros.Length; i++) * { * if(heroData.heroTypeId == roadStationT.forbidChessHeros[i]) * { * moveData.crashType = 2; * moveData.crashHero = heroData; * return moveData; * } * }*/ /// for (int i = 0; i < roadStationS.connectedPointIds.Length; i++) { FieldRoadStation roadStation = App.Package.ChessGame.GetFieldRoadStationById(roadStationS.connectedPointIds[i]); if (roadStation == roadStationT) { moveData.crashType = 0; moveData.points = new ChessPoint[] { roadStationS.point, roadStationT.point }; return(moveData); } } if (roadStationS.type == FieldRoadStationType.Rail && roadStationT.type == FieldRoadStationType.Rail) { if (heroData.heroTypeId == 2)//工兵行走 { List <FieldRoadPath> paths = new List <FieldRoadPath>(); List <int> usedStations = new List <int>(); usedStations.Add(roadStationS.id); FieldRoadPath pathStart = new FieldRoadPath(); pathStart.pathStations.Add(roadStationS.id); paths.Add(pathStart); LookForRailWayPath(roadStationT, paths, usedStations, 1, 32); for (int i = 0; i < paths.Count; i++) { FieldRoadPath path = paths[i]; if (path.pathStations[path.pathStations.Count - 1] != roadStationT.id) { continue; } ChessPoint[] points = path.ToChessPoints(); ChessHeroData crashHero = HasChessHeroOnPathPoints(points); if (crashHero == null) { moveData.crashType = 0; moveData.crashHero = null; moveData.points = points; return(moveData); } else { moveData.crashHero = heroData; } } moveData.crashType = 3; moveData.crashHero = heroData; return(moveData); } else if (roadStationS.point.x == roadStationT.point.x)//这里要特别注意 { ChessPoint[] points = new ChessPoint[Mathf.Abs(roadStationS.point.y - roadStationT.point.y) + 1]; int d = (roadStationS.point.y < roadStationT.point.y) ? 1 : -1; points[0] = roadStationS.point; for (int i = 1; i < points.Length; i++) { points[i] = new ChessPoint(roadStationS.point.x, roadStationS.point.y + d * i); if (!IsConnected(points[i - 1], points[i]) || !IsRailWay(points[i - 1], points[i]))//要判断是否相连啊,且都是铁路 { moveData.crashType = 2; return(moveData); } } ChessHeroData crashHero = HasChessHeroOnPathPoints(points); if (crashHero == null) { moveData.crashType = 0; moveData.points = points; } else { moveData.crashType = 3; moveData.crashHero = crashHero; } return(moveData); } else if (roadStationS.point.y == roadStationT.point.y) { ChessPoint[] points = new ChessPoint[Mathf.Abs(roadStationS.point.x - roadStationT.point.x) + 1]; int d = (roadStationS.point.x < roadStationT.point.x) ? 1 : -1; points[0] = roadStationS.point; for (int i = 1; i < points.Length; i++) { points[i] = new ChessPoint(roadStationS.point.x + d * i, roadStationS.point.y); if (!IsConnected(points[i - 1], points[i]) || !IsRailWay(points[i - 1], points[i]))//要判断是否相连啊,且都是铁路 { moveData.crashType = 2; return(moveData); } } ChessHeroData crashHero = HasChessHeroOnPathPoints(points); if (crashHero == null) { moveData.crashType = 0; moveData.points = points; } else { moveData.crashType = 3; moveData.crashHero = crashHero; } return(moveData); } else { //不能走直角 } } } moveData.crashType = 1; moveData.crashHero = heroData; return(moveData); }