-
Notifications
You must be signed in to change notification settings - Fork 0
/
GearBox.java
56 lines (48 loc) · 1.1 KB
/
GearBox.java
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
public class GearBox {
//private int gears;
//private int offset;
private int currentGear;
private int maxGear=6;
private int[] offsets = {0,3,10,20,30,40,50};
private int[] steps = {0,20,60,80,100,120,120};
private void changeGear(int gear) {
this.currentGear = gear;
}
// checkGear Marche avec if et case
public void checkGear(int currentSpeed) {
if (currentSpeed == 0 && currentGear == 0) {
changeGear(1);
}else if (currentSpeed < steps[1]){
changeGear(1);
}else if (currentSpeed < steps[2]){
changeGear(2);
}else if (currentSpeed < steps[3]){
changeGear(3);
}else if (currentSpeed < steps[4]){
changeGear(4);
}else if (currentSpeed < steps[5]){
changeGear(5);
}else{
changeGear(6);
}
}
// idee:
// private void checkGear(int currentSpeed) {
// for (int i=0; i < steps.length; i++) {
//
// }
// }
public int getAccel(int currentSpeed) {
int accel = 0;
for (int i = 0; i<offsets.length;i++) {
if (this.currentGear == i) {
accel = offsets[i];
break;
}
}
return accel;
}
public int getCurrentGear() {
return currentGear;
}
}