Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ncdc.bow;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.commons.io.FileUtils;
- import org.newdawn.slick.util.pathfinding.AStarPathFinder;
- import org.newdawn.slick.util.pathfinding.Path;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.web.client.RestTemplate;
- @SpringBootApplication
- public class BowApplication {
- public static void main(String[] args) {
- SpringApplication.run(BowApplication.class, args);
- RestTemplate restTemplate = new RestTemplate();
- Integer[][] rawMap = restTemplate.getForObject("http://bow.westeurope.cloudapp.azure.com:8080/getMap", Integer[][].class);
- Map map = new Map(rawMap);
- map.printMap();
- AStarPathFinder asPathFinder = new AStarPathFinder(map, 1000, false);
- Path path = asPathFinder.findPath(null, 0, 0, 7, 3);
- for (int i = 0; i < path.getLength(); i++) {
- System.out.println(path.getStep(i).getX() + ", " + path.getStep(i).getY());
- }
- // map.printMapWithPath(path);
- map.printMapWithPathByWiktus(path);
- System.out.println(getMovesListFromPath(path));
- createHTMLFile(map);
- }
- public static List<String> getMovesListFromPath(Path path) {
- ArrayList<String> movesList = new ArrayList<String>();
- int lastX = path.getX(0),
- lastY = path.getY(0),
- currentX = path.getX(0),
- currentY = path.getY(0);
- for(int i = 0; i < path.getLength(); i++) {
- currentX = path.getX(i);
- currentY = path.getY(i);
- if(currentX - lastX == 1) {
- movesList.add("R");
- } else if(currentX - lastX == -1) {
- movesList.add("L");
- } else if(currentY - lastY == 1) {
- movesList.add("U");
- } else if(currentY - lastY == -1) {
- movesList.add("D");
- }
- lastX = currentX;
- lastY = currentY;
- }
- return movesList;
- }
- public static void createHTMLFile(Map map) {
- map.printMap();
- Integer[][] htmlMap = map.map;
- htmlMap = map.getRotatedMap(htmlMap);
- for(int y = 0; y < htmlMap.length; y++ ) {
- for(int x = 0; x < htmlMap[y].length; x++) {
- System.out.print(htmlMap[y][x] + " ");
- }
- System.out.println();
- }
- File htmlTemplateFile = new File("html/template.html");
- File newHtmlFile = new File("html/new.html");
- String htmlString = "";
- try {
- htmlString = FileUtils.readFileToString(htmlTemplateFile);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- StringBuilder strBuilder = new StringBuilder("");
- for(int y = 0; y < htmlMap.length; y++ ) {
- strBuilder.append("\n\t\t<tr>");
- for(int x = 0; x < htmlMap[y].length; x++) {
- strBuilder.append("\n\t\t\t<td><img src=\"");
- switch(htmlMap[y][x]) {
- case 0: strBuilder.append("0"); break;
- case 1: strBuilder.append("1"); break;
- case 2: strBuilder.append("2"); break;
- case 3: strBuilder.append("3"); break;
- case 4: strBuilder.append("4"); break;
- case 5: strBuilder.append("5"); break;
- }
- strBuilder.append(".png\"></td>");
- }
- strBuilder.append("\n\t\t</tr>\n\t");
- }
- htmlString = htmlString.replace("$table", strBuilder.toString());
- try {
- FileUtils.writeStringToFile(newHtmlFile, htmlString);
- } catch(IOException ex) {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement