private void btnFindRoute_Click(object sender, EventArgs e) { RouteFinder routeFinder = new RouteFinder(0, 0, width - 1, height - 1, chbCanMoveDiagonally.Checked); int countInitialLocations = 0; int countGoalLocations = 0; for (int i = 0; i < pnlMAP.Controls.Count; i++) { int x = i % width; int y = i / width; Location loc = new Location(x, y); switch ((string)pnlMAP.Controls[i].Tag) { case initialTag: countInitialLocations++; if (countInitialLocations > 1) { MessageBox.Show("There cannot be more than one initial location.", this.Text); return; } routeFinder.InitialLocation = loc; break; case obstacleTag: routeFinder.AddObstacle(loc); break; case goalTag: countGoalLocations++; routeFinder.AddGoal(loc); break; case routeTag: MakeEmpty(pnlMAP.Controls[i] as Button); break; } } if (countGoalLocations == 0) { MessageBox.Show("There must be atleast one goal location.", this.Text); } DisplayRoute(routeFinder.CalculateRoute()); }