-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWheel.cs
80 lines (70 loc) · 1.67 KB
/
Wheel.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
using System;
using System.Collections.Generic;
namespace Wheels
{
/// <summary>
/// A Wheel.
/// </summary>
public class Wheel
{
/// <summary>
/// List of wheels driven by this wheel instance.
/// </summary>
private List<Wheel> _drivenWheels = new List<Wheel>();
/// <summary>
/// List of wheels coupled in this wheel instance.
/// </summary>
private List<Wheel> _coupledWheels = new List<Wheel>();
/// <summary>
/// Gets the number of cogs on the wheel.
/// </summary>
/// <value>Number of cogs on the wheel.</value>
public int Cogs { get; }
/// <summary>
/// Gets or sets (protected) the RPM of the wheel.
/// RPM - Rotations Per Minute
/// </summary>
/// <value>Rpm.</value>
public double Rpm { get; protected set; }
/// <summary>
/// Initializes a new instance of the <see cref="Wheels.Wheel"/> class.
/// </summary>
/// <param name="cogs">Number of cogs.</param>
public Wheel (int cogs)
{
Cogs = cogs;
}
/// <summary>
/// Drives another wheel.
/// </summary>
/// <param name="w">Another wheel.</param>
public void Drives(Wheel w)
{
_drivenWheels.Add (w);
}
/// <summary>
/// Couples a wheel.
/// </summary>
/// <param name="w">Another wheel.</param>
public void Couples(Wheel w)
{
_coupledWheels.Add (w);
}
/// <summary>
/// Spins the wheel.
/// </summary>
/// <param name="rpm">Rpm.</param>
public void Spin(double rpm)
{
Rpm = rpm;
// Spin all the driven wheels.
foreach (Wheel dw in _drivenWheels) {
dw.Spin (Rpm / (dw.Cogs / Convert.ToDouble(Cogs)));
}
// Spin all the coupled wheels.
foreach (Wheel cw in _coupledWheels) {
cw.Spin (Rpm);
}
}
}
}