-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crosswalk.cs
53 lines (48 loc) · 1.55 KB
/
Crosswalk.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
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Crossroad
{
public class Crosswalk
{
public Crosswalk(RoadParts road)
{
RoadPart = road;
LocAxis = (int)road % 2 == 0 ? Axes.Horizontal : Axes.Vertical;
CrosswalkFild = new()
{
Width = RoadSizes.ROAD_WIDTH,
Height = RoadSizes.CROSSWALK_ZEBRA_WIDTH,
};
}
public Canvas CrosswalkFild { set; get; } = new();
public Axes LocAxis { set; get; } = Axes.Vertical;
public RoadParts RoadPart { set; get; } = 0;
public ObservableCollection<Pedestrian> Pedestrians { set; get; } = new();
public void AddPedestrian(object sender, RoutedEventArgs e)
{
var dir = Canvas.GetRight((sender as Button)) == 0 ?
PedestrianDirections.Forward
: PedestrianDirections.Backward;
var pedastrian = new Pedestrian(RoadPart, dir);
Pedestrians.Add(pedastrian);
}
public void AddPedestrian(PedestrianDirections dir)
{
var pedastrian = new Pedestrian(RoadPart, dir);
Pedestrians.Add(pedastrian);
}
public void Go()
{
Pedestrians
.ToList()
.ForEach(p =>
{
p.Move();
Pedestrians.Remove(p);
});
}
public bool IsFree { set; get; } = true;
}
}