From 3807eb5d0f2ec53c2042c804ae23c41cd5fb7374 Mon Sep 17 00:00:00 2001 From: Leen Dereu Date: Fri, 23 Mar 2018 13:50:00 +0100 Subject: [PATCH] collision --- OGP1718-Worms/src/worms/model/Worm.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 21dc85f..6a2c8d0 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -593,8 +593,12 @@ public class Worm { subtractActionPoints(cost); } - public void collision() { - + public void collision(Worm smallestWorm, Worm largestWorm) { + long total = 1 + (new Random().nextLong() * (10 - 1)); + long loseSmallest = total/(largestWorm.getOrientation()/(smallestWorm.getOrientation()+largestWorm.getOrientation())); + long loseLargest = total - loseSmallest; + smallestWorm.decreaseHitPoints(loseSmallest); + largestWorm.decreaseHitPoints(loseLargest); } //=================================================================================== @@ -769,7 +773,7 @@ public class Worm { //=================================================================================== @Basic @Raw - public long gethitPoints() { + public long getHitPoints() { return this.hitPoints; } @@ -782,6 +786,10 @@ public class Worm { private long hitPoints; + public void decreaseHitPoints(long value) { + setHitPoints(getHitPoints() - value); + } + //=================================================================================== // endregion }