'Should I create a class instead of object for weapons?
I am trying to create weapons of God Of War 3 game. For people who doesn't know God Of War 3, we have 6 weapons (I am not counting bow, head and boots) and just 4 weapon are upgradable. Other 2 weapons are already maximum level. Also damage multiplier increasing amount in each level is different for all weapons. And each weapon needs a different amount of red orb to be upgraded.(be used to upgrade equipments) So, what do you think? Should I create a class for each weapon or create an object for each weapon? If I don't create a class for each weapon, it looks like that:
class Weapons{
static int redOrb=0; //We need that to upgrade our equipments.
int level; //Weapon level
boolean useStatus; //If the weapon is unlocked, useStatus should be true, otherwise false.
String name;
int[] BladesOfExileLVL={4000,7000,8000,10000}; //That's mean how much red orbs are needed to upgrade the weapons
int[] ClawsOfHadesLVL={3000,5000,6000,9000};
int[] NemeanCestusLVL={3000,5000,5000,8000};
int[] NemesisWhipLVL={3000,5000,5000,8000};
Weapons(boolean useStatus,String name){
level=1;
this.name=name;
}
public Weapons(int level, boolean useStatus,String name){
this.level=level;
this.name=name;
}
//More codes...
}
public class GodOfWar {
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
Weapons BladesOfAthena=new Weapons(5,true,"Blades Of Athena");
Weapons BladesOfExile=new Weapons(false,"Blades Of Exile");
Weapons BladeOfOlympus=new Weapons(false,"Blade Of Olympus");
Weapons ClawsOfHades=new Weapons(false,"Claws Of Hades");
Weapons NemeanCestus=new Weapons(false,"Nemean Cestus");
Weapons NemesisWhip=new Weapons(false,"Nemesis Whip");
ArrayList<Weapons> KratosWeapons=new ArrayList<Weapons>();
KratosWeapons.add(BladesOfAthena);
KratosWeapons.add(BladesOfExile);
KratosWeapons.add(BladeOfOlympus);
KratosWeapons.add(ClawsOfHades);
KratosWeapons.add(NemeanCestus);
KratosWeapons.add(NemesisWhip);
If I create a class for each weapon, it looks like that now:
class Weapons {
static int redOrb = 0;
private int level;
private boolean useStatus;
String name;
Weapons(int level, boolean useStatus, String name) {
this.level = level;
this.name = name;
}
Weapons(boolean useStatus, String name) {
level = 1;
this.name = name;
}
//More codes...
} class BladesOfAthena extends Weapons{
BladesOfAthena(boolean useStatus,String name){
super(useStatus,name);
}
void levelUpNeededOrb(){
System.out.println("This weapon is already at maximum level");
}
void levelUp(){
}
}
class BladesOfExile extends Weapons{
static int[] LVLUpCost={4000,7000,8000,10000};
BladesOfExile(boolean useStatus,String name){
super(useStatus,name);
}
}
class BladeOfOlympus extends Weapons{
BladeOfOlympus(boolean useStatus,String name){
super(useStatus,name);
}
}
class ClawsOfHades extends Weapons{
static int[] LVLUpCost={3000,5000,6000,9000};
ClawsOfHades(boolean useStatus,String name){
super(useStatus,name);
}
}
class NemeanCestus extends Weapons{
int[] LVLUpCost={3000,5000,5000,8000};
NemeanCestus(boolean useStatus,String name){
super(useStatus,name);
}
}
class NemesisWhip extends Weapons{
private int[] LVLUpCost={3000,5000,5000,8000};
NemesisWhip(boolean useStatus,String name){
super(useStatus,name);
}
}
public class GodOfWar2 {
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
ArrayList<Weapons> KratosWeapons=new ArrayList<Weapons>();
BladesOfAthena bladesOfAthena=new BladesOfAthena(true,"Blades Of Athena");
BladesOfExile bladesOfExile=new BladesOfExile(false,"Blades Of Exile");
BladeOfOlympus bladeOfOlympus=new BladeOfOlympus(false,"Blade Of Olympus");
ClawsOfHades clawsOfHades=new ClawsOfHades(false,"Claws Of Hades");
NemeanCestus nemeanCestus=new NemeanCestus(false,"Nemean Cestus");
NemesisWhip nemesisWhip=new NemesisWhip(false,"NemesisWhip");
KratosWeapons.add(bladesOfAthena);
KratosWeapons.add(bladesOfExile);
KratosWeapons.add(bladeOfOlympus);
KratosWeapons.add(clawsOfHades);
KratosWeapons.add(nemeanCestus);
KratosWeapons.add(nemesisWhip);
These two codes are different and I haven't decided which one is better. Could you help me? And I have 1 more question. Should I use inheritance or inner classes for weapons if you say that I need to create classes instead of objects?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
