From 1974396f61aa8f109b03b7f10228700bcfa3a091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Fri, 13 May 2016 22:10:29 +0200 Subject: [PATCH] Implemented initial player death --- cicaprojekt/Player.java | 22 ++++++++++++++++------ cicaprojekt/PlayerBase.java | 18 +++++++++--------- cicaprojekt/PlayerBaseDrawer.java | 5 +++-- cicaprojekt/PlayerDrawer.java | 2 ++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/cicaprojekt/Player.java b/cicaprojekt/Player.java index 5a5342f..a135002 100644 --- a/cicaprojekt/Player.java +++ b/cicaprojekt/Player.java @@ -7,6 +7,12 @@ public class Player extends PlayerBase { private List zpmContainer; private Box boxLifted; + @Override + public void destroy() { + destroyed = true; + if(hasBox()) + boxLifted.destroy(); + } public Player(String name, Tile startTile, Direction startDirection) { super(name, startTile, startDirection); @@ -18,14 +24,17 @@ public class Player extends PlayerBase { } public void boxLift() { - boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).getABox(); + if(!isDestroyed()) + boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).getABox(); } public void boxDrop() { - Tile target = currentTile.getAdjacentTile(facingDirection); - if(target.isSteppable()) { - target.putABox(boxLifted); - boxLifted = null; + if(!isDestroyed()) { + Tile target = currentTile.getAdjacentTile(facingDirection); + if (target.isSteppable()) { + target.putABox(boxLifted); + boxLifted = null; + } } } @@ -35,7 +44,8 @@ public class Player extends PlayerBase { } public void shootStargate(Stargate stargate) { - this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection); + if(!isDestroyed()) + this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection); } public int getZPMCount(){ diff --git a/cicaprojekt/PlayerBase.java b/cicaprojekt/PlayerBase.java index 836d453..892a2cf 100644 --- a/cicaprojekt/PlayerBase.java +++ b/cicaprojekt/PlayerBase.java @@ -31,16 +31,16 @@ public class PlayerBase implements Destroyable { } public void move(Direction direction) { - this.setFacingDirection(direction); - Tile adjtile = this.getCurrentTile().getAdjacentTile(direction); + if(!isDestroyed()) { + this.setFacingDirection(direction); + Tile adjtile = this.getCurrentTile().getAdjacentTile(direction); - if (adjtile != null) - { - if (adjtile.isSteppable()) - { - currentTile.onExit(this); - setCurrentTile(adjtile); - adjtile.onEntry(this); + if (adjtile != null) { + if (adjtile.isSteppable()) { + currentTile.onExit(this); + setCurrentTile(adjtile); + adjtile.onEntry(this); + } } } } diff --git a/cicaprojekt/PlayerBaseDrawer.java b/cicaprojekt/PlayerBaseDrawer.java index 190ffb9..c6a967d 100644 --- a/cicaprojekt/PlayerBaseDrawer.java +++ b/cicaprojekt/PlayerBaseDrawer.java @@ -12,7 +12,6 @@ public class PlayerBaseDrawer extends AbstractDrawer implements Drawer { @Override public void draw() throws IOException { - switch(playerbase.name){ case "Replicator": switch(playerbase.facingDirection){ @@ -29,7 +28,9 @@ public class PlayerBaseDrawer extends AbstractDrawer implements Drawer { changeImage("Replicator_Left.png"); break; } - } + } + if(playerbase.isDestroyed()) + changeImage("Empty.png"); } @Override diff --git a/cicaprojekt/PlayerDrawer.java b/cicaprojekt/PlayerDrawer.java index dc3fa9b..6689ac8 100644 --- a/cicaprojekt/PlayerDrawer.java +++ b/cicaprojekt/PlayerDrawer.java @@ -87,6 +87,8 @@ public class PlayerDrawer extends AbstractDrawer implements Drawer { break; } } + if(player.isDestroyed()) + changeImage("Empty.png"); } @Override