Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualepicpunnum

Posted 27 October 2012 - 08:23 AM

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: http://docs.oracle.c...lect/index.html
Things to find to make things a bit easier:
  • 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).

#1epicpunnum

Posted 26 October 2012 - 11:52 PM

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: http://docs.oracle.com/javase/tutorial/reflect/index.html
Things to find to make things a bit easier:
  • 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).

PARTNERS