Sign in to follow this  

RogueLike Class Selection

Recommended Posts

Hey everyone! It's been a while again since I've posted. I'm working on a Roguelike right now, and I'm currently in the console stage still. I'm trying to work out all the mechanics before I flush out the graphics.

Currently I plan on having several classes available to the player that have unique skill trees and stats. I have a class Entity that is the top level class for anything that can battle in the game. Monster extends Entity and Player extends Entity. Then I have each of the individual classes of Monster extend Monster and the same for the Player. However this is where I seem to have run into a snag.

When I start the game I create a Dungeon object with a random number of Floors. Dungeon then spawns those number of Floor objects, each with a random number of Rooms. Then each Floor spawns those number of Room objects, and finally each Room takes care of how many items,"interactors", and Monsters it has.

After Dungeon has spawned the entirety of it's components it generates a random story based on a static array of Strings that I pull from a "random" utility class I made. Then the game proceeds into the TUTORIAL state before going into the actual game loop. At this point the program asks the Player his/her name and profession. This is the part that confuses me. My program is currently responding to requests to the Player as such:

Pick your Job:


However a number of things escape me. I only have a few classes as of now, but I plan to expand on them, so how should I prompt the character with the classes? As of now I simply use a forLoop to run through an array of String names of the classes. But then after that how do I read in a number input to spawn the right class for the character?

Also, in anticipation of the graphics I had a few questions as well. I don't plan on making the game real time. The window will display one Room at a time and a mini-map of the rooms at the top left corner. The player will make every command from a selection of buttons at the bottom section of the screen.

This is where I get confused.

Take the following hypothetical situation:

Player is a Warrior, and enters a battle with a monster. The bottom panel displays

The player decides to attack so he clicks the attack button. The panel's "state" switches over to the attack state and displays a new set of buttons. However, each class will have a different set and number of buttons. How would I allocate them in the screen per each class? I haven't gotten to this stage yet but I would still like some feedback on it.

I'm still cleaning up the code a bit, it's quite ugly so I'm not going to post it immediately. If anyone requests it though I will gladly post it.
Thank you so much for your help, I hope my questions and descriptions were clear enough.

Share this post

Link to post
Share on other sites
epicpunnum    459
I'm still not the best when it comes to Java, but here is my response as I would go about it:
If you wish to read something into the Java console (AKA: System), your best bet is to use Scanner (java.util.Scanner), which is a means of getting information from something containing Strings. An example of this could be as follows:
[source lang="java"]import java.util.Scanner; //remember to import Scanner
public class Foo{
//Using a global array of Strings so it can be reused.
//Need to change/add a job? Just edit the array
private String[] jobs = new String[]{"ARCHER",

public static void main(String[] args){
System.out.println("Pick your Job:\n");
for (int i=1; i<=jobs.length; i++) //goes through each jobs and labels it
Scanner s = new Scanner(; //Creates scanner for (the console)
String answer = s.nextLine(); //user inputs String here.
for(String j: jobs) //for each loop. checks every name for matches
if (answer.equalsIgnoreCase(j))
//put your Player creation code here or something.
As for your Panel during turn-based combat, I would make it store an Entity. Then, every Entity in your game could have its own moveset. Just give your Entity class a public method that would allow it to share it with your Panel, and viola!
Hopefully I was clear enough with that response. Doing code out for all that just to explain it to you would be an overhaul. :)

Share this post

Link to post
Share on other sites
Thanks for the reply! I'm a little bit unsure about that for loop though. The way it's set up it would show you one job then ask you for input, then another, and ask you for input and so on. Unless I'm reading it wrong. I assume since you weren't using braces on your for loop that you only meant to loop the displaying code right? If so, that's what I have so far. Ah I see, and then in the second for loop your looping through the array to see if my string matches one of the available classes. That's what I thought as well. However, I would have to then specifically instantiate that class.

If I picked Archer I would have to go:

Player player = new Archer("Adrian");

or for whichever respective class. So how would I do that in the context of that loop? Would I have to make yet another switch statement that says
case Archer:
new Archer();
case Warrior:
new Warrior();

and so on?

As for the graphics yes that does make a lot of sense. However say the Warrior class has these skills inside his [SKILL] button (click [SKILL] and it jumps to a new state with new buttons)


and then the Warrior levels up, allowing him to choose between [BLOOD FRENZY] and [TENDON SLICE] as his skills. His panel would then have a new button added to it. So how would I take care of adding new buttons as they pop up dynamically?

Again thank you so much for your help! I'm going to have a quick snack break and chill out to let my brain relax a bit before going back to coding.

Share this post

Link to post
Share on other sites
epicpunnum    459
A point to clarify, as it may shorten your code, when writing for loops, while loops, or if statements, it is acceptable in Java to not use the curly braces, so long as the content of your loop is only one command or block statement (another if statement or loop). As long as you keep your indentation okay, it should still be understandable by most.

A switch statement would work for that if you wanted to, but you would have to update your code with every new job added. Another thing you would have to do is make your User Input match the strings you compare it to. Due to the ASCII values that chars are assigned, "Archer" != "archer" (which is why I used String.equalsIgnoreCase()). However, you can easily just capitalize/lowercase all of the User Input via String.toUpperCase() or String.toLowerCase().

Another way to work around this, which would require less updating on your part, would be to use the Java Reflection API. If you're not familiar with reflection, it's the practice of referring to your own code on a more abstract level, so that you can create indefinite objects. It can be confusing though, and more difficult to debug if you have to, because all of the reflection processes occur at runtime.

I'm going to avoid going to much into it for the sake of sanity, but it's really useful if you want to try.
INFO/API: [url=""][/url]
Things to find to make things a bit easier:[list]
[*]Class.forName(String name) or Class literals. These give you a Class Object (your starting point)
[*]Constructor.newInstance(Object... args) creates a new object from the Class. args is a list of any arguments, but you'll probably just need a String.
As for the moves, you could do what some party-based games do, and limit the number of skills available. That way, you can simply make the buttons take up a fraction of the available space and leave unused ones blank until they are filled in (think of the battle interface from the earlier Pokemon games). Edited by epicpunnum

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this