public string ShortPath(string from, string to) { List <City> citys = LoadCities(); var sp = new ShortPath(); string path = sp.GetShortestPath(citys.ToList <ICity>(), from, to); List <Vertex> vertexs = TempData.Peek("vertex") as List <Vertex>; string jsonResult = string.Format("{{\"city\":{0},\"connections\":{1}}}", (new City()).LoadMap(vertexs), (new Connections()).LoadConnections(vertexs, path)); return(jsonResult); }
// private TankSpineAttach _spineAttach; public UnitDriver(GameObject owner, GameObject body, float speed) { _unit = owner.GetComponent <Unit> (); _game = BattleGame.instance; _shortPath = new ShortPath(_unit, _game.mapGrid); this._owner = owner; this._body = body; _engine = new TankEngine(_unit); _turningControl = new AimmingControl(body, ROTATION_SPEED); this._speed = speed; // _spineAttach = owner.GetComponent<TankSpineAttach> (); }
public static Texture2D LoadImg(string path, bool isShortPath = false) { if (isShortPath) { path = ShortPath.Get(path); } path = path.Replace('/', '\\'); if (xnbFiles.Contains(path)) { return(LoadImgFromContent(path)); } else if (resFiles.Contains(path)) { return(LoadImgFromRes(path)); } else { throw new Exception("Can't find image in Content or Resources " + path); } }
/** * This method gets the HttpRequestBase object for start location from database * then performs the Short Path algorithm to return the path to nearest emergency exitis as a View to the user * @return matrix */ public ActionResult SearchEmergencyView() { int i = 0; string CurrentselectedValue = Request["CurrentLocation"]; // Get table values for start location string sql = "Select [Row] AS RowValue, [Col] AS ColumnValue, Nearest_EmergencyStairX, Nearest_EmergencyStairY, Floor from Mapped_Floor " + " Where Room Like '" + CurrentselectedValue + "'"; DataTable dt = new DataTable(); using (SqlConnection cn = new SqlConnection(connectionstr)) { cn.Open(); SqlCommand cmd = new SqlCommand(sql, cn); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); cn.Close(); } int StartRoomRow = 0; int StartRoomColumn = 0; int NearestExitRow = 0; int NearestExitColumn = 0; String StartFloor = String.Empty; if (dt.Rows.Count > 0) { StartRoomRow = int.Parse(dt.Rows[0]["RowValue"].ToString()); StartRoomColumn = int.Parse(dt.Rows[0]["ColumnValue"].ToString()); NearestExitRow = int.Parse(dt.Rows[0]["Nearest_EmergencyStairX"].ToString()); NearestExitColumn = int.Parse(dt.Rows[0]["Nearest_EmergencyStairY"].ToString()); StartFloor = dt.Rows[0]["Floor"].ToString(); } // To get the values from DB ViewBag.FirstDisplay = false; ViewBag.SecondDisplay = false; ViewBag.ThirdDisplay = false; ViewBag.FirstDisplayTitle = ""; ViewBag.SecondDisplayTitle = ""; ViewBag.ThirdDisplayTitle = ""; ViewModels.Matrix matrix = new ViewModels.Matrix(); ViewModels.Matrix matrix1 = new ViewModels.Matrix(); ViewModels.Matrix matrix2 = new ViewModels.Matrix(); int r = 0; int c = 0; if (StartFloor.Equals("S")) { // The first display data - Second Floor foreach (var item in db.Second_Floor.OrderBy(o => new { o.Row, o.Col }).ToList()) { r = (int)item.Row; c = (int)item.Col; matrix.grid[r, c] = (int)item.Value; matrix.label[r, c] = item.Name; matrix.path[r, c] = (int)item.PathOrNot; } ViewBag.FirstDisplayTitle = "Second Floor"; // The second display data - First Floor foreach (var item in db.First_Floor.OrderBy(o => new { o.Row, o.Col }).ToList()) { r = (int)item.Row; c = (int)item.Col; matrix1.grid[r, c] = (int)item.Value; matrix1.label[r, c] = item.Name; matrix1.path[r, c] = (int)item.PathOrNot; } ViewBag.SecondDisplayTitle = "First Floor"; // The third display data - Ground Floor foreach (var item in db.Ground_Floor.OrderBy(o => new { o.Row, o.Col }).ToList()) { r = (int)item.Row; c = (int)item.Col; matrix2.grid[r, c] = (int)item.Value; matrix2.label[r, c] = item.Name; matrix2.path[r, c] = (int)item.PathOrNot; } ViewBag.ThirdDisplayTitle = "Ground Floor"; ViewBag.FirstDisplay = true; ViewBag.SecondDisplay = true; ViewBag.ThirdDisplay = true; } else if (StartFloor.Equals("F")) { // The first display data - First Floor foreach (var item in db.First_Floor.OrderBy(o => new { o.Row, o.Col }).ToList()) { r = (int)item.Row; c = (int)item.Col; matrix.grid[r, c] = (int)item.Value; matrix.label[r, c] = item.Name; matrix.path[r, c] = (int)item.PathOrNot; } ViewBag.FirstDisplayTitle = "First Floor"; // The second display data - Ground Floor foreach (var item in db.Ground_Floor.OrderBy(o => new { o.Row, o.Col }).ToList()) { r = (int)item.Row; c = (int)item.Col; matrix1.grid[r, c] = (int)item.Value; matrix1.label[r, c] = item.Name; matrix1.path[r, c] = (int)item.PathOrNot; } ViewBag.SecondDisplayTitle = "Ground Floor"; ViewBag.FirstDisplay = true; ViewBag.SecondDisplay = true; } else if (StartFloor.Equals("G")) { // The first display data - Ground Floor foreach (var item in db.Ground_Floor.OrderBy(o => new { o.Row, o.Col }).ToList()) { r = (int)item.Row; c = (int)item.Col; matrix.grid[r, c] = (int)item.Value; matrix.label[r, c] = item.Name; matrix.path[r, c] = (int)item.PathOrNot; } ViewBag.FirstDisplayTitle = "Ground Floor"; ViewBag.FirstDisplay = true; } var m = new ShortPath(matrix.path); var n = new ShortPath(matrix1.path); var p = new ShortPath(matrix2.path); if (StartFloor.Equals("S")) { var x = m.FindPath(StartRoomRow, StartRoomColumn, NearestExitRow, NearestExitColumn); var y = n.FindPath(NearestExitRow, NearestExitColumn, NearestExitRow, NearestExitColumn); var z = p.FindPath(NearestExitRow, NearestExitColumn, NearestExitRow, NearestExitColumn); int Row = matrix.grid.GetLength(0); int Col = matrix.grid.GetLength(1); for (int row = 0; row < Row; row++) { for (int col = 0; col < Col; col++) { if (x[row, col] == 7) { matrix.grid[row, col] = 7; } } } int Row1 = matrix1.grid.GetLength(0); int Col1 = matrix1.grid.GetLength(1); for (int row = 0; row < Row1; row++) { for (int col = 0; col < Col1; col++) { if (y[row, col] == 7) { matrix1.grid[row, col] = 7; } } } int Row2 = matrix2.grid.GetLength(0); int Col2 = matrix2.grid.GetLength(1); for (int row = 0; row < Row2; row++) { for (int col = 0; col < Col2; col++) { if (z[row, col] == 7) { matrix2.grid[row, col] = 7; } } } } else if (StartFloor.Equals("F")) { var x = m.FindPath(StartRoomRow, StartRoomColumn, NearestExitRow, NearestExitColumn); var y = n.FindPath(NearestExitRow, NearestExitColumn, NearestExitRow, NearestExitColumn); int Row = matrix.grid.GetLength(0); int Col = matrix.grid.GetLength(1); for (int row = 0; row < Row; row++) { for (int col = 0; col < Col; col++) { if (x[row, col] == 7) { matrix.grid[row, col] = 7; } } } int Row1 = matrix1.grid.GetLength(0); int Col1 = matrix1.grid.GetLength(1); for (int row = 0; row < Row1; row++) { for (int col = 0; col < Col1; col++) { if (y[row, col] == 7) { matrix1.grid[row, col] = 7; } } } } else if (StartFloor.Equals("G")) { var x = m.FindPath(StartRoomRow, StartRoomColumn, NearestExitRow, NearestExitColumn); int Row = matrix.grid.GetLength(0); int Col = matrix.grid.GetLength(1); for (int row = 0; row < Row; row++) { for (int col = 0; col < Col; col++) { if (x[row, col] == 7) { matrix.grid[row, col] = 7; } } } } ViewData["first"] = matrix; ViewData["second"] = matrix1; ViewData["third"] = matrix2; return(View(matrix)); }