-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameData.java
More file actions
123 lines (107 loc) · 4.01 KB
/
GameData.java
File metadata and controls
123 lines (107 loc) · 4.01 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Krishay
// 5/16/22
// GameData.java
// This class contains the game's data, and it allows for other clases to read
// and write information to each other.
public class GameData
{
private boolean hasSpoiler; // Determines if the car has a spoiler
private boolean hasExhaust; // Determines if the car has an exhaust
private boolean hasMirrors; // Determines if the car has mirrors
private boolean hasRoof; // Determines if the car has a roof
private String carColor; // Determines the car color
private int carSpeed; // Determines if the computer cars' speeds
private String[] texts; // A String[] containing the texts to type
private SprintTyperHolder sprintHolder; // An instance of the holder class
// needed for accessing a method
private int amountLines; // The amount of lines from the holder class
public GameData(SprintTyperHolder sprintHolderIn, int amtLinesIn)
{
amountLines = amtLinesIn;
sprintHolder = sprintHolderIn;
hasSpoiler = true;
hasExhaust = true;
hasMirrors = true;
hasRoof = true;
carColor = "Red";
carSpeed = 1;
texts = new String[amountLines];
fillTextsArray();
}
// This method fills the texts array using a for-loop and a random number that
// acts as a random index to be generated.
public void fillTextsArray()
{
int lineNumToRead = 0;
boolean[] selectedQuestions = new boolean[amountLines];
for (int i = 0; i < amountLines; i++)
{
lineNumToRead = (int)(Math.random() * amountLines) + 1;
while (selectedQuestions[lineNumToRead - 1] == true)
lineNumToRead = (int)(Math.random() * amountLines) + 1;
if (selectedQuestions[lineNumToRead - 1] == false)
{
texts[i] = sprintHolder.getTypingText("texts.txt", lineNumToRead, i);
selectedQuestions[lineNumToRead - 1] = true;
}
}
}
// Here, the car drawing class can request to get the info for a car part to
// decide whether it needs to be drawn or not.
public boolean getCarPartInfo(String carPart)
{
if (carPart.equalsIgnoreCase("Spoiler"))
return hasSpoiler;
else if (carPart.equalsIgnoreCase("Exhaust"))
return hasExhaust;
else if (carPart.equalsIgnoreCase("Mirrors"))
return hasMirrors;
else if (carPart.equalsIgnoreCase("Roof"))
return hasRoof;
else
return false;
}
// The JCheckBoxes within the settings panel can use this method to set the
// appropriate variable to the appropriate value. These variables determine
// what is needed to be drawn with a boolean. If it is needed, then the value
// is true, else, it is false.
public void setCarPartInfo(String carPart, boolean val)
{
if (carPart.equalsIgnoreCase("Spoiler"))
hasSpoiler = val;
else if (carPart.equalsIgnoreCase("Exhaust"))
hasExhaust = val;
else if (carPart.equalsIgnoreCase("Mirrors"))
hasMirrors = val;
else if (carPart.equalsIgnoreCase("Roof"))
hasRoof = val;
}
// Gets the color of the car. This is used in the car drawing class.
public String getColor()
{
return carColor;
}
// Sets the color of the car. This is used in the settings panel.
public void setColor(String color)
{
carColor = color;
}
// Gets the car speed for the computer cars. This is used in the game
// panel.
public int getCarSpeed()
{
return carSpeed;
}
// Sets the car speed for the computer cars. This is used in the settings
// panel.
public void setCarSpeed(int speed)
{
carSpeed = speed;
}
// Returns a String from the texts[] array at a given index. This is used
// in the game panel.
public String getTypingTextArray(int index)
{
return texts[index];
}
}