- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameHelper.java
More file actions
Latest commit
75 lines (68 loc) · 1.75 KB
/
Copy pathGameHelper.java
File metadata and controls
75 lines (68 loc) · 1.75 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
importjava.io.*;
importjava.util.*;
publicclassGameHelper {
privatestaticfinalStringalphabet = "abcdefg";
privateintgridLength = 7;
privateintgridSize = 49;
privateint[] grid = newint[gridSize];
privateintcomCount = 0;
publicStringgetUserInput(Stringprompt) {
StringinputLine = null;
System.out.println(prompt + " ");
try {
BufferedReaderis = newBufferedReader(newInputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length() == 0) returnnull;
}
catch (IOExceptione) {
System.out.println("IOException: " + e);
}
returninputLine;
}
publicArrayList<String> placeDotCom(intcomSize) {
ArrayList<String> alphaCells = newArrayList<String>();
String[] alphacoords = newString[comSize];
Stringtemp = null;
int[] coords = newint[comSize];
intattempts = 0 ;
booleansuccess = false;
intlocation = 0;
comCount++;
intincr = 1;
if((comCount %2) == 1){
incr = gridLength;
}
while (!success & attempts++ < 200) {
location = (int) (Math.random()*gridSize);
//System.out.println(location)
intx = 0;
success = true;
while (success && x < comSize) {
if (grid[location] == 0) {
coords[x++] = location;
location += incr;
if(location >= gridSize) {
success = false;
}
if (x>0 && (location % gridLength == 0)) {
success = false;
}
}else {
success = false;
}
}
}
intx = 0 ;
introw = 0 ;
intcolumn = 0;
while (x < comSize) {
grid[coords[x]] = 1;
row = (int) (coords[x] / gridLength);
column = coords[x] % gridLength;
temp = String.valueOf(alphabet.charAt(column));
alphaCells.add(temp.concat(Integer.toString(row)));
x++;
}
returnalphaCells;
}
}