forked from foxguardsolutions/CodeCamp-MarsRover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
78 lines (58 loc) · 2.01 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
74
75
76
77
78
using System;
namespace MarsRover
{
public static class Program
{
public static void Main(string[] args)
{
int xLoc = AskForXLocation();
int yLoc = AskForYLocation();
char direction = AskForDirection();
string movements = AskForMovements();
Rover rover = new Rover(xLoc, yLoc, direction);
rover.World = CreateWorld();
foreach (char movement in movements)
{
if (!rover.Move(movement))
{
break;
}
}
Console.WriteLine("Final Location: " + rover.CurrentLocation.X + " " + rover.CurrentLocation.Y);
}
private static int AskForXLocation()
{
Console.WriteLine("Enter your starting X Location:");
int xLoc = int.Parse(Console.ReadLine());
return xLoc;
}
private static int AskForYLocation()
{
Console.WriteLine("Enter your starting Y Location:");
int yLoc = int.Parse(Console.ReadLine());
return yLoc;
}
private static char AskForDirection()
{
Console.WriteLine("Enter your starting direction (N, E, S, W):");
char direction = Convert.ToChar(Console.ReadLine());
return direction;
}
private static string AskForMovements()
{
Console.WriteLine("Enter your movements (L, R, F, B):");
string movements = Console.ReadLine();
return movements;
}
private static Grid CreateWorld()
{
Grid world = new Grid(10, 10);
world.GridCellAt(3, 5).ContainsObstacle = true;
world.GridCellAt(3, 6).ContainsObstacle = true;
world.GridCellAt(1, 8).ContainsObstacle = true;
world.GridCellAt(7, 4).ContainsObstacle = true;
world.GridCellAt(6, 2).ContainsObstacle = true;
return world;
}
}
}