Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public void addWeapon(Weapon newWeapon) {
* Gets the equipped weapon of this Character
*/
public Weapon getEquippedWeapon() {
if (equippedWeapon == -1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's out of range but not -1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pfft

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no u

return null;
}
return weapons.get(equippedWeapon);
}

Expand Down
16 changes: 16 additions & 0 deletions src/Fists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Default weapon for when you are unarmed
*/
public class Fists extends Weapon {
public Fists() {
super("fists", "your hands", 3);
}


@Override
public boolean useOn(Character target) {
target.health -= getBaseDamage();
System.out.println("Slapped for " + getBaseDamage() + " damage.");
return true;
}
}
19 changes: 14 additions & 5 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class Main {
public static void main(String[] args) {
Weapon defaultWeapon = new Fists();
ArrayList<Character> characters = new ArrayList<>();
/*
Adding Your Character to the Arena, by Avery
Expand Down Expand Up @@ -37,12 +38,20 @@ public static void main(String[] args) {
continue;
}
int targetIndex = curr.pickTarget(characters);
if (targetIndex != i) {
System.out.println(curr.getName() + " attacked " +
characters.get(targetIndex).getName() +
" with their " + curr.getEquippedWeapon().getName());
if (targetIndex == -1) {
System.out.println(curr.getName() + "'s attack failed because" +
" it couldn't find a good target.");
continue;
}
Character target = characters.get(targetIndex);
Weapon weapon = curr.getEquippedWeapon();
if (weapon == null) {
weapon = defaultWeapon;
}
curr.getEquippedWeapon().useOn(characters.get(targetIndex));
System.out.println(curr.getName() + " attacks " +
target.getName() +
" with their " + weapon.getName());
weapon.useOn(target);
}
if (characters.size() == 1) {
System.out.println(characters.get(0).getName() + " won!");
Expand Down