-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (46 loc) · 1.34 KB
/
Copy pathmain.cpp
File metadata and controls
57 lines (46 loc) · 1.34 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
#include "input_reader.h"
#include "coordinates.h"
#include "grid.h"
#include "robot.h"
#include "commander.h"
using namespace ToyRobot;
int main( int argc, char *argv[] )
{
if( argc > 2 )
{
std::cerr << "ERROR: Unsupported number of arguments." << std::endl;
return 1;
}
int length = 4, width = 4;
Coordinates dimensions( length, width );
std::shared_ptr<Grid> grid = nullptr;
try
{
grid = std::make_shared<Grid>( dimensions );
}
catch( const char* ex )
{
std::cerr << ex << std::endl;
return EXIT_FAILURE;
}
auto robot = std::make_shared<Robot>();
std::unique_ptr<Commander> commander = nullptr;
if( argc < 2 )
{
auto console_reader = std::make_shared<ConsoleReader>();
commander = std::make_unique<Commander>( console_reader, grid );
std::cout << "--- TOY ROBOT program (enter a blank command to exit) ---" << std::endl;
}
else if( argc == 2 )
{
std::string filename( argv[1] );
auto file_reader = std::make_shared<FileReader>();
file_reader->SetFilepath( filename );
if( ! file_reader->ReadAllLines() )
return 1;
commander = std::make_unique<Commander>( file_reader, grid );
}
commander->TrackRobot( robot );
commander->PlayWithRobot();
return 0;
}