corrected 'Editorstate' and 'GameServerLogic' and edited 'SeaSynchronizer' and added assets
This commit is contained in:
@@ -7,9 +7,13 @@
|
|||||||
|
|
||||||
package pp.battleship.client.gui;
|
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.Material;
|
||||||
import com.jme3.material.RenderState.BlendMode;
|
import com.jme3.material.RenderState.BlendMode;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
@@ -26,6 +30,7 @@
|
|||||||
import static pp.util.FloatMath.HALF_PI;
|
import static pp.util.FloatMath.HALF_PI;
|
||||||
import static pp.util.FloatMath.PI;
|
import static pp.util.FloatMath.PI;
|
||||||
|
|
||||||
|
//TODO models
|
||||||
/**
|
/**
|
||||||
* The {@code SeaSynchronizer} class is responsible for synchronizing the graphical
|
* 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.
|
* representation of the ships and shots on the sea map with the underlying data model.
|
||||||
@@ -35,6 +40,9 @@
|
|||||||
class SeaSynchronizer extends ShipMapSynchronizer {
|
class SeaSynchronizer extends ShipMapSynchronizer {
|
||||||
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
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 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 COLOR = "Color"; //NON-NLS
|
||||||
private static final String SHIP = "ship"; //NON-NLS
|
private static final String SHIP = "ship"; //NON-NLS
|
||||||
private static final String SHOT = "shot"; //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
|
* @return the spatial representing the battleship
|
||||||
*/
|
*/
|
||||||
private Spatial createShip(Battleship ship) {
|
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;
|
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.
|
* Creates a new {@link Material} with the specified color.
|
||||||
* If the color includes transparency (i.e., alpha value less than 1),
|
* 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
@@ -242,7 +242,7 @@ public void loadMap(File file) throws IOException {
|
|||||||
if (!dto.fits(logic.getDetails()))
|
if (!dto.fits(logic.getDetails()))
|
||||||
throw new IOException(lookup("map.doesnt.fit"));
|
throw new IOException(lookup("map.doesnt.fit"));
|
||||||
if (!verifyMap(dto)) {
|
if (!verifyMap(dto)) {
|
||||||
throw new IOException("Map is not valid");
|
throw new IOException(lookup("map is not valid"));
|
||||||
}
|
}
|
||||||
ownMap().clear();
|
ownMap().clear();
|
||||||
dto.getShips().forEach(ownMap()::add);
|
dto.getShips().forEach(ownMap()::add);
|
||||||
@@ -263,14 +263,16 @@ private boolean verifyMap(ShipMapDTO dto){ //MapMessage msg, int playerID
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* checks, whether a ship is out of the grid
|
* checks, whether a ship is out of the grid
|
||||||
|
*
|
||||||
* @param dto is the Map, where the ships are in
|
* @param dto is the Map, where the ships are in
|
||||||
* @return true, if all ships are in bound
|
* @return true, if all ships are in bound
|
||||||
*/
|
*/
|
||||||
private boolean verifyBounds(ShipMapDTO dto) {
|
private boolean verifyBounds(ShipMapDTO dto) {
|
||||||
for(Battleship ship: dto.getShips()){
|
|
||||||
int mapWidth = dto.getWidth();
|
int mapWidth = dto.getWidth();
|
||||||
int mapHeight = dto.getHeight();
|
int mapHeight = dto.getHeight();
|
||||||
if(ship.getMaxX()>mapWidth || ship.getMinX()<0 || ship.getMaxY()> mapHeight || ship.getMinY() < 0) return false;
|
for (Battleship ship : dto.getShips()) {
|
||||||
|
if (ship.getMaxX() > mapWidth || ship.getMinX() < 0 || ship.getMaxY() > mapHeight || ship.getMinY() < 0)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -282,31 +284,29 @@ private boolean verifyBounds(ShipMapDTO dto){
|
|||||||
* @return true, if no ships overlap
|
* @return true, if no ships overlap
|
||||||
*/
|
*/
|
||||||
private boolean verifyOverlap(ShipMapDTO dto) {
|
private boolean verifyOverlap(ShipMapDTO dto) {
|
||||||
List<Battleship> ships = dto.getShips();
|
List<Battleship> battleshipList = dto.getShips();
|
||||||
for(Battleship ship : ships){
|
for (int i = 0; i < battleshipList.size(); i++) {
|
||||||
for(Battleship compareShip : ships){
|
Battleship ship1 = battleshipList.get(i);
|
||||||
if(!(ships==compareShip)){
|
for (int j = i + 1; j < battleshipList.size(); j++) {
|
||||||
if(ship.collidesWith(compareShip)){
|
Battleship ship2 = battleshipList.get(j);
|
||||||
|
if (ship1.collidesWith(ship2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
List<Battleship> ships = dto.getShips();
|
List<Battleship> ships = dto.getShips();
|
||||||
List<Battleship> shipsReduceList = new ArrayList<>(ships);
|
for (Battleship ship : ships) {
|
||||||
for(Battleship ship: ships){ //iterate through the list of all ships on the grid
|
for (Battleship compareShip : ships) {
|
||||||
shipsReduceList.remove(ship); // delete the current ship from the second list, so it will not test, if it collides with itself
|
if (ships != compareShip) {
|
||||||
for(Battleship battleship:shipsReduceList){ //iterates through the other ships
|
if (ship.collidesWith(compareShip)) return false;
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -171,7 +171,8 @@ private boolean verifyBounds(MapMessage msg, int playerID){
|
|||||||
int mapWidth = getPlayerById(playerID).getMap().getWidth();
|
int mapWidth = getPlayerById(playerID).getMap().getWidth();
|
||||||
int mapHeight = getPlayerById(playerID).getMap().getHeight();
|
int mapHeight = getPlayerById(playerID).getMap().getHeight();
|
||||||
for (Battleship ship : msg.getShips()) {
|
for (Battleship ship : msg.getShips()) {
|
||||||
if(ship.getMaxX() > mapWidth || ship.getMinX()<0 || ship.getMaxY()> mapHeight || ship.getMinY() < 0) return false;
|
if (ship.getMaxX() > mapWidth || ship.getMinX() < 0 || ship.getMaxY() > mapHeight || ship.getMinY() < 0)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -183,26 +184,23 @@ private boolean verifyBounds(MapMessage msg, int playerID){
|
|||||||
* @return true, if no ships overlap
|
* @return true, if no ships overlap
|
||||||
*/
|
*/
|
||||||
private boolean verifyOverlap(MapMessage msg) {
|
private boolean verifyOverlap(MapMessage msg) {
|
||||||
List<Battleship> ships = msg.getShips();
|
List<Battleship> battleshipList = msg.getShips();
|
||||||
for(Battleship ship:ships){
|
for (int i = 0; i < battleshipList.size(); i++) {
|
||||||
for(Battleship compareShip:ships){
|
Battleship ship1 = battleshipList.get(i);
|
||||||
if(!(ship==compareShip)){
|
for (int j = i + 1; j < battleshipList.size(); j++) {
|
||||||
if(ship.collidesWith(compareShip)){
|
Battleship ship2 = battleshipList.get(j);
|
||||||
|
if (ship1.collidesWith(ship2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
List<Battleship> ships = msg.getShips(); // the list the first loop iterates through
|
List<Battleship> ships = msg.getShips();
|
||||||
List<Battleship> shipsReduceList = new ArrayList<>(ships); // the second list, holds the other remaining ships
|
for (Battleship ship : ships) {
|
||||||
for(Battleship ship: ships){ // iterates through the first list
|
for (Battleship compareShip : ships) {
|
||||||
shipsReduceList.remove(ship);//remove the current ship, so it doesn't check the collision with it self
|
if (ship != compareShip) {
|
||||||
for(Battleship battleship:shipsReduceList){ // iterates through the second list
|
if (ship.collidesWith(compareShip)) return false;
|
||||||
if(ship.collidesWith(battleship)){ //if there is a collision, it returns false
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user