-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBoardPanelHelper.java
138 lines (120 loc) · 5.08 KB
/
BoardPanelHelper.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
/*******************************************************************
* Contains various helper functions that assist Board Panel class.
* Functions are called from Board Panel class.
******************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class BoardPanelHelper {
public BoardPanelHelper(){
//empty default constructor
}
public String[] assignExitOptions(int roomNum){
String[] options = null;
if(roomNum == 1 || roomNum == 4 || roomNum == 7 || roomNum == 8)
options = new String[]{"1"};
else if(roomNum == 2 || roomNum == 3 || roomNum == 9)
options = new String[]{"1","2"};
else if(roomNum == 6)
options = new String[]{"1","2","3"};
else
options = new String[]{"1","2","3","4"};
return options;
}
public ClueGameConstants.DOORS findSpecificDoor(int roomNumber, int doorSelection){
for(ClueGameConstants.DOORS doors : ClueGameConstants.DOORS.values()){
if(doors.getRoomNumber() == roomNumber)
if(doors.getDoorID() == doorSelection)
return doors;
}
return null;
}
public boolean determineIfSelectedDoorIsBlocked(int xSpace, int ySpace, HashMap<Long, Player> playerMap){
for(Map.Entry<Long, Player> player : playerMap.entrySet()) {
Player p = player.getValue();
if(p.getCurrentXLocation() == xSpace && p.getCurrentYLocation() == ySpace)
return true;
}
return false;
}
public ArrayList<Boolean[]> getAttemptedDoorsList(){
ArrayList<Boolean[]> attemptedDoorsListArray = new ArrayList<>();
for(int i = 0; i < 9; i++){
int roomNumber = i + 1;
switch (roomNumber){
case 1: attemptedDoorsListArray.add(new Boolean[]{false}); break;
case 2: attemptedDoorsListArray.add(new Boolean[]{false,false}); break;
case 3: attemptedDoorsListArray.add(new Boolean[]{false,false}); break;
case 4: attemptedDoorsListArray.add(new Boolean[]{false}); break;
case 5: attemptedDoorsListArray.add(new Boolean[]{false,false,false,false,false}); break;
case 6: attemptedDoorsListArray.add(new Boolean[]{false,false, false}); break;
case 7: attemptedDoorsListArray.add(new Boolean[]{false}); break;
case 8: attemptedDoorsListArray.add(new Boolean[]{false}); break;
case 9: attemptedDoorsListArray.add(new Boolean[]{false,false}); break;
default: break;
}
}
return attemptedDoorsListArray;
}
public int determineTrueAmountInDoorArray(Boolean[] doorArray){
int count = 0;
for(boolean bValue : doorArray){
if(bValue) count++;
}
return count;
}
public boolean isRoomAShortCutRoom(int roomNumber){
return roomNumber == 1 || roomNumber == 8 || roomNumber == 4 || roomNumber == 7;
}
public Rectangle getBounds(int x, int y) {
//increase x offset by 30
//increase y offset by 16
return new Rectangle(x + 30,y + 16,20,20);
}
public int getCombinedSuggestionContentNumber(String charName, String weaponName, int roomNumber){
int characterSuggestionValue = getSuggestionNumValue(charName, ClueGameConstants.CHARACTER_NAMES_ARRAY);
int weaponSuggestionValue = getSuggestionNumValue(weaponName, ClueGameConstants.WEAPON_NAMES_ARRAY);
return (characterSuggestionValue * 100) + (weaponSuggestionValue * 10) + roomNumber;
}
private int getSuggestionNumValue(String inputString, String[] arrayToSearch){
int i = 0;
for(String strToFind : arrayToSearch){
if(strToFind.equals(inputString))
return i+1;
i++;
}
return i;
}
public int getDoorId(int row, int col) {
for(ClueGameConstants.DOORS door : ClueGameConstants.DOORS.values()) {
if(door.getRow() == row && door.getCol() == col)
return door.getRoomNumber();
}
return 0;
}
public int getDirection(int row, int col) {
for(ClueGameConstants.DOORS door : ClueGameConstants.DOORS.values()) {
if(door.getRow() == row && door.getCol() == col)
return door.getDirection();
}
return 0;
}
/*
public Player getPlayerFromMap(String characterName, HashMap<Long, Player> map) {
for()
return map.get(player.getPlayerId());
} */
public String getNameFromAccusingString(String inputStr){
int index = inputStr.indexOf("-");
return inputStr.substring(0, index);
}
public String getNameFromSuggestedString(String inputStr){
int colonIndex = inputStr.indexOf(":");
int commaIndex = inputStr.indexOf(",");
return inputStr.substring(colonIndex+2, commaIndex);
}
}