Skip to content

Commit

Permalink
FIX: Allowed aborting when entering a new name.
Browse files Browse the repository at this point in the history
COMMENT: Updated TODO comments.
  • Loading branch information
tsaglam committed Oct 21, 2018
1 parent 9a9726e commit f5ee1d8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/carcassonne/model/ai/AbstractPlayerAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AbstractPlayerAI() {
public abstract CarcassonneMove getBestMove();

public List<CarcassonneMove> getPossibleMoves() {
// TODO (HIGH) implement method getPossibleMoves().
// TODO (MEDIUM) implement method getPossibleMoves().
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carcassonne/model/ai/CarcassonneMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class CarcassonneMove implements Comparable<CarcassonneMove> {
* Basic constructor, creates the move object.
*/
public CarcassonneMove() {
// TODO (HIGH) Implement CarcassonneMove class. Maybe build two subclasses.
// TODO (MEDIUM) Implement CarcassonneMove class. Maybe build two subclasses.
}

@Override
public int compareTo(CarcassonneMove otherMove) {
// TODO (HIGH) Implement compareTo() method.
// TODO (MEDIUM) Implement compareTo() method.
return 0;
}
}
2 changes: 1 addition & 1 deletion src/main/java/carcassonne/model/grid/FieldsPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private GridDirection getFieldOpposite(GridDirection position, GridDirection nei
private List<GridDirection> getFieldPositions(Tile tile, GridDirection startingPoint) {
List<GridDirection> fieldPositions = new LinkedList<>();
for (GridDirection position : GridDirection.values()) { // for every position on tile
if (tile.hasConnection(startingPoint, position)) { // TODO (HIGH) Add exceptions!
if (tile.hasConnection(startingPoint, position)) {
fieldPositions.add(position);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carcassonne/model/terrain/Terrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void rotateRight() {
rotate(GridDirection.indirectNeighbors());
}

private void createMeepleSpots() { // TODO (MEDIUM) Improve code quality.
private void createMeepleSpots() { // TODO (HIGH) Improve code quality.
meepleSpots = new LinkedList<>();
meepleSpots.addAll(Arrays.asList(GridDirection.values()));
for (GridDirection spot : GridDirection.values()) { // for every spot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ public MenuNamesMouseAdapter(int player, JMenuItem item) {
*/
@Override
public void mousePressed(MouseEvent e) {
String newName = GameMessage.getUserInput("Please enter a new name for player " + item.getText() + "!");
GameOptions.getInstance().playerNames[player] = newName;
item.setText(newName);
String name = GameMessage.getUserInput("Please enter a new name for player " + item.getText() + "!");
if (name != null) { // if not canceled.
if (name.isEmpty()) {
GameMessage.showMessage("Invalid name, please try again!");
mousePressed(e); // try again
} else {
GameOptions.getInstance().playerNames[player] = name;
item.setText(name);
}
}
}

}
7 changes: 1 addition & 6 deletions src/main/java/carcassonne/view/secondary/GameMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ private GameMessage() {
* @return the user input string.
*/
public static String getUserInput(String messageText) {
String input = JOptionPane.showInputDialog(null, messageText, TITLE, JOptionPane.QUESTION_MESSAGE);
if (input != null && input.length() > 0) {
return input;
}
showWarning("You need to enter something!");
return getUserInput(messageText);
return JOptionPane.showInputDialog(null, messageText, TITLE, JOptionPane.QUESTION_MESSAGE);
}

/**
Expand Down

0 comments on commit f5ee1d8

Please sign in to comment.