Hi guys I'm kinda new to Java Programming so I'm asking help for the algorithm for my code any help would do or suggestions thank you
Character class
CharacterDuel Main class
Dice class
Swordsman Class
Wizard Class
Character class
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package rpg; /** * * @author jomaejen6 */ public class Character { // TODO code application logic here //static variables static Dice dice = new Dice(); //instance variables public String name; public int strength,dexterity,intelligence,maxlife,currentlife; public Character(String n, int s, int d,int i){ name = n; strength = s; dexterity = d; intelligence = i; maxlife= dice.roll(); currentlife = maxlife; } //to return a random dice roll using the roll method in the Dice.java, //modified by the character's strength public int attack(){ return (dice.roll()) + strength; } //decreases the currentlife by the damage parameter public void wound(int damage){ this.currentlife = this.currentlife - damage; } //increases current life by the heal parameter //currentlife cannot be greater than maxlife public void heal(int Healing){ //this.currentlife = this.currentlife + heal; if(this.currentlife<this.maxlife) { currentlife+=Healing; } } //returns name public String getName(){ return name; } //returns strength public int getStrength(){ return strength; } //returns dexterity public int getDexterity(){ return dexterity; } //returns intelligence public int getIntelligence(){ return intelligence; } //returns currentlife public int getCurrentLife(){ return currentlife; } //returns maxlife public int getMaxLife(){ return maxlife; } }
CharacterDuel Main class
package rpg; public class CharacterDuel { public static void main(String[] args) { Wizard Nami = new Wizard("Nami",3,4,5); Swordsman Zoro = new Swordsman("Zoro",6,5,4); int damage; for(int i = 1;;i++) { System.out.println("Round " + i); System.out.println(Nami.getName()+"'s Health: "+Nami.getMaxLife()); System.out.println(Zoro.getName()+"'s Health: "+Zoro.getMaxLife()); // check to see if character has magic points left to cast spells, // otherwise, attack if(Nami.getCurrentMagic()>=5) { damage = Nami.castLightningBolt(); System.out.println(Nami.getName()+" uses Lightning Bolt to "+Zoro.getName()+" for "+damage); }else{ damage = Nami.attack(); System.out.println(Nami.getName()+" Smacks "+Zoro.getName()+" for "+damage); } if( (Nami.getCurrentMagic() >= 8) && (Nami.getCurrentLife() < 10) ) { Nami.heal(i); System.out.println(Nami.getName() + " Casts heal for " +Nami.castHeal()); Zoro.wound(damage); if (Zoro.getCurrentLife()<=0) { System.out.println(Nami.getName()+" wins!"); break; } } if (Zoro.getCurrentMagic()>=5) { damage = Zoro.swordSlash(); System.out.println(Zoro.getName()+" uses SwordSlash to "+Nami.getName()+" for "+damage); } else { damage = Zoro.attack(); System.out.println(Zoro.getName()+" Smacks "+Nami.getName()+" for "+damage); } if( (Zoro.getCurrentMagic() >= 5) && (Zoro.getCurrentLife() < 10) ) { Zoro.heal(i); System.out.println(Zoro.getName() + " Casts mindTransfer for " +Zoro.mindTransfer()); Nami.wound(damage); if (Nami.getCurrentLife()<=0) { System.out.println(Zoro.getName()+" wins!"); break; } } } } }
Dice class
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package rpg; import java.util.Random; /** * * @author jomaejen6 */ public class Dice { private Random r; /** * Initializes the random number generator */ public Dice(){ r=new Random(); } /** * Returns a random integer between 1 and 6 using Random r */ public int roll(){ return r.nextInt(24)+1; } }
Swordsman Class
package rpg; public class Swordsman extends Character { /** instance variables */ int maxmagic; int currentmagic; int mindTransfer; String s ="Swordsman"; public Swordsman(String n, int s, int d, int i) { super (n, s, d, i); maxmagic = 10; currentmagic = maxmagic; } public int swordSlash() { if(currentmagic >=5 ){ currentmagic = (currentmagic - 5) ; return dice.roll()+getStrength(); } return 0; } public int mindTransfer() { mindTransfer = dice.roll()+getStrength(); if(currentmagic >=8 ){ currentmagic = (currentmagic - 8)+dice.roll()+currentlife; } return mindTransfer; } public int getMaxMagic() { maxmagic = dice.roll()+10; return maxmagic; } public int getCurrentMagic() { currentmagic = maxmagic; return currentmagic; } }
Wizard Class
package rpg; public class Wizard extends Character { /** instance variables */ int maxmagic; int currentmagic; int castheal; /** * The Wizard(String,int,int,int) constructor overrides the constructor with * the same signature in Character. It first calls that constructor using * the super keyword, then initializes maxmagic to a value, and sets * currentmagic to the same value, similar to lifepoints. */ String w ="Wizard"; public Wizard(String n, int s, int d, int i) { super (n, s, d, i); maxmagic = 10; currentmagic = maxmagic; } /** * castLightningBolt() represents casting a magic spell. The method first * checks that currentmagic is greater than/equal to 5. If it is, * currentmagic is reduced by 5 and a random number is returned using the * dice inherited from Character, modified by the character's intelligence. * Otherwise, returns 0. */ public int castLightningBolt() { if(currentmagic >=5 ){ currentmagic = (currentmagic - 5); return dice.roll()+getIntelligence(); } return 0; } /** * castHeal() represents casting a magic spell. The method first * checks that currentmagic is greater than/equal to 8. If it is, * currentmagic is reduced by 8 and the character's heal() method is * called with a random number, modified by the character's intelligence * score. The amount healed is also returned by the method. */ public int castHeal() { if(currentmagic >=8){ currentmagic = (currentmagic - 8); return (dice.roll()+getIntelligence()); } return 0; } /** * Returns maxmagic */ public int getMaxMagic() { maxmagic = dice.roll()+10; return maxmagic; } /** * Returns currentmagic */ public int getCurrentMagic() { currentmagic = maxmagic; return currentmagic; } }