-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngine.java
178 lines (155 loc) · 6.13 KB
/
Engine.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;
import java.io.IOException;
public class Engine {
public static String language;
public static String languageAbbreviation;
public static final String systemText_loc = "_system_text.txt";
public static final String descriptions_loc = "_descriptions.txt";
public static final long baseSpeed = 2000L;
public static final long[] speedSettings = {baseSpeed, baseSpeed/2, baseSpeed/4, baseSpeed/8, baseSpeed/16}; // Time in between ticks
public static int speedSetting = 0;
public static long tickSpeed = speedSettings[speedSetting];
static Scanner stdin = new Scanner(System.in);
public static MapManager mapManager = new MapManager();
// public static CharacterManager characterManager = new CharacterManager();
// public static DemographicsManager demograpicsManager = new DemographicsManager();
// public static EventManager eventManager = new EventManager();
// public static DateManager dateManager = new DateManager();
public static void init(){
MapManager.init();
// CharacterManager.init();
// DemographicsManager.init();
// EventManager.init();
// DateManager.init();
}
public static boolean tick(){
boolean active = true;
//System.out.println(DateManager.currentGameDate);
//active = active && DateManager.incrementQuarterHour();
return active;
}
public static int getInput(String[] responses){
/* getInput
* takes responses, a list of acceptable strings
* only returns when an acceptable input is given
* returns an integer corresponding to the index of the accepted string in the responses list
*/
String input = "";
while(true){
System.out.print("> ");
input = stdin.nextLine().toUpperCase();
for(int i = 0; i < responses.length; i++){
if(responses[i].equals(input)){
return i;
}
}
}
}
public static int getInput(){
/* getInput
* asks for an input until one is given
* returns when input is recieved
*/
String input = "";
while(true){
System.out.print("> ");
input = stdin.nextLine().toUpperCase();
if(input != null) return 1;
}
}
public static void log(String logline){
try {
File logFile = new File("log.txt");
logFile.createNewFile(); // does nothing if already exists
PrintWriter logWriter = new PrintWriter(new FileWriter(logFile, true));
logWriter.printf("%s : %s%n", getDate(), logline);
logWriter.close();
return;
}
catch(IOException e){
System.out.println(e);
System.exit(-1);
}
}
public static void log(String context, String logline){
try {
File logFile = new File("log.txt");
logFile.createNewFile(); // does nothing if already exists
PrintWriter logWriter = new PrintWriter(new FileWriter(logFile, true));
logWriter.printf("%s : %s: %s%n", getDate(), context.toUpperCase(), logline);
logWriter.close();
return;
}
catch(IOException e){
System.out.println(e);
System.exit(-1);
}
}
public static void log(String context, String logline, String trace){
try {
File logFile = new File("log.txt");
logFile.createNewFile(); // does nothing if already exists
PrintWriter logWriter = new PrintWriter(new FileWriter(logFile, true));
logWriter.printf("%s : %s: %s @ %s%n", getDate(), context.toUpperCase(), logline, trace);
logWriter.close();
return;
}
catch(IOException e){
System.out.println(e);
System.exit(-1);
}
}
public static void log(Exception logE){
try {
File logFile = new File("log.txt");
logFile.createNewFile(); // does nothing if already exists
PrintWriter logWriter = new PrintWriter(new FileWriter(logFile, true));
logWriter.printf("%s : %s @ %s%n", getDate(), logE.toString(), logE.getStackTrace()[0].toString());
logWriter.close();
return;
}
catch(IOException e){
System.out.println(e);
System.exit(-1);
}
}
public static String getDate(){
return new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSS").format(new java.util.Date());
}
public static void reset() throws IOException {
File logFile = new File("log.txt");
logFile.createNewFile(); // does nothing if already exists
FileOutputStream logStream = new FileOutputStream(logFile, false);
logStream.close();
log("Reset Engine");
return;
}
public static float randPercent(){
return randPercent(0.0f, 1.0f);
}
public static float randPercent(float min, float max){
// will perform the same if min and max are flipped
Random rand = new Random();
return (min - max) * rand.nextFloat() + min; // return a float between min and max (exclusive), equally distributed
}
public static double randDouble(double min, double max){
// will perform the same if min and max are flipped
Random rand = new Random();
return (min - max) * rand.nextDouble() + min; // return a double between min and max (exclusive), equally distributed
}
public static int randInt(int max){
return randInt(0, max);
}
public static int randInt(int min, int max){
if(max > min) throw new IllegalArgumentException(String.format("The minimum is less than the maximum: %d < %d.%n", max, min));
Random rand = new Random();
return rand.nextInt(max - min + 1) + min; // return an integer between min and max (inclusive), equally distributed
}
}