private void PrivateClear(bool tookTurn) { this.TookTurn = tookTurn; TimeToGetWord = -1; TileList.Clear(); CardUsed = 0; }
public void FindNearestTarget() { List <GameObject> targets = GameObject.Find("GameMaster").GetComponent <MapData>().getPlayers(); GameObject nearest = null; float nearestDistance = Mathf.Infinity; foreach (GameObject obj in targets) { //computeAdjacencyList(); foreach (GameObject resetTile in tiles) { resetTile.GetComponent <Tile>().distance = -1; resetTile.GetComponent <Tile>().visited = false; } obj.GetComponent <PlayerMove>().currentTile = getTargetTile(obj); Tile t = obj.GetComponent <PlayerMove>().currentTile; TileList process = new TileList(); t.distance = 0; process.Add(t); t.visited = true; while (process.Count > 0) { bool finishLoop = false; process.Sort(process.getComparator()); Tile currentTile = process[0]; process.RemoveAt(0); this.getTargetTile(gameObject); if (currentTile.Equals(this.currentTile)) { finishLoop = true; process.Clear(); if (currentTile.distance - currentTile.getMoveCost() + 1 < nearestDistance) { nearest = obj; nearestDistance = currentTile.distance - currentTile.getMoveCost() + 1; distanceToTarget = nearestDistance; } } foreach (Tile tile in currentTile.adjacencyList) { if (!tile.visited && tile.isWalkable && finishLoop == false) { tile.parent = currentTile; tile.visited = true; tile.distance = currentTile.distance + tile.getMoveCost(); process.Add(tile); } } } } target = nearest; }
public static void LoadMap() { TileList.Clear(); //ObjectList.Clear(); string FullFile = File.ReadAllText(@"C:\Users\Alex\Documents\TestMap.fmf"); string[] TileData = FullFile.Substring(FullFile.IndexOf("<tile>"), FullFile.IndexOf("</tile>")).Replace("<tile>", "").Replace("</tile>", "").Split(';'); foreach (string s in TileData) { if (s != "") { string[] TileSplit = s.Split(':'); int X = Int32.Parse(TileSplit[0]); int Y = Int32.Parse(TileSplit[1]); Texture2D tx = TextureList[TileSplit[2].Replace("_", "")]; TileList.Add(new Tile(X, Y, tx)); } } int FFA = FullFile.IndexOf("<obj>"); int FFB = FullFile.IndexOf("</obj>"); string[] ObjData = FullFile.Split(new string[] { "<obj>" }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("</obj>", "").Split(';'); foreach (string s in ObjData) { if (s != "") { string[] TileSplit = s.Split(':'); int X = Int32.Parse(TileSplit[0]); int Y = Int32.Parse(TileSplit[1]); Texture2D tx = ObjTextureList[TileSplit[2].Replace("_", "").Split('\\')[1]]; ObjectList.Add(new WorldObject(X, Y, tx)); } } try { string[] BndData = FullFile.Split(new string[] { "<bound>" }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("</bound>", "").Split(';'); foreach (string s in BndData) { if (s != "") { string[] TileSplit = s.Split(':'); int X = Int32.Parse(TileSplit[0]); int Y = Int32.Parse(TileSplit[1]); Texture2D tx = TextureList["bound"]; BoundList.Add(new Tile(X, Y, tx)); } } } catch (Exception ex) { Debug.WriteLine(ex); } }
public void FindActionToTake() { Tile tileToMoveTo = null; float nearestDistance = Mathf.Infinity; if (!attackableTiles.Contains(target.GetComponent <PlayerMove>().getTargetTile(target))) { foreach (Tile t in edgeTiles) { foreach (GameObject resetTile in tiles) { resetTile.GetComponent <Tile>().distance = -1; resetTile.GetComponent <Tile>().visited = false; } TileList process = new TileList(); t.distance = 0; process.Add(t); t.visited = true; while (process.Count > 0) { bool finishLoop = false; process.Sort(process.getComparator()); Tile currentTile = process[0]; process.RemoveAt(0); //Debug.Log(currentTile.transform.position); //if (currentTile.transform.position == new Vector3(1.5f, 7.5f, 0)){ // Debug.DrawLine(currentTile.transform.position, currentTile.transform.position + Vector3.up, Color.white, 10f); // foreach (Tile temp in currentTile.adjacencyList){ // } //} if (currentTile.Equals(target.GetComponent <PlayerMove>().currentTile)) { finishLoop = true; process.Clear(); if (currentTile.distance - currentTile.getMoveCost() + 1 < nearestDistance) { tileToMoveTo = t; nearestDistance = currentTile.distance - currentTile.getMoveCost() + 1; } } foreach (Tile tile in currentTile.adjacencyList) { if (!tile.visited && tile.isWalkable && finishLoop == false) { tile.parent = currentTile; tile.visited = true; tile.distance = currentTile.distance + tile.getMoveCost(); process.Add(tile); } } } } this.tileToMoveTo = tileToMoveTo; } else { this.tileToMoveTo = null; canAttack = true; } }