From b1cb6aec68cd26e7a6ba842d8fdbfb1856d0c14e Mon Sep 17 00:00:00 2001 From: Robert Berlin Date: Wed, 22 Sep 2021 13:33:55 +0200 Subject: [PATCH 1/3] Added Comparable for Weapon level and added sort to Weapon constructor --- .../kalebmarc/textfighter/main/Weapon.java | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index 45055909..48a2e615 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -7,8 +7,9 @@ import javax.swing.*; import java.util.ArrayList; +import java.util.Collections; -public class Weapon { +public class Weapon implements Comparable { //Weapon List public static final ArrayList arrayWeapon = new ArrayList<>(); @@ -61,6 +62,8 @@ public Weapon(String name, int ammoUsed, int ammoIncludedWithPurchase, boolean b } + Collections.sort(arrayWeapon); + } public Weapon(String name, boolean startingWeapon, boolean buyable, int price, int level,//For Melee @@ -197,13 +200,13 @@ public void dealDam() { if (this.melee) { /* * Melee Attack - */ + */ damageDealt = Random.RInt(this.damageMin, this.damageMax); } else { - /* - * Gun Attack - */ + /* + * Gun Attack + */ if (getAmmo() >= this.ammoUsed) { for (int i = 1; i <= this.ammoUsed; i++) { @@ -230,19 +233,19 @@ public void dealDam() { com.hotmail.kalebmarc.textfighter.player.Stats.totalDamageDealt += damageDealt; com.hotmail.kalebmarc.textfighter.player.Xp.setBattleXp(damageDealt, true); if(!Enemy.get().takeDamage(damageDealt)) { // !dead - Ui.cls(); - Ui.println("----------------------------------------------------"); - Ui.println("You have attacked a " + Enemy.get().getName() + "!"); - Ui.println("You dealt " + damageDealt + " damage with a " + this.name); - Ui.println("----------------------------------------------------"); - Ui.println("Your health: " + com.hotmail.kalebmarc.textfighter.player.Health.getStr()); - Ui.println("Enemy health: " + Enemy.get().getHeathStr()); - Ui.println("----------------------------------------------------"); - Ui.pause(); - - if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){ - Enemy.get().useFirstAidKit(); - } + Ui.cls(); + Ui.println("----------------------------------------------------"); + Ui.println("You have attacked a " + Enemy.get().getName() + "!"); + Ui.println("You dealt " + damageDealt + " damage with a " + this.name); + Ui.println("----------------------------------------------------"); + Ui.println("Your health: " + com.hotmail.kalebmarc.textfighter.player.Health.getStr()); + Ui.println("Enemy health: " + Enemy.get().getHeathStr()); + Ui.println("----------------------------------------------------"); + Ui.pause(); + + if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){ + Enemy.get().useFirstAidKit(); + } } damageDealt = 0; } @@ -376,4 +379,9 @@ public void buyAmmo() { public int getAmmoPrice() { return this.ammoPrice; } + + @Override + public int compareTo(Weapon w) { + return Integer.compare(this.level, w.level); + } } \ No newline at end of file From ad6898d748e296e12a05417b3c0ad82678edcdc1 Mon Sep 17 00:00:00 2001 From: Robert Berlin Date: Wed, 22 Sep 2021 13:38:06 +0200 Subject: [PATCH 2/3] Revert "Added Comparable for Weapon level and added sort to Weapon constructor" This reverts commit b1cb6aec68cd26e7a6ba842d8fdbfb1856d0c14e. --- .../kalebmarc/textfighter/main/Weapon.java | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index 48a2e615..45055909 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -7,9 +7,8 @@ import javax.swing.*; import java.util.ArrayList; -import java.util.Collections; -public class Weapon implements Comparable { +public class Weapon { //Weapon List public static final ArrayList arrayWeapon = new ArrayList<>(); @@ -62,8 +61,6 @@ public Weapon(String name, int ammoUsed, int ammoIncludedWithPurchase, boolean b } - Collections.sort(arrayWeapon); - } public Weapon(String name, boolean startingWeapon, boolean buyable, int price, int level,//For Melee @@ -200,13 +197,13 @@ public void dealDam() { if (this.melee) { /* * Melee Attack - */ + */ damageDealt = Random.RInt(this.damageMin, this.damageMax); } else { - /* - * Gun Attack - */ + /* + * Gun Attack + */ if (getAmmo() >= this.ammoUsed) { for (int i = 1; i <= this.ammoUsed; i++) { @@ -233,19 +230,19 @@ public void dealDam() { com.hotmail.kalebmarc.textfighter.player.Stats.totalDamageDealt += damageDealt; com.hotmail.kalebmarc.textfighter.player.Xp.setBattleXp(damageDealt, true); if(!Enemy.get().takeDamage(damageDealt)) { // !dead - Ui.cls(); - Ui.println("----------------------------------------------------"); - Ui.println("You have attacked a " + Enemy.get().getName() + "!"); - Ui.println("You dealt " + damageDealt + " damage with a " + this.name); - Ui.println("----------------------------------------------------"); - Ui.println("Your health: " + com.hotmail.kalebmarc.textfighter.player.Health.getStr()); - Ui.println("Enemy health: " + Enemy.get().getHeathStr()); - Ui.println("----------------------------------------------------"); - Ui.pause(); - - if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){ - Enemy.get().useFirstAidKit(); - } + Ui.cls(); + Ui.println("----------------------------------------------------"); + Ui.println("You have attacked a " + Enemy.get().getName() + "!"); + Ui.println("You dealt " + damageDealt + " damage with a " + this.name); + Ui.println("----------------------------------------------------"); + Ui.println("Your health: " + com.hotmail.kalebmarc.textfighter.player.Health.getStr()); + Ui.println("Enemy health: " + Enemy.get().getHeathStr()); + Ui.println("----------------------------------------------------"); + Ui.pause(); + + if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){ + Enemy.get().useFirstAidKit(); + } } damageDealt = 0; } @@ -379,9 +376,4 @@ public void buyAmmo() { public int getAmmoPrice() { return this.ammoPrice; } - - @Override - public int compareTo(Weapon w) { - return Integer.compare(this.level, w.level); - } } \ No newline at end of file From 5ae44bc4013bcdbdb30e496c17d5e205e70f288c Mon Sep 17 00:00:00 2001 From: Robert Berlin Date: Wed, 22 Sep 2021 13:39:46 +0200 Subject: [PATCH 3/3] Added Comparable for Weapon level and added sort to Weapon constructor --- .../kalebmarc/textfighter/main/Weapon.java | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java index 45055909..48a2e615 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java @@ -7,8 +7,9 @@ import javax.swing.*; import java.util.ArrayList; +import java.util.Collections; -public class Weapon { +public class Weapon implements Comparable { //Weapon List public static final ArrayList arrayWeapon = new ArrayList<>(); @@ -61,6 +62,8 @@ public Weapon(String name, int ammoUsed, int ammoIncludedWithPurchase, boolean b } + Collections.sort(arrayWeapon); + } public Weapon(String name, boolean startingWeapon, boolean buyable, int price, int level,//For Melee @@ -197,13 +200,13 @@ public void dealDam() { if (this.melee) { /* * Melee Attack - */ + */ damageDealt = Random.RInt(this.damageMin, this.damageMax); } else { - /* - * Gun Attack - */ + /* + * Gun Attack + */ if (getAmmo() >= this.ammoUsed) { for (int i = 1; i <= this.ammoUsed; i++) { @@ -230,19 +233,19 @@ public void dealDam() { com.hotmail.kalebmarc.textfighter.player.Stats.totalDamageDealt += damageDealt; com.hotmail.kalebmarc.textfighter.player.Xp.setBattleXp(damageDealt, true); if(!Enemy.get().takeDamage(damageDealt)) { // !dead - Ui.cls(); - Ui.println("----------------------------------------------------"); - Ui.println("You have attacked a " + Enemy.get().getName() + "!"); - Ui.println("You dealt " + damageDealt + " damage with a " + this.name); - Ui.println("----------------------------------------------------"); - Ui.println("Your health: " + com.hotmail.kalebmarc.textfighter.player.Health.getStr()); - Ui.println("Enemy health: " + Enemy.get().getHeathStr()); - Ui.println("----------------------------------------------------"); - Ui.pause(); - - if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){ - Enemy.get().useFirstAidKit(); - } + Ui.cls(); + Ui.println("----------------------------------------------------"); + Ui.println("You have attacked a " + Enemy.get().getName() + "!"); + Ui.println("You dealt " + damageDealt + " damage with a " + this.name); + Ui.println("----------------------------------------------------"); + Ui.println("Your health: " + com.hotmail.kalebmarc.textfighter.player.Health.getStr()); + Ui.println("Enemy health: " + Enemy.get().getHeathStr()); + Ui.println("----------------------------------------------------"); + Ui.pause(); + + if (Enemy.get().getHealth() <= Enemy.get().getHealthMax() / 3){ + Enemy.get().useFirstAidKit(); + } } damageDealt = 0; } @@ -376,4 +379,9 @@ public void buyAmmo() { public int getAmmoPrice() { return this.ammoPrice; } + + @Override + public int compareTo(Weapon w) { + return Integer.compare(this.level, w.level); + } } \ No newline at end of file