-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fleetsize check and exceptions to fleet validation - closes #18 -
closes #19
- Loading branch information
Philip Jensen
committed
Sep 22, 2015
1 parent
a887a71
commit 912b93b
Showing
13 changed files
with
218 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/edu/dirtybit/battlechat/exceptions/InvalidFleetsizeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package edu.dirtybit.battlechat.exceptions; | ||
|
||
import edu.dirtybit.battlechat.BattleShipConfiguration; | ||
import edu.dirtybit.battlechat.GameConfiguration; | ||
import edu.dirtybit.battlechat.model.Fleet; | ||
import edu.dirtybit.battlechat.model.Ship; | ||
|
||
public class InvalidFleetsizeException extends Exception { | ||
|
||
public InvalidFleetsizeException(String message) { | ||
super(message); | ||
} | ||
|
||
public static String MakeMessage(GameConfiguration config, int canoes, int cruisers, int submarines, int destroyers, int battleships, int carriers) | ||
{ | ||
String message = "Incorrect fleet size: "; | ||
message += "canoes = " + canoes + "(" + Integer.parseInt(config.getProperty(BattleShipConfiguration.ConfigKeys.CANOE_COUNT.toString())) + "), "; | ||
message += "cruisers = " + cruisers + "(" + Integer.parseInt(config.getProperty(BattleShipConfiguration.ConfigKeys.CRUISER_COUNT.toString())) + "), "; | ||
message += "submarines = " + submarines + "(" + Integer.parseInt(config.getProperty(BattleShipConfiguration.ConfigKeys.CANOE_COUNT.toString())) + "), "; | ||
message += "destroyers = " + canoes + "(" + Integer.parseInt(config.getProperty(BattleShipConfiguration.ConfigKeys.CANOE_COUNT.toString())) + "), "; | ||
message += "battleships = " + canoes + "(" + Integer.parseInt(config.getProperty(BattleShipConfiguration.ConfigKeys.CANOE_COUNT.toString())) + "), "; | ||
message += "carriers = " + canoes + "(" + Integer.parseInt(config.getProperty(BattleShipConfiguration.ConfigKeys.CANOE_COUNT.toString())) + ")"; | ||
return message; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/edu/dirtybit/battlechat/exceptions/ShipOutOfBoundsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.dirtybit.battlechat.exceptions; | ||
|
||
import edu.dirtybit.battlechat.model.Ship; | ||
|
||
public class ShipOutOfBoundsException extends Exception { | ||
|
||
private Ship ship; | ||
|
||
public ShipOutOfBoundsException(Ship ship, int endx, int endy) { | ||
super("Ship of type \"" + ship.getShiptype().toString() + "\" was placed outside the board, or extends out of the board at: (\"" + ship.getX() + "\",\"" + ship.getY() + "\" - \"" + endx + "\",\"" + endy + "\")"); | ||
this.ship = ship; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/edu/dirtybit/battlechat/exceptions/ShipsOverlapException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package edu.dirtybit.battlechat.exceptions; | ||
|
||
import edu.dirtybit.battlechat.model.Ship; | ||
|
||
public class ShipsOverlapException extends Exception { | ||
|
||
public ShipsOverlapException(int x, int y) { | ||
super("Two ships overlapped at: (\"" + x + "\",\"" + y + "\")"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.