-1
I am developing a project in java, a "farm game" where there are several Tats for the character that is created. When we create a character defenimos which his class, it will influence his Stats.
My problem is here, when I choose the class the Stats do not update properly.
Code for choosing the class:
import java.util.InputMismatchException;
public class Knight extends Game {
public static PlayerClass chooseSubClass() {
System.out.println("1 -» Heavy \n2 -» SwordsMaster \n3 -» Royal");
int op = 0;
while (op == 0) {
try {
op = Main.in.nextInt();
} catch (InputMismatchException ex) {
System.out.println(ex);
}
}
PlayerClass playerClass;
switch (op) {
case 1:
playerClass = new Heavy();
break;
case 2:
playerClass = new Swordsmaster();
break;
case 3:
playerClass = new Royal ();
break;
default:
playerClass = chooseSubClass();
break;
}
return playerClass;
}
}
If heavy choice:
public class Heavy extends PlayerClass {
public Heavy() {
attackDamage += 50;
armorPenetration += 20;
}
}
The Tats:
public class PlayerClass {
public long attackDamage = 10;
public long armorPenetration;
public long magicDamage= 10;
public long magicPenetration;
public double attackSpeed= 1;
public long money = 100;
public int level = 1;
}
Player code
public class Player extends PlayerClass{
private String playerName;
private PlayerClass playerClass;
public String classes = "1 -» Knight \n2 -» Mage \n3 -» Archer";
//Chooses the class and subclass of the player
public void chooseClass() {
System.out.println(classes);
int op = Main.in.nextInt();
switch (op) {
case 1:
playerClass = Knight.chooseSubClass();
break;
case 2:
playerClass = Mage.chooseSubClass();
break;
default:
chooseClass();
break;
}
}
// Setter method
public void setPlayerName(String name) {
playerName = name;
}
// Getter method
public String getPlayerName() {
return playerName;
}
public String getClassName() {
return playerClass.getClass().getName();
}
}