-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBridgeGame.java
More file actions
44 lines (35 loc) · 1.02 KB
/
BridgeGame.java
File metadata and controls
44 lines (35 loc) · 1.02 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
package bridge;
import java.util.*;
public class BridgeGame {
private final List<String> bridge;
private BridgeBoard bridgeBoard = new BridgeBoard();
public BridgeGame(List<String> bridge) {
this.bridge = bridge;
}
public boolean move(String moving) {
int currentLocation = bridgeBoard.getSize();
boolean isPossible = isPossibleMove(moving, currentLocation);
if (moving.equals("U")) {
bridgeBoard.drawUpMovement(isPossible);
}
if (moving.equals("D")) {
bridgeBoard.drawDownMovement(isPossible);
}
return isPossible;
}
private boolean isPossibleMove(String moving, int currentLocation) {
if (moving.equals(bridge.get(currentLocation))) {
return true;
}
return false;
}
public void retry() {
bridgeBoard = new BridgeBoard();
}
public BridgeBoard getBridgeBoard() {
return bridgeBoard;
}
public int getSize() {
return bridge.size();
}
}