I've just learned a bit about enums, and I want to give them a try in my new minigame, currently, I am using them to tell the state of a current arena. From my understanding, if I were to use enums to tell the state of an arena instead of a HashMap etc., would I only be able to have 1 arena per server? If this isn't the case, How do I set it up so that I can have multiple arenas?
Starfire1337 First of all, create an arena object. (Main step on creating arenas). After that, store all your variables (name, id, maxPlayers, spawns, etc...) And to apply that enum, make sure you add the enum class as a variable. ex: Code:java package me.FabeGabe; public class Arena { // All your variables...private State s; public Arena(**YOUR VARIABLES HERE**) {// Make sure your arena's state is set to// lobby once it's created so players can join.s = State.LOBBY;} //Get the arena's state.public State getState() {return s;} }
Starfire1337 enums are just a set of constants with optional properties and methods. http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
Enums can be used like classes. What I mean by this is that you can use them as objects. So yes you can do it for multiple arenas. Simple do new(enumName(AnyValuesIfYouRequireFromEnum)). You will then have an instance of that enum.
Forseth11 You can't initialize an enum. Please know what you're talking about before giving advice to others. Starfire1337 I would recommend you look at the link fireblast709 for more information about enums, however I'll give you a simplified one which answers your question. If you store the state of an arena in the arena class you do not require to have a HashMap containing the enum and the arena (as that wouldn't be the smartest idea anyways). When you're comparing enums it is recommended to use '==' or switch statements.
fireblast709 mazentheamazin Oh my gosh I can not believe I even said something that stupid last night! Why did I say us an enum like: new enum? I meant to say something like: enumName var = enumName.value.