-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgi_main.cpp
More file actions
58 lines (57 loc) · 1.72 KB
/
cgi_main.cpp
File metadata and controls
58 lines (57 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <fstream>
#include "UI.hpp"
#include "Pathfinder.hpp"
int main()
{
// create a web page
UI ui("Pathfinder");
std::string inv = ui.param("Inventory");
std::string map = ui.param("Map");
// create Pathfinder object
Pathfinder p;
// read map and inventory
p.readMap(map);
p.readInventory(inv);
// add items to cart
for(size_t i = 0; i < ui.queries().size(); i++)
{
////~ std::cerr << "here" << std::endl;
if(ui.queries().at(i) == "item")
{
p.add_to_cart(ui.params().at(i));
}
////~ std::cout << ui.queries().at(i) << " --> " << ui.params().at(i) << "<br>" <<std::endl;
}
////~ p.map().printMapHTML();
////~ p.inventory().to_stringHTML();
////~ p.cart().to_stringHTML();
// generate shortest route
p.generate();
// set map scale to 100 pixels
p.map().scale(100);
// javascript
std::cout << "<script>" << std::endl
<< "window.onload = draw;" << std::endl
<< "function draw(){" << std::endl
<< "var canvas = document.getElementById(\"canvas1\");" << std::endl
<< "console.log(canvas.width); console.log(canvas.height);" << std::endl
<< "var ctx = canvas.getContext(\"2d\");" << std::endl;
// draw map
p.map().draw_map();
//mark items
p.mark_items();
// draw path
p.width(p.map().scale()/10);
// set path width
p.draw_path();
std::cout << "}" << std::endl
<< "</script>" << std::endl;
// html
std::cout << "<body>" << std::endl;
ui.color_body();
////~ std::cout << "<p>Scale: " << p.map().scale() << " Path: " << path_to_string(p.path()) << "</p><br><br>" << std::endl;
std::cout << "<canvas id=\"canvas1\" width=\"" << p.map().width() * p.map().scale()
<< "\" height=\"" << p.map().height() * p.map().scale() <<"\"></canvas>" << std::endl;
std::cout << "</body>" << std::endl;
}