-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.cs
More file actions
70 lines (62 loc) · 1.67 KB
/
Copy pathCar.cs
File metadata and controls
70 lines (62 loc) · 1.67 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Adapter
{
class Car
{
public int Speed { get; set; }
public float WheelRotation { get; set; }
public bool IsStarted { get; set; }
const int AccelerationSpeed = 8;
const int MaxSpeed = 100;
const float RotationSpeed = 11.5f;
const float MaxWheelAxis = 40;
public Car()
{
IsStarted = false;
Speed = 0;
WheelRotation = 0;
}
public void Start()
{
IsStarted = true;
Console.WriteLine("Car started");
}
public bool ShutDown()
{
if (Math.Abs(Speed) > 10)
return false;
IsStarted = false;
Speed = 0;
Console.WriteLine("Car shut downed");
return true;
}
public void SpeedUp()
{
if(IsStarted)
{
Speed = Math.Min(Speed + AccelerationSpeed, MaxSpeed);
Console.WriteLine("Car gain speed: " + Speed);
}
}
public void SpeedDown()
{
if(IsStarted)
{
Speed = Math.Max(Speed - AccelerationSpeed, -MaxSpeed);
Console.WriteLine("Car sped down: " + Speed);
}
}
public void TurnRight()
{
WheelRotation = Math.Min(WheelRotation + RotationSpeed, MaxWheelAxis);
}
public void TurnLeft()
{
WheelRotation = Math.Max(WheelRotation - RotationSpeed, -MaxWheelAxis);
}
}
}