added 'Shell' and 'ShellControl' and editet the two visitors 'Visitor' and 'VoidVisitor'

This commit is contained in:
Benjamin Feyer
2024-10-10 22:23:55 +02:00
parent dffb5b4d63
commit 30a735bd6e
4 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package pp.battleship.client.gui;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import pp.battleship.model.Shell;
import pp.battleship.model.ShipMap;
public class ShellControl extends AbstractControl {
private Shell shell;
private ShipMap map;
private static final Float HEIGHT = 0f;
public ShellControl(Shell shell, ShipMap map){
this.shell=shell;
this.map=map;
}
@Override
protected void controlUpdate(float tpf) {
if (spatial == null) return;
if(spatial.getLocalTranslation().getY()<=HEIGHT){
spatial.getParent().detachChild(spatial);
}
else{
spatial.move(0,-0.5f*tpf,0);
}
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}
public Shell getShell(){
return shell;
}
}

View File

@@ -0,0 +1,31 @@
package pp.battleship.model;
public class Shell implements Item {
private IntPoint target;
public Shell(IntPoint target){
this.target=target;
}
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
@Override
public void accept(VoidVisitor visitor) {
visitor.visit(this);
}
public IntPoint getTarget(){
return target;
}
}

View File

@@ -28,4 +28,6 @@ public interface Visitor<T> {
* @return the result of visiting the Battleship element * @return the result of visiting the Battleship element
*/ */
T visit(Battleship ship); T visit(Battleship ship);
T visit(Shell shell);
} }

View File

@@ -25,4 +25,6 @@ public interface VoidVisitor {
* @param ship the Battleship element to visit * @param ship the Battleship element to visit
*/ */
void visit(Battleship ship); void visit(Battleship ship);
void visit(Shell shell);
} }