Toribash
Sub wins. Hands down. However, if you are with someone who is incapable of reading subs and paying attention to the show... -.-,
use Random class, set an integer range
Random ran = new Random(); #generate random object
int x = ran.nextInt(101) #sets x to a random integer between 0 & 100(doesn't reach max)
if (a==1) {
if (x<=30) {
results of 40 damage being done;
}
}

this should work, because chances are equal that it will be anywhere from 0 to 100. 30% chance it will be less than or equal to 30. make sense?
this is actually a fairly short version. you could use a float and 0.10f, or a short if you want, to make it use negligibly less memory. but this sort of thing is probably the best solution. make a big bowl of copypasta, man
using one of these wouldn't actually make it any shorter, just slightly more efficient. Anyone else have a better way?

edit: derpy moment, just make a method for the percentage. why didn't i think of that before? drugs.
private Random ran = new Random(); #generate random object

public boolean percentmethod (int desiredchance) {
int x = ran.nextInt(101) #sets x to a random integer between 0 & 100(doesn't reach max)
if (a==1) {
if (x<=desiredchance) {
return true;
}
}
execute whatever you want in your main program, using the result to decide by calling percentmethod(20) for a 20% chance of returning true. etc. does that help?
Last edited by rcarey; Sep 27, 2012 at 10:05 PM.
Yes, Jbuttons have a text field that you can set, and a buttonlistener would do what you are looking for. When initiating the JButton, add text.
JButton mybutton = new JButton("your text");
or you can use the inherited setText(). Also, the Actionlistener is probably going to be the same since you only want to return a boolean, with the same sort of action performed each time, you can probably write a listener once and then add it to all the buttons you make. In order to help you more, i would have to see the code. I'm good, but not that good also, just saying, not a member of this org yet.
Also, with the addition of said buttons, this game graduates from fully text-based to somewhat graphical. Congrats ;P
Ok well make your methods public so you can access them from another .java file if you need to.
the settext thing: mybutton.setText("your text"); will set it. this works by inheriting the setText method common to a lot of javax.swing components, of which JButton is one.
To help you implement the actionlistener ("listens" to catch a click event on the button, and then executes specified code when it is clicked), i need to see what you have so I know what variables can be used. Probably what you want to do is create your own listener class that implements ActionListener (this allows it to inherit it's function) and specify what you want done when it is clicked. If you are going to fully implement the buttons, you might need some help. It might be a little tough to do with 3 weeks of java, as you don't really understand inheritance or encapsulation yet for that matter. Again, happy to assist you bro. 3rd year computer science student here ;p
Email is godliness10@gmail.com
-----
As a side note, when comparing strings use .equals
sometimes the boolean comparison can cause problems, by referring to the exact object ( in memory) rather than the string's value
mystring.equals("y"); #returns a boolean


for various reasons, though, i would suggest using a boolean if you are going to have it driven by buttons as opposed to text. it's silly to have it create a string when the input is just click or no click boolean makes more sense...and takes up a ridiculously small amount of memory.
Last edited by rcarey; Sep 28, 2012 at 07:55 AM. Reason: <24 hour edit/bump
Hyoudo Issei : "I will be Devil Harem!"
Akihisa Yoshii : "Tu Ne Voundaris pas Devenir Mon Amie?"
Yuuji Sakamoto : "The Baka-man is cooler than you!"
Fumino Serizawa : "Ni kai Shine!"
Lol
Selling something? Need some toricredits? Click this quickly.
Main rival of ToriBot since 20&&
- made in Indonesia

The warrior guided by the spirit serves humanity, the warrior without, serves the ego.
"apapapa" Apachai Hopachai The Shinigami of Muay thai
"0h no" -Trice
A.K.A Tricerafi || Thanks Papa Donut, bless you
Another is Suprised me..
Selling something? Need some toricredits? Click this quickly.
Main rival of ToriBot since 20&&
- made in Indonesia

The warrior guided by the spirit serves humanity, the warrior without, serves the ego.
Never played a good anime game. But anime style games like touhou or recettear are great. Games based on anime are generally about money rather than good gameplay.

Some of the DBZ are ok.


I want to play Amagami some time.

I usually play naruto
Bleach
Dragon Ball
but not are games that I consider very good