corrected 'Editorstate' and 'GameServerLogic' and edited 'SeaSynchronizer' and added assets
This commit is contained in:
@@ -7,9 +7,13 @@
|
||||
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.light.AmbientLight;
|
||||
import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.light.Light;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
@@ -26,6 +30,7 @@
|
||||
import static pp.util.FloatMath.HALF_PI;
|
||||
import static pp.util.FloatMath.PI;
|
||||
|
||||
//TODO models
|
||||
/**
|
||||
* The {@code SeaSynchronizer} class is responsible for synchronizing the graphical
|
||||
* representation of the ships and shots on the sea map with the underlying data model.
|
||||
@@ -35,6 +40,9 @@
|
||||
class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
||||
private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o"; //NON-NLS
|
||||
private static final String SUBMARINE ="Models/Submarine/submarine.obj";
|
||||
private static final String DESTROYER ="Models/Destroyer/10619_Battleship.obj";
|
||||
private static final String SMALL_SHIP ="Models/SmallShip/10634_SpeedBoat_v01_LOD3.obj";
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
private static final String SHOT = "shot"; //NON-NLS
|
||||
@@ -141,7 +149,14 @@ public Spatial visit(Battleship ship) {
|
||||
* @return the spatial representing the battleship
|
||||
*/
|
||||
private Spatial createShip(Battleship ship) {
|
||||
return ship.getLength() == 4 ? createBattleship(ship) : createBox(ship);
|
||||
//return ship.getLength() == 4 ? createBattleship(ship) : createBox(ship);
|
||||
return switch(ship.getLength()){
|
||||
case(1)-> createSmallShip(ship);
|
||||
case(2)-> createSubmarine(ship);
|
||||
case(3)-> createDestroyer(ship);
|
||||
case(4)-> createBattleship(ship);
|
||||
default -> createBox(ship);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,6 +176,36 @@ private Spatial createBox(Battleship ship) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
private Spatial createDestroyer(Battleship ship){
|
||||
final Spatial model=app.getAssetManager().loadModel(DESTROYER);
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot())-HALF_PI, 0f);
|
||||
model.scale(0.0001f);
|
||||
model.move(0,0.3f ,0);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
return model;
|
||||
}
|
||||
|
||||
private Spatial createSubmarine(Battleship ship){
|
||||
final Spatial model=app.getAssetManager().loadModel(SUBMARINE);
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.25f);
|
||||
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private Spatial createSmallShip(Battleship ship){
|
||||
final Spatial model = app.getAssetManager().loadModel(SMALL_SHIP);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
|
||||
model.scale(0.001f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Material} with the specified color.
|
||||
* If the color includes transparency (i.e., alpha value less than 1),
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
newmtl Battleship
|
||||
illum 4
|
||||
Kd 0.00 0.00 0.00
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
map_Kd BattleshipC.jpg
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn1SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn2SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.00 0.00 0.00
|
||||
Ns 256.00
|
||||
newmtl blinn3SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn4SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn5SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn6SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn7SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
newmtl blinn8SG
|
||||
illum 4
|
||||
Kd 0.50 0.50 0.50
|
||||
Ka 0.00 0.00 0.00
|
||||
Tf 1.00 1.00 1.00
|
||||
Ni 1.00
|
||||
Ks 0.50 0.50 0.50
|
||||
Ns 256.00
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 360 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 717 KiB |
@@ -0,0 +1,28 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 08.06.2011 15:26:00
|
||||
|
||||
newmtl _10634_SpeedBoat_v01_LOD310634_SpeedBoat_v01
|
||||
Ns 53.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.5882 0.5882 0.5882
|
||||
Kd 0.5882 0.5882 0.5882
|
||||
Ks 0.2000 0.2000 0.2000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 10634_SpeedBoat_v01.jpg
|
||||
map_Kd 10634_SpeedBoat_v01.jpg
|
||||
|
||||
newmtl glass
|
||||
Ns 80.0000
|
||||
Ni 1.5000
|
||||
d 0.2000
|
||||
Tr 0.8000
|
||||
Tf 0.2000 0.2000 0.2000
|
||||
illum 2
|
||||
Ka 0.5882 0.5882 0.5882
|
||||
Kd 0.5882 0.5882 0.5882
|
||||
Ks 0.5000 0.5000 0.5000
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 168 KiB |
@@ -0,0 +1,16 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 29.03.2012 14:25:39
|
||||
|
||||
newmtl default
|
||||
Ns 35.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.5400 0.5400 0.5400
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 14084_WWII_ship_German_Type_II_U-boat_diff.jpg
|
||||
map_Kd 14084_WWII_ship_German_Type_II_U-boat_diff.jpg
|
||||
203099
Projekte/battleship/client/src/main/resources/Models/Submarine/submarine.obj
Normal file
203099
Projekte/battleship/client/src/main/resources/Models/Submarine/submarine.obj
Normal file
File diff suppressed because it is too large
Load Diff
@@ -241,8 +241,8 @@ public void loadMap(File file) throws IOException {
|
||||
final ShipMapDTO dto = ShipMapDTO.loadFrom(file);
|
||||
if (!dto.fits(logic.getDetails()))
|
||||
throw new IOException(lookup("map.doesnt.fit"));
|
||||
if(!verifyMap(dto)){
|
||||
throw new IOException("Map is not valid");
|
||||
if (!verifyMap(dto)) {
|
||||
throw new IOException(lookup("map is not valid"));
|
||||
}
|
||||
ownMap().clear();
|
||||
dto.getShips().forEach(ownMap()::add);
|
||||
@@ -257,20 +257,22 @@ public void loadMap(File file) throws IOException {
|
||||
* @param dto the map
|
||||
* @return true, if the map is valid
|
||||
*/
|
||||
private boolean verifyMap(ShipMapDTO dto){ //MapMessage msg, int playerID
|
||||
private boolean verifyMap(ShipMapDTO dto) { //MapMessage msg, int playerID
|
||||
return verifyBounds(dto) && verifyOverlap(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks, whether a ship is out of the grid
|
||||
*
|
||||
* @param dto is the Map, where the ships are in
|
||||
* @return true, if all ships are in bound
|
||||
*/
|
||||
private boolean verifyBounds(ShipMapDTO dto){
|
||||
for(Battleship ship: dto.getShips()){
|
||||
int mapWidth = dto.getWidth();
|
||||
int mapHeight = dto.getHeight();
|
||||
if(ship.getMaxX()>mapWidth || ship.getMinX()<0 || ship.getMaxY()> mapHeight || ship.getMinY() < 0) return false;
|
||||
private boolean verifyBounds(ShipMapDTO dto) {
|
||||
int mapWidth = dto.getWidth();
|
||||
int mapHeight = dto.getHeight();
|
||||
for (Battleship ship : dto.getShips()) {
|
||||
if (ship.getMaxX() > mapWidth || ship.getMinX() < 0 || ship.getMaxY() > mapHeight || ship.getMinY() < 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -281,32 +283,30 @@ private boolean verifyBounds(ShipMapDTO dto){
|
||||
* @param dto ist the map, where the ships are in
|
||||
* @return true, if no ships overlap
|
||||
*/
|
||||
private boolean verifyOverlap(ShipMapDTO dto){
|
||||
List<Battleship> ships = dto.getShips();
|
||||
for(Battleship ship : ships){
|
||||
for(Battleship compareShip : ships){
|
||||
if(!(ships==compareShip)){
|
||||
if(ship.collidesWith(compareShip)){
|
||||
return false;
|
||||
}
|
||||
private boolean verifyOverlap(ShipMapDTO dto) {
|
||||
List<Battleship> battleshipList = dto.getShips();
|
||||
for (int i = 0; i < battleshipList.size(); i++) {
|
||||
Battleship ship1 = battleshipList.get(i);
|
||||
for (int j = i + 1; j < battleshipList.size(); j++) {
|
||||
Battleship ship2 = battleshipList.get(j);
|
||||
if (ship1.collidesWith(ship2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
/*
|
||||
List<Battleship> ships = dto.getShips();
|
||||
List<Battleship> shipsReduceList = new ArrayList<>(ships);
|
||||
for(Battleship ship: ships){ //iterate through the list of all ships on the grid
|
||||
shipsReduceList.remove(ship); // delete the current ship from the second list, so it will not test, if it collides with itself
|
||||
for(Battleship battleship:shipsReduceList){ //iterates through the other ships
|
||||
if(ship.collidesWith(battleship)){// tests, for all other remaining ships, if they collide with the current one
|
||||
return false; // return false, if there is a collision
|
||||
for (Battleship ship : ships) {
|
||||
for (Battleship compareShip : ships) {
|
||||
if (ships != compareShip) {
|
||||
if (ship.collidesWith(compareShip)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -143,8 +143,8 @@ public Player addPlayer(int id) {
|
||||
public void received(MapMessage msg, int from) {
|
||||
if (state != ServerState.SET_UP)
|
||||
LOGGER.log(Level.ERROR, "playerReady not allowed in {0}", state); //NON-NLS
|
||||
else if(!verifyMap(msg,from)){
|
||||
LOGGER.log(Level.ERROR,"player submitted invalid map",state);
|
||||
else if (!verifyMap(msg, from)) {
|
||||
LOGGER.log(Level.ERROR, "player submitted invalid map", state);
|
||||
}
|
||||
else
|
||||
playerReady(getPlayerById(from), msg.getShips());
|
||||
@@ -153,11 +153,11 @@ else if(!verifyMap(msg,from)){
|
||||
/**
|
||||
* this method returns true, if the given map is valid (don't overlap or out of bound)
|
||||
*
|
||||
* @param msg the message, where the map is in
|
||||
* @param msg the message, where the map is in
|
||||
* @param playerID the player, who committed the map
|
||||
* @return true, if the map is valid
|
||||
*/
|
||||
private boolean verifyMap(MapMessage msg, int playerID){
|
||||
private boolean verifyMap(MapMessage msg, int playerID) {
|
||||
return verifyBounds(msg, playerID) && verifyOverlap(msg);
|
||||
}
|
||||
|
||||
@@ -167,11 +167,12 @@ private boolean verifyMap(MapMessage msg, int playerID){
|
||||
* @param msg is the message, where the map is in
|
||||
* @return true, if all ships are in bound
|
||||
*/
|
||||
private boolean verifyBounds(MapMessage msg, int playerID){
|
||||
private boolean verifyBounds(MapMessage msg, int playerID) {
|
||||
int mapWidth = getPlayerById(playerID).getMap().getWidth();
|
||||
int mapHeight = getPlayerById(playerID).getMap().getHeight();
|
||||
for(Battleship ship: msg.getShips()){
|
||||
if(ship.getMaxX() > mapWidth || ship.getMinX()<0 || ship.getMaxY()> mapHeight || ship.getMinY() < 0) return false;
|
||||
for (Battleship ship : msg.getShips()) {
|
||||
if (ship.getMaxX() > mapWidth || ship.getMinX() < 0 || ship.getMaxY() > mapHeight || ship.getMinY() < 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -182,27 +183,24 @@ private boolean verifyBounds(MapMessage msg, int playerID){
|
||||
* @param msg is the message, where the map is in
|
||||
* @return true, if no ships overlap
|
||||
*/
|
||||
private boolean verifyOverlap(MapMessage msg){
|
||||
List<Battleship> ships = msg.getShips();
|
||||
for(Battleship ship:ships){
|
||||
for(Battleship compareShip:ships){
|
||||
if(!(ship==compareShip)){
|
||||
if(ship.collidesWith(compareShip)){
|
||||
return false;
|
||||
}
|
||||
private boolean verifyOverlap(MapMessage msg) {
|
||||
List<Battleship> battleshipList = msg.getShips();
|
||||
for (int i = 0; i < battleshipList.size(); i++) {
|
||||
Battleship ship1 = battleshipList.get(i);
|
||||
for (int j = i + 1; j < battleshipList.size(); j++) {
|
||||
Battleship ship2 = battleshipList.get(j);
|
||||
if (ship1.collidesWith(ship2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
/*
|
||||
List<Battleship> ships = msg.getShips(); // the list the first loop iterates through
|
||||
List<Battleship> shipsReduceList = new ArrayList<>(ships); // the second list, holds the other remaining ships
|
||||
for(Battleship ship: ships){ // iterates through the first list
|
||||
shipsReduceList.remove(ship);//remove the current ship, so it doesn't check the collision with it self
|
||||
for(Battleship battleship:shipsReduceList){ // iterates through the second list
|
||||
if(ship.collidesWith(battleship)){ //if there is a collision, it returns false
|
||||
return false;
|
||||
List<Battleship> ships = msg.getShips();
|
||||
for (Battleship ship : ships) {
|
||||
for (Battleship compareShip : ships) {
|
||||
if (ship != compareShip) {
|
||||
if (ship.collidesWith(compareShip)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user