My programming class is having us build a simple battle system for a text-based RPG. I have the parent class put together for the fighters, and I'm trying to make a driver class to test two automated battlers against each other. The idea is that each fighter's attack speed is added to a variable every frame until it hits 100. Once that happens, then the fighter's turn is triggered and he takes a swipe at the other guy before resetting his timer back to zero. That way, higher speed characters will get to attack more often since they're adding more to their timer each frame. Unfortunately, both fighters just stare at each other and don't do anything. If anybody on the site knows Java programming, or even just programming in general, could you take a look and tell me what's going wrong?
Driver Class
import java.util.Scanner; public class BattleTest{ public static void main(String[] args){ DungeonCharacter firstPlayer = new DungeonCharacter("Warrior 01", 1000, 5, 80, 15, 25); DungeonCharacter secondPlayer = new DungeonCharacter("Warrior 02", 1000, 3, 80, 20, 30); battle(firstPlayer, secondPlayer); } public static void battle(DungeonCharacter firstPlayer, DungeonCharacter secondPlayer){ Scanner input = new Scanner(System.in); int timer = 100; int firstPlayerTimer = 0; int secondPlayerTimer = 0; while(firstPlayer.isAlive() == true && secondPlayer.isAlive() == true){ //Display Turn Information firstPlayerTimer = firstPlayerTimer + firstPlayer.getAttackSpeed(); if(firstPlayerTimer == 100){ //Display Battle Stats System.out.println("- - - - - - - - - - - - - - - - - - - -"); System.out.println(secondPlayer.getName()); System.out.println("HP: " + secondPlayer.getHitPoints()); System.out.println(" "); System.out.println(firstPlayer.getName()); System.out.println("HP: " + firstPlayer.getHitPoints()); System.out.println(" "); System.out.println(" "); firstPlayer.attack(secondPlayer); input.nextLine(); firstPlayerTimer = 0; } if(secondPlayerTimer == 100){ //Display Battle Stats System.out.println("- - - - - - - - - - - - - - - - - - - -"); System.out.println(secondPlayer.getName()); System.out.println("HP: " + secondPlayer.getHitPoints()); System.out.println(" "); System.out.println(firstPlayer.getName()); System.out.println("HP: " + firstPlayer.getHitPoints()); System.out.println(" "); System.out.println(" "); secondPlayer.attack(firstPlayer); input.nextLine(); secondPlayerTimer = 0; } } } }
DungeonCharacter Class
public class DungeonCharacter{ //Variable List protected String name; protected int hitPoints; protected int attackSpeed; protected double chanceToHit; protected int damageMin, damageMax; public DungeonCharacter(String name, int hitPoints, int attackSpeed, double chanceToHit, int damageMin, int damageMax){ this.name = name; this.hitPoints = hitPoints; } public String getName(){ return this.name; } public int getHitPoints(){ return this.hitPoints; } public int getAttackSpeed(){ return this.attackSpeed; } public void addHitPoints(int hitPoints){ if(this.hitPoints <= 0){ return; } else{ this.hitPoints = this.hitPoints + hitPoints; } } public void subtractHitPoints(int hitPoints){ if(this.hitPoints <= 0){ return; } else{ this.hitPoints = this.hitPoints - hitPoints; } } //if(== 0 // monster has been killed public boolean isAlive(){ if(this.hitPoints > 0){ return true; } else{ return false; } } public void attack(DungeonCharacter opponent){ boolean canAttack; int damage; canAttack = Math.random() <= chanceToHit; //If a randomly generated number is less than "chanceToHit" if(canAttack){ damage = (int)(Math.random() * (damageMax - damageMin + 1)) + damageMin; opponent.subtractHitPoints(damage); System.out.println(); } //end if(canAttack) else{ System.out.println(this.getName() + "'s attack on " + opponent.getName() + " has failed!"); } } }