-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResources.java
83 lines (70 loc) · 2.43 KB
/
Resources.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
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
//contains methods for checking and operations on the amount of resources that a player has.
import java.util.Arrays;
public class Resources{
private static int[] resourceList; // static because the player should only have one list of resources
private int fuel;
private int ammo;
private int steel;
private int bauxite;
// Constructors
public Resources()
{
resourceList = new int[]{0,0,0,0};
fuel = ammo = steel = bauxite = 0;
}
public Resources(int f, int a, int s, int b)
{
resourceList = new int[]{f, a, s, b};
fuel = f; ammo = a; steel = s; bauxite = b;
}
public Resources(int[] list)
{
resourceList = list.clone();
fuel = list[0]; ammo = list[1]; steel = list[2]; bauxite = list[3];
}
// Setter / Getter
public void setResourceList(int[] list)
{
resourceList = list.clone();
fuel = list[0]; ammo = list[1]; steel = list[2]; bauxite = list[3];
}
public void printResourceList()
{
for (int i = 0; i < 4; i++){
System.out.print(resourceList[i] + " ");
}
System.out.println();
}
public int[] getResourceList()
{
return resourceList.clone();
}
// Estimates the amount of time needed for all resources to fill to a desired amount (in seconds)
public int predictTime(int[] required)
{
// resourceList has four fields for current resources: oil, ammo, steel, bauxite
// required is for the desired amount of each resource
int[] perSecond = {0,0,0,0};
int biggestTime = 0;
for (int i = 0; i < 4; i++) // Set perSecond to the amount of time in hours needed to accumulate resources
{
// Set perSecond to the difference between required and current
perSecond[i] = required[i] - resourceList[i];
if (perSecond[i] < 0)
{
perSecond[i] = 0;
}
// Multiply difference by 60 to get time in seconds for each resource
perSecond[i] = perSecond[i] * 60;
}
perSecond[3] = perSecond[3] * 3; // Bauxite takes 3 times as long to accumulate
for (int i = 0; i < 4; i++) // Pick resource with longest time
{
if (perSecond[i] > biggestTime)
{
biggestTime = perSecond[i];
}
}
return biggestTime;
}
}