public override void OnOpen(Intent intent) { base.OnOpen(intent); Debugger.Log("MainPanel Open"); string ip = PlayerPrefs.GetString("hostIp"); if (ip != "") { ipInput.value = ip; } FieldRoadStation s1 = new FieldRoadStation() { type = FieldRoadStationType.Rail, point = new ChessPoint(1, 5), }; FieldRoadStation s2 = new FieldRoadStation() { type = FieldRoadStationType.Barrack, point = new ChessPoint(1, 6), }; Debugger.Warn(ChessAgainst.IsBarrack(new ChessPoint(1, 7))); Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(0, 7))); Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(1, 6))); Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(1, 10))); Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(4, 6))); //App.Manager.UI.ReplaceView("UIGamePanel"); //OnSetIp(); }
private void ShowChessMoveTo(ChessPoint point1, ChessPoint point2) { //显示轨迹 FieldRoadStation station = App.Package.ChessGame.GetFieldRoadStationByPoint(point1); UIWChessItem uiItem = station.gameObject.GetComponent <UIWChessItem>(); uiItem.SetArrow(point2); }
public static void LookForRailWayPath(FieldRoadStation roadStationT, List <FieldRoadPath> paths, List <int> usedStations, int currentR, int max) { if (paths.Count < 1) { return; } List <FieldRoadPath> pathsNext = new List <FieldRoadPath>(); FieldRoadPath path; FieldRoadStation roadStationS; for (int i = paths.Count - 1; i >= 0; i--) { path = paths[i]; if (path.pathStations.Count < currentR) { break; } int startId = path.pathStations[path.pathStations.Count - 1]; if (startId == roadStationT.id) { continue; //找到的不找了 } roadStationS = App.Package.ChessGame.GetFieldRoadStationById(startId); for (int j = 0; j < roadStationS.connectedPointIds.Length; j++) { int id = roadStationS.connectedPointIds[j]; FieldRoadStation roadStationC = App.Package.ChessGame.GetFieldRoadStationById(id); if (roadStationC.type == FieldRoadStationType.Rail) { if (path.pathStations.IndexOf(id) == -1) { FieldRoadPath pathNext = new FieldRoadPath(path); pathNext.pathStations.Add(id); pathsNext.Add(pathNext); } } } } paths.AddRange(pathsNext); if (currentR + 1 <= max) { LookForRailWayPath(roadStationT, paths, usedStations, currentR + 1, max); } }
void InitFieldRoadStations() { for (int i = 0; i < App.Package.ChessGame.MapRoadStations.Count; i++) { FieldRoadStation station = App.Package.ChessGame.MapRoadStations[i]; GameObject go; int yo = station.point.y % 6; string child = "Horizontal" + yo + "/ChessEmpty" + station.point.x; if (station.point.y < 6) { go = m_MyselfMapFied.transform.Find(child).gameObject; } else { go = m_EnemyMapFied.transform.Find(child).gameObject; } station.gameObject = go; } }
/// <summary> /// 初始化战场的道路连接数据 /// </summary> public void InitFieldMap() { m_MapRoadStations.Clear(); for (int i = 0; i < 12; i++) { for (int j = 0; j < 5; j++) { FieldRoadStation roadStation = new FieldRoadStation(); roadStation.point = new ChessPoint(j, i); if (ChessAgainst.InRailArea(roadStation.point)) { roadStation.type = FieldRoadStationType.Rail; } else if (ChessAgainst.IsBarrack(roadStation.point)) { roadStation.type = FieldRoadStationType.Barrack; } roadStation.id = m_MapRoadStations.Count; m_MapRoadStations.Add(roadStation); } } List <int> connetedIds = new List <int>(); for (int i = 0; i < m_MapRoadStations.Count; i++) { connetedIds.Clear(); for (int j = 0; j < m_MapRoadStations.Count; j++) { if (i != j) { if (ChessAgainst.IsConnected(m_MapRoadStations[i], m_MapRoadStations[j])) { connetedIds.Add(j); //Debugger.Warn(m_MapRoadStations[i].point.ToString()+" => "+ m_MapRoadStations[j].point.ToString()); } } } m_MapRoadStations[i].connectedPointIds = connetedIds.ToArray(); } }
public static bool IsConnected(FieldRoadStation station1, FieldRoadStation station2) { if (station1.point.x == station2.point.x && (station1.point.x == 1 || station1.point.x == 3)) { if ((station1.point.y == 5 && station2.point.y == 6) || (station1.point.y == 6 && station2.point.y == 5)) { return(false); } } int s1 = Mathf.Abs(station1.point.x - station2.point.x); int s2 = Mathf.Abs(station1.point.y - station2.point.y); if (s1 > 1 || s2 > 1) { return(false); } if (s1 + s2 > 1 && station1.type != FieldRoadStationType.Barrack && station2.type != FieldRoadStationType.Barrack) { return(false); } return(true); }
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); }