public void MoveOrTurn(Formation f, Direction dir) { // find formation bool found = false; int fx = -99, fy = -99; for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { if (Tiles[x, y].Formation == f) { fx = x; fy = y; found = true; break; } } if (found) { break; } } if (f.Facing == dir) { Move(f, dir); } else { f.Facing = dir; f.Act(Tiles[fx, fy].Terrain.MovementCost); } }
public void Move(Formation f, Direction dir) { // find formation bool found = false; int fx = -99, fy = -99; for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { if (Tiles[x, y].Formation == f) { fx = x; fy = y; found = true; break; } } if (found) { break; } } if (CoordsInBounds(fx + dir.DeltaX, fy + dir.DeltaY)) { var targetTile = Tiles[fx + dir.DeltaX, fy + dir.DeltaY]; if (targetTile.Formation == null) { // move Tiles[fx, fy].Formation = null; targetTile.Formation = f; if (f == Heroes) { HeroX = fx + dir.DeltaX; HeroY = fy + dir.DeltaY; // pick up items foreach (var item in targetTile.Items.Values) { item.Found(Heroes); } targetTile.Items.Clear(); // update fog of war for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { if (TestLineOfSight(HeroX, HeroY, x, y)) { Tiles[x, y].HasBeenSeen = true; } } } } } else { // fight Fight(Tiles[fx, fy], targetTile); } // spend time f.Act(Tiles[fx + dir.DeltaX, fy + dir.DeltaY].Terrain.MovementCost); } }