/
GameTiles.java
148 lines (131 loc) · 3.52 KB
/
GameTiles.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
import java.util.*;
import java.io.*;
public class GameTiles{
private LinkedList<Location> tiles;
GameTiles(){
tiles = new LinkedList<Location>();
initializeTiles();//generate the locations and extra actors
}
public void resetBoard(){
for(int i = 0; i < tiles.size(); i++){
Location curr = tiles.get(i);
curr.getSet().setScene(new Scene());
}
}
public Location get(int ID){//get the location at certain ID
int curr = 0;
while(curr != tiles.size() && tiles.get(curr).getID() != ID){
curr++;
}
return tiles.get(curr);
}
public int size(){ return tiles.size(); }
public boolean isBoardWrapped(){ //check if all locations have no shot counters
int curr = 0;
while(curr != tiles.size() && tiles.get(curr).getSet().getShotCounter() != 0){
curr++;
}
if(curr == tiles.size()){
return true;
}else{
return false;
}
}
public void drawScenes(SceneDeck deck){ //set scene to a location
for(int i = 0; i < tiles.size(); i++){
int ID = tiles.get(i).getID();
if(ID != 4 && ID != 8){
tiles.get(i).getSet().setScene(deck.drawCard());
}
}
}
public boolean checkFinishRound(){ //check if round has finished
boolean finishRound = true;
for(int i = 0; i < tiles.size(); i++){
Location currTile = tiles.get(i);
Set film = currTile.getSet();
if(film.getShotCounter() != 0){
finishRound = false;
}
}
return finishRound;
}
private int grabID(int ID, int boundary){ //initializeNeighbors helper
if(ID == boundary){
if(boundary == 8){
ID = 1;
}else{
ID = 9;
}
}else{
ID = ID + 1;
}
return ID;
}
private void initializeNeighbors(){ //creates the neighbor relation
int neighborLeft = 2;
int neighborRight = 8;
int neighborDown = 9;
int neighborUp = 0;
for(int ID = 1; ID <= 12; ID++){
LinkedList<Location> neighbors = new LinkedList<Location>();
Location spot = get(ID);
neighbors.add(get(neighborLeft));
neighbors.add(get(neighborRight));
neighbors.add(get(neighborDown));
if(neighborUp != 0){
neighbors.add(get(neighborUp));
}
spot.setNeighbors(neighbors);
if(ID < 8){
neighborLeft = grabID(neighborLeft, 8);
neighborRight = grabID(neighborRight, 8);
if(ID % 2 == 0){
neighborDown = neighborDown + 1;
}
}else if (ID == 8){
neighborLeft = 1;
neighborRight = 2;
neighborDown = 12;
neighborUp = 10;
}else{
neighborLeft = neighborLeft + 2;
neighborRight = neighborRight + 2;
neighborDown = grabID(neighborDown, 12);
neighborUp = grabID(neighborUp, 12);
}
}
}
private void initializeTiles(){//parse through locations
File tileFile = new File("DeadwoodTiles.txt");
try{
Scanner scn = new Scanner(tileFile);
while(scn.hasNextLine()){
Location loc = new Location();
String curr = scn.nextLine();
String[] spliced = curr.split("\\|");
loc.setID(Integer.parseInt(spliced[0]));
loc.setName(spliced[1]);
loc.getSet().setShotCounter(Integer.parseInt(spliced[2]));
if(Integer.parseInt(spliced[2]) != 0){
ExtraRole extra = new ExtraRole();
LinkedList<ExtraRole> listExtras = new LinkedList<ExtraRole>();
for(int i = 3; i < spliced.length; i++){
if(i % 2 != 0){
extra.setJobTitle(spliced[i]);
}else{
extra.setWorkLevel(Integer.parseInt(spliced[i]));
listExtras.add(extra);
extra = new ExtraRole();
}
}
loc.getSet().createExtras(listExtras);
}
tiles.add(loc);
}
initializeNeighbors();
}catch(Exception e){
e.printStackTrace();
}
}
}