Java Help!
Quaunaut
The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
in Off-Topic
<div class="IPBDescription">D:</div> I'm learning to code java, and I'm doing well, but there are a few things I've been wondering:
How do I create a random number, and after that, put paramaters on it(like 1-100, 1-10, all that).
I'll have more questions later, but this is the most pressing.
How do I create a random number, and after that, put paramaters on it(like 1-100, 1-10, all that).
I'll have more questions later, but this is the most pressing.
Comments
RandomIntGenerator( <lowestnumber> , <highestnumber> )
the numbers CAN be negative
{
//stuff between 0 and 10
}
I think, I'm still a Java nublet myself
IIRC, RPG Jssmfulhud answer wins.
edit: oh ignore me, what do I know, Marik's is obviously correct
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
Random r = new Random();
int randomInt = r.nextInt();
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
int randomInt = r.nextInt();<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
And you should know that if your plaining on taking the AP cs test.
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Random r = new Random();
int randomInt = r.nextInt(n);<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
for a random number between 0 and n-1
or
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->Random r = new Random();
int randomInt = r.nextInt(n) + 1;<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
for a random number between 1 and n
int randomInt = r.nextInt();<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
And you should know that if your plaining on taking the AP cs test. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
Thats next year! This year is just wierd...stuff. Yeah. Hard to explain.
Thanks folks for this. I'm wanting to make my own little mini text RPG as a way of showing how even in basic programming, that unique game designs can come out(being all my friends are like "You must remake a classic like Pac Man or pong!")
<3
Edit: And I *hate* the Java API. It doesn't show you anything, doesn't explain anything in terms that anyone can understand- its like a reference for people who've already memorized all of java's commands! <!--emo&:(--><img src='http://www.unknownworlds.com/forums/html/emoticons/sad-fix.gif' border='0' style='vertical-align:middle' alt='sad-fix.gif' /><!--endemo-->
Edit: And I *hate* the Java API. It doesn't show you anything, doesn't explain anything in terms that anyone can understand- its like a reference for people who've already memorized all of java's commands! <!--emo&:(--><img src='http://www.unknownworlds.com/forums/html/emoticons/sad-fix.gif' border='0' style='vertical-align:middle' alt='sad-fix.gif' /><!--endemo--> <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
To quote George Orwell, "The best books are the ones that tell you what you already know." <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
True, finding out specifics about stuff requires that you have between a general and good idea of what you're looking for...but when you do, the API helps. For instance, it's very common to forget whether nextInt(6) will generate numbers from 0 to 6, 1 to 6, 0 to 5, 1 to 5....the api lets you know exactly.
Well, I actually want it to be rather simple. First I wanna dev my own battle system and a level up system. From there, I'll construct a first mini-story so that I can construct a stats based interaction system, similar to that in Deus Ex, or Bloodlines(being its text based, it should be merely a matter of creating the choice when a certain stat is reached).
I know it'll be lots of work, but it'll help me learn! <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html/emoticons/biggrin-fix.gif' border='0' style='vertical-align:middle' alt='biggrin-fix.gif' /><!--endemo-->
<a href='http://java.sun.com/docs/books/tutorial/' target='_blank'>Excellent resource, every link <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo--></a>
*waves to qua*
hullo you voicespamming monkey you!
Qbasic is a terrible language for writing text RPG's though, the things get whipped off like no time in an object oriented language. The sequential line number hopping system of Qbasic is just not condusive to statistics storage or randomly generated events, and if you try to actually include a story, good luck because you are screwed.
[edit] this whole topic makes me want to relearn visual C++ and start coding out some of my text RPG ideas...
Qbasic is a terrible language for writing text RPG's though, the things get whipped off like no time in an object oriented language. The sequential line number hopping system of Qbasic is just not condusive to statistics storage or randomly generated events, and if you try to actually include a story, good luck because you are screwed.
[edit] this whole topic makes me want to relearn visual C++ and start coding out some of my text RPG ideas... <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
Oh, it worked fine. It just went through several design iterations, took on mass, and eventually grew into a kind of single player MUD complete with a custom scripting language. A hell of a lot of fun to write, it just never got finished before I decided I'd better hurry up and move on to C.
See, my instructor is teaching us things according to a book, and when it comes down to it, he's barely 3 days ahead of us. Heh. But I was wondering, what command could make me go to whatever line I tell it to? A'la the "Goto" command(if I am thinking of it correctly). Thanks <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html/emoticons/biggrin-fix.gif' border='0' style='vertical-align:middle' alt='biggrin-fix.gif' /><!--endemo-->
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->import javax.swing.JOptionPane;
class player {
static int strength;
static int dexterity;
static int agility;
static int intelligence;
static int wisdom;
static int charisma;
static int hp;
static int mp;
static String name;
}
class monster {
}
class rpg {
public static void main(String args[]) {
String Choicepoints;
player.name = JOptionPane.showInputDialog("What is your character's name?");
System.out.println("Player name is "+player.name);
player.strength = 0;
player.dexterity=0;
player.agility=0;
player.intelligence=0;
player.wisdom=0;
player.charisma=0;
int x = RandomIntGenerator(1,10);
System.out.println(x);
for(int choicepoints=30;choicepoints>0;choicepoints--){
String Choices;
int choices;
Choices = JOptionPane.showInputDialog("Choose what to put your attribute points into?"+
"\n 1. Strength : "+player.strength+
"\n 2. Dexterity : "+player.dexterity+
"\n 3. Agility : "+player.agility+
"\n 4. Intelligence : "+player.intelligence+
"\n 5. Wisdom : "+player.wisdom+
"\n 6. Charisma : "+player.charisma+
"\n Choose by number. You have "+choicepoints+" points left to put into attributes."+
"\n Just remember to put at least a few points into everything, or you may find your character...limited.");
choices = Integer.parseInt(Choices);
if(choices==1)player.strength++;
if(choices==2)player.dexterity++;
if(choices==3)player.agility++;
if(choices==4)player.intelligence++;
if(choices==5)player.wisdom++;
if(choices==6)player.charisma++;
}
player.hp=(player.strength*5)+20;
player.mp=(player.intelligence*5)+10;
System.out.println(player.name+"'s Character Sheet:");
System.out.println();
System.out.println("Health: "+player.hp);
System.out.println("Mana: "+player.mp);
System.out.println();
System.out.println("Strength: "+player.strength);
System.out.println("Dexterity: "+player.dexterity);
System.out.println("Agility: "+player.agility);
System.out.println("Intelligence: "+player.intelligence);
System.out.println("Wisdom: "+player.wisdom);
System.out.println("Charisma: "+player.charisma);
for(;player.hp=0;;) {
//the battle system
if(monster.hp=0)[B]Goto command goes here. It'll go to the line above this very for loop.[/B]
}<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
Yeah, at that ending part. And yes, I realize that my current thing of this RPG is pretty basic- I'm still working on learning how to manipulate the JOptionPane stuff, as well as frame modifiers.
Also, being I haven't been able to use it yet until now, I can't seem to figure out how to get the random thing to work. Could someone show me it in a working context?
just make an operation (aka monsterDed) that gets called when monster.hp = 0
forinstance you could have an action that accepts a monster type object for its argument.
so you call monsterDed(*insert monster you are playing with atm here*) and it will pull out how much xp, what loot etc etc should be added to your character <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
and you can ofcourse create a class that handels all combat by simply passing it a playerChar object and a monster object.
hehe, I havn't messed around with Java in a whiel, but I still like it (I also definatly recomend that you get ussed to ussing the API as you will often find a simple way to do omething you have been doing the long way all along)
I had a project where I had to encode a number. We were suposed to use for loops, I found a piece in the API that let me simply set a deffenition for what each number should be changed into <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo--> (oh, yah the grader told me not do do it b/c we were technicaly suposed to be doing for loops, so I left it in my code commented out <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->)
You hate Java, don't you?
You hate Java, don't you? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
Nah, he makes comments like that in the Super Secret forums whenever we start talking about Linux or other coding-related stuff, too <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
pshaw (please ignore the fact that I was gona get a psyche major)
See, my instructor is teaching us things according to a book, and when it comes down to it, he's barely 3 days ahead of us. Heh. But I was wondering, what command could make me go to whatever line I tell it to? A'la the "Goto" command(if I am thinking of it correctly). Thanks <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html/emoticons/biggrin-fix.gif' border='0' style='vertical-align:middle' alt='biggrin-fix.gif' /><!--endemo--> <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
I don't know really any java, but I was under the impression that it handled this alot like C++... basicly there is no goto command, what you would do with goto loops in QB is done massively more efficiantly with loop commands, function calls, and multiple objects. If you need to back track your story in the game it should be built as multiple objects so that you can call them at any point in time from any point in the game. and levels and statistics should not under any circumstance be stored anywhere but in objects or callable functions.
[edit]oh, and Soulscorpion, I wasn't saying that Qbasic isn't capable of building text RPG's, I have a few partially finished ones in it myself. I was just saying that Qbasic is much messier and no where near as efficiant for building them as any of the object oriented languages are.
Actually, psychology is, like my own media sciences, a social, not a humanistic science. We're bound to empirical data, they're not <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
But yeah, whenever people start talking about advanced technicals, part of my brain just shuts down.
Your name is oddly fitting