-
Notifications
You must be signed in to change notification settings - Fork 0
/
Planet.cs
52 lines (44 loc) · 927 Bytes
/
Planet.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
using System;
using System.Collections.Generic;
using System.Text;
namespace MarsRovers
{
/* Planet
*
* Holds list of Rovers and a default Terrain
*/
public partial class Planet
{
List<Rover> myRovers;
public Plateau DefaultTerrain {get;set;}
public List<Rover> Rovers {
get {
if(myRovers == null)
myRovers = new List<Rover>();
return myRovers;
}
set {
myRovers = value;
}
}
public Planet() {}
// Add a rover
public void Add(Rover rover) {
Rovers.Add(rover);
}
// Move each rover in turn
public void MoveRovers() {
foreach(Rover r in Rovers) {
r.Go(DefaultTerrain);
}
}
// Output current positions of all the rovers as text
public string RoverPositions() {
StringBuilder output = new StringBuilder();
foreach(Rover r in Rovers) {
output.Append(r.ToString() + System.Environment.NewLine);
}
return output.ToString();
}
}
}