-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActorViewer.cs
86 lines (67 loc) · 1.92 KB
/
ActorViewer.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
79
80
81
82
83
84
85
86
using System.Linq;
using System.Windows.Forms;
namespace LangontsAntSimulator
{
public partial class ActorViewer : UserControl
{
#region Private Member Declarations
private IActor _actor;
private ISimulation _simulation;
#endregion Private Member Declarations
#region Public Constructors
public ActorViewer()
{
InitializeComponent();
}
#endregion Public Constructors
#region Public Methods
public void UpdateUi()
{
string location;
string facing;
string nextMove;
location = string.Empty;
facing = string.Empty;
nextMove = string.Empty;
if (this.Simulation != null && this.Actor != null)
{
LangtonsAntSimulation simulation;
IBlock currentBlock;
Direction nextFacing;
location = string.Format("X:{0}, Y:{1}", this.Actor.Location.X, this.Actor.Location.Y);
currentBlock = this.Simulation.Blocks.FirstOrDefault(b => b.Location == this.Actor.Location);
if (currentBlock != null)
{
facing = string.Format("{0} ({1})", this.Actor.Facing.ToString(), currentBlock.IsTagged ? "Black" : "White");
simulation = (LangtonsAntSimulation)this.Simulation;
nextFacing = simulation.GetNextFacing(currentBlock, this.Actor.Facing);
nextMove = nextFacing.ToString();
}
}
locationTextBox.Text = location;
facingTextBox.Text = facing;
nextMoveTextBox.Text = nextMove;
}
#endregion Public Methods
#region Public Properties
public IActor Actor
{
get { return _actor; }
set
{
_actor = value;
this.UpdateUi();
}
}
public ISimulation Simulation
{
get { return _simulation; }
set
{
_simulation = value;
this.UpdateUi();
}
}
#endregion Public Properties
}
}