Skip to content

Commit

Permalink
Merge pull request hhaslam11#124 from roberlin1992/issue67
Browse files Browse the repository at this point in the history
Issue hhaslam11#67: Sorting Weapons by Level
  • Loading branch information
hhaslam11 authored Sep 22, 2021
2 parents 627cfd6 + 5ae44bc commit 2391a88
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/com/hotmail/kalebmarc/textfighter/main/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;

public class Weapon {
public class Weapon implements Comparable<Weapon> {

//Weapon List
public static final ArrayList<Weapon> arrayWeapon = new ArrayList<>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2391a88

Please sign in to comment.