-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyView.h
64 lines (56 loc) · 1.38 KB
/
MyView.h
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
59
60
61
#pragma once
#include "View.h"
#include "CLI.h"
#include "Solution.h"
#include <algorithm>
class MyView : public View
{
public:
MyView (CLI& cli): cli(cli){};
virtual void start(std::shared_ptr<Controller> c)
{
this->cli.start(c);
}
virtual void display(Maze2d &maze)
{
cli.getout()<<maze<<std::endl;
}
virtual void showMsg(std::string s) // cout msg to the screen
{
cli.getout()<<s<<std::endl;
}
virtual void displaySolution(Maze2d& maze, Solution<Position>& solution)
{
auto _maze = maze.getMaze();
auto start = maze.getStartPosition();
auto &out = cli.getout();
auto sol = solution.getPath();
for (int i = 0; i < _maze.size(); i++)
{
for (int j = 0; j < _maze.size(); j++)
{
State<Position> p = {{j,i}, 0};
if (_maze[i][j] == 1)
out << "\u2593";
else if (i == start.getYPosition() && j == start.getXPosition())
{
out << "$";
}
else
{
bool inSol = false;
for (auto p : sol)
if (p->data == Position{ j, i })
{
inSol = true;
break;
}
out << (inSol ? "*" : " ");
}
}
out << "\n";
}
}
private:
CLI cli;
};