-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.java
79 lines (72 loc) · 2.33 KB
/
move.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
/*
1. Constructs words out of tiles
2. Checks if word is valid using Game method
3. If word is valid, ask Game to place the word
4. If word is not valid, either give it back to player or put back on the board
5. If word is valid, return the total score to the player
-----
*/
import java.util.ArrayList;
class move {
public static final int RIGHT = 1;
public static final int DOWN = 2;
static int totalNumberOfMoves;
String word;
int direction;
int startRow;
int startCol;
static boolean isValid;
ArrayList<String> secondaryWords;
/*
Constructs a move object
@param word - the word to be constructed
@param direction - direction
@param startRow - starting row coordinate of the move
@param startCol - starting col coordinate of the move
*/
public move(String word, int direction, int startCol, int startRow) {
// TODO: add invalid argument checks
this.word = word;
this.direction = direction;
this.startCol = startCol;
this.startRow = startRow;
this.isValid = false;
move.totalNumberOfMoves = 0;
}
//variables are not declared private
// public void setSecondaryWords(ArrayList<String> list) {
// if (!list.isEmpty()) {
// this.secondaryWords = list;
// } else {
// System.out.println("Secondary list empty! Nothing to set.");
// }
// }
/*
utility method that converts Strings to char arrays
useful for using characters for validation
@param str input string word
@return Char array of str
*/
public static char[] convertStringToCharsArray(String str) {
char[] charArr = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
charArr[i] = str.charAt(i);
}
return charArr;
}
/*
to check the game state (valid + invalid)
@return # of moves
*/
public static int movesPlayedSoFar() {
return move.totalNumberOfMoves;
}
// @return computes total score of a word
public int computeWordScore(move move) {
return -1;
}
public static void registerCorrectMove(move move) {
if (move.isValid) { totalNumberOfMoves++; }
else { System.out.println("Invalid move, unable to register"); }
}
}