java - Are enums changeable at all? -
i've been working on game, , in game i'm summoner has tamed monsters (much pokemon). want , have backpack of 5 tamed monsters, of can spawn 1 @ time. recommended me use enums (i can't contact person anymore :(), i've been looking @ few enum tutorials , examples, , can't figure out how me.
let enum :
public enum tamedmonsterstats { elf(0,"res/siren_monster_girl_sprite_by_tsarcube-d52y2zu.png",0,100); dragon(0,"res/dragon.png",0,100); private int haveit; private string photoname; private int typeofdamage;/* * 0: dark * 1: light * 2: */ private int hp; tamedmonsterstats(int haveit,string photoname,int typeofdamage,int hp){ this.haveit = haveit; this.photoname = photoname; this.typeofdamage = typeofdamage; this.hp = hp; } public int gethaveit(){ return haveit; } public string getphotoname(){ return photoname; } public int gettypeofdamage(){ return typeofdamage; } public int gethp(){ return hp; } public void sethp(int hp) { hp = hp; } }
this kind of work, daveychu pointed out, makes impossible me have 2 instances of same creature, idea have enum backpack monster1,monster2,monster3,monster4,monster5 , , filling them values dynamically, feel doing means shouldn't requiring enums @ all, true?
you can add setter method on enum:
public void sethp(int hp) { hp = hp; }
however, i'm bit wary of use of enum. in situation, 1 "dragon" instance exist @ time wonder if user wants have more of them or if enemy has 1 @ same time.
your typeofdamage on other hand excellent candidate enum:
public enum damagetype { dark, light, normal }
you can use enum:
elf(0, "res/siren_monster_girl_sprite_by_tsarcube-d52y2zu.png", damagetype.dark, 100), dragon(0, "res/dragon.png", damagetype.light, 100); private damagetype typeofdamage; tamedmonsterstats(int haveit, string photoname, damagetype typeofdamage, int hp) { this.typeofdamage = typeofdamage; } public damagetype gettypeofdamage() { return typeofdamage; }
it makes lot more readable having pass random integers.
Comments
Post a Comment