This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
73 lines (60 loc) · 2.43 KB
/
Program.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using MarsApp.InputValidation;
using MarsApp.Mars;
using MarsApp.Utils;
namespace MarsApp
{
class Program
{
static void Main(string[] args)
{
var upperRight = Console.ReadLine();
IInputValidation inputValidation = new CoordinateInputValidation(upperRight);
if (!inputValidation.IsValid())
{
throw new Exception("Invalid upper-right coordinate!");
}
var upperRightValues = upperRight.Split(" ");
var plateau = new Plateau
{
Width = int.Parse(upperRightValues[0]),
Height = int.Parse(upperRightValues[1]),
Rovers = new List<Rover>()
};
var selection = "Y";
while (selection == "Y")
{
var position = Console.ReadLine();
inputValidation = new PositionInputValidation(position);
if (inputValidation.IsValid() == false)
{
throw new Exception("Invalid position!");
}
var positionValues = position.Split(" ");
var pointX = int.Parse(positionValues[0]);
var pointY = int.Parse(positionValues[1]);
var direction = Util.DetectDirectionInput(positionValues[2]);
if (Util.CheckStartingPosition(plateau, pointX, pointY) == false)
{
throw new Exception("Rover's starting position must be inside the plateau!");
}
var rover = new Rover(pointX, pointY, direction);
var command = Console.ReadLine();
inputValidation = new CommandInputValidation(command);
if (!inputValidation.IsValid())
{
throw new Exception("Invalid command!");
}
rover.ExecuteCommand(command, plateau);
plateau.Rovers.Add(rover);
Console.WriteLine("Do you want to continue adding the rover? 'Y' or 'N'");
selection = Console.ReadLine();
}
foreach (var rover in plateau.Rovers)
{
Console.WriteLine(rover.PointX + " " + rover.PointY + " " + Util.DetectDirectionOutput(rover.Direction));
}
}
}
}