<!--QuoteBegin-Quaunaut+Feb 9 2005, 11:31 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Feb 9 2005, 11:31 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->Oh! I remembered my other question.
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--> Never, ever, ever <i>ever</i>, <i>ever</i> use such a command. It violates every rule of good programming practice and in the long run will turn your code to crap.
Seriously. People in programming are always saying "never do this" or "always do this". Normally, there are no hard and fast rules; sometimes you have to break OO, sometimes you have to make a mess. <i>GOTO is the exception!</i>
Just trust me on this and it'll be far less painful in the long run. In your specific case enclose the <span style='font-family:courier'>for</span> inside another loop.
ThansalThe New ScumJoin Date: 2002-08-22Member: 1215Members, Constellation
hehe, I still tihnk it would be more fun to create a single object type that defines all characters (both PC and NPC)
then create a function that handles combat by being passed 2 (or possibly more) characters for combat.
alow a simple alignment tag to decide how characters will react to each other (thus alowing 2 monsters to attack the PC and leave each other alone, or to have the PC be given back up by town guards).
and in your combat function you can simply call a killed function that accepts 2 characters (the killer and the slain) to properly handel rewards <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
oo is fun <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
QuaunautThe longest seven days in history...Join Date: 2003-03-21Member: 14759Members, Constellation, Reinforced - Shadow
edited February 2005
<!--QuoteBegin-Thansal+Feb 10 2005, 07:57 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Thansal @ Feb 10 2005, 07:57 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> hehe, I still tihnk it would be more fun to create a single object type that defines all characters (both PC and NPC)
then create a function that handles combat by being passed 2 (or possibly more) characters for combat.
alow a simple alignment tag to decide how characters will react to each other (thus alowing 2 monsters to attack the PC and leave each other alone, or to have the PC be given back up by town guards).
and in your combat function you can simply call a killed function that accepts 2 characters (the killer and the slain) to properly handel rewards <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
oo is fun <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo--> <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> Actually, thats what I've changed my code to end up doing. Its easier. A *lot* easier.
Edit: So, how do you exactly use that random thing? I (yeah, I know I suck) sadly couldn't figure out how to use them.
Qua, use intellij or eclipse, have it do all the silly tedious things for you <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
QuaunautThe longest seven days in history...Join Date: 2003-03-21Member: 14759Members, Constellation, Reinforced - Shadow
<!--QuoteBegin-Niteowl+Feb 10 2005, 10:11 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Niteowl @ Feb 10 2005, 10:11 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Qua, use intellij or eclipse, have it do all the silly tedious things for you <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo--> <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> www.jcreator.com
Marik_SteeleTo rule in hell...Join Date: 2002-11-20Member: 9466Members
<!--QuoteBegin-Quaunaut+Feb 10 2005, 12:38 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Feb 10 2005, 12:38 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Niteowl+Feb 10 2005, 10:11 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Niteowl @ Feb 10 2005, 10:11 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Qua, use intellij or eclipse, have it do all the silly tedious things for you <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo--> <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> www.jcreator.com
That kind of thing? I also use JBuilder.
I need help.... D: <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> I'm a JCreator-->JCreator Pro-->JBuilder (for a <i>very</i> short time period)-->Eclipse convert. My last computer science teacher tried to switch the whole class over to JGrasp.
For Java coding, I haven't found anything that'll pull me from Eclipse.
<!--QuoteBegin-Thansal+Feb 10 2005, 11:45 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Thansal @ Feb 10 2005, 11:45 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> emacs? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> emacs is great, if you want to spend the 3-6 months ramp up time to be comfortable with it. <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
WARNING :this is not an open invitation for an EMACS vs VI vs VIM vs WHATEVER debate.
<!--QuoteBegin-Snidely+Feb 10 2005, 01:47 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Snidely @ Feb 10 2005, 01:47 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> For random you will need to
import java.util.Random; <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> import java.util.*; will work but rember never do import java.*.*;
ThansalThe New ScumJoin Date: 2002-08-22Member: 1215Members, Constellation
<!--QuoteBegin-Niteowl+Feb 10 2005, 04:13 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Niteowl @ Feb 10 2005, 04:13 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Thansal+Feb 10 2005, 11:45 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Thansal @ Feb 10 2005, 11:45 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> emacs? <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> emacs is great, if you want to spend the 3-6 months ramp up time to be comfortable with it. <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
WARNING :this is not an open invitation for an EMACS vs VI vs VIM vs WHATEVER debate. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> hehe, the CS department at my college had a *nix/emacs night to get all of the new majors (and any one else) ussed to it.
also we have a great settings file that most of the department usses (and with some interesting modifications from various alum and visiting people <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->)
As I am getting tempted to finish teaching myself to program I might grab one of those other editors (yay for college drop outs!)
QuaunautThe longest seven days in history...Join Date: 2003-03-21Member: 14759Members, Constellation, Reinforced - Shadow
<!--QuoteBegin-Niteowl+Feb 10 2005, 12:34 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Niteowl @ Feb 10 2005, 12:34 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> if you are wondering why ppl like eclipse/intellij, it's one word babay.. REFACTORING.
Btw, you should really have accessor methods to your object properties, not accessing them directly
i.e. player.getStrength(), not player.strength. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> Is eclipse free? If so, where may I get it?
Also, why should I be using methods instead of direct access? I was planning on switching to them to add weapon damage and item buffing, but what is your reason?
Marik_SteeleTo rule in hell...Join Date: 2002-11-20Member: 9466Members
edited February 2005
<!--QuoteBegin-Quaunaut+Feb 10 2005, 09:16 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Feb 10 2005, 09:16 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Niteowl+Feb 10 2005, 12:34 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Niteowl @ Feb 10 2005, 12:34 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> if you are wondering why ppl like eclipse/intellij, it's one word babay.. REFACTORING.
Btw, you should really have accessor methods to your object properties, not accessing them directly
i.e. player.getStrength(), not player.strength. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> Is eclipse free? If so, where may I get it?
Also, why should I be using methods instead of direct access? I was planning on switching to them to add weapon damage and item buffing, but what is your reason? <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> It's so free, <a href='http://www.eclipse.org' target='_blank'>its url ends in .org</a> As for why not to use direct access...it gets important when stuff is related to other stuff. Hopefully this analogy will get across; [edit]Scratch this whole thing, I have a simpler, easier to understand one further below.
QuaunautThe longest seven days in history...Join Date: 2003-03-21Member: 14759Members, Constellation, Reinforced - Shadow
Well, my stuff is 100% code, more or less. That seems extra work for no payoff, at least at the moment. Is it more of a "good habit" thing? Also, how would I do that and go about taking away the HP from an attack?
Marik_SteeleTo rule in hell...Join Date: 2002-11-20Member: 9466Members
edited February 2005
<!--QuoteBegin-Quaunaut+Feb 10 2005, 10:54 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Feb 10 2005, 10:54 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Well, my stuff is 100% code, more or less. That seems extra work for no payoff, at least at the moment. Is it more of a "good habit" thing? Also, how would I do that and go about taking away the HP from an attack? <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> Hmm...I'm trying to rethink up a better analogy by going to a previous idea, one without graphics at all.
Let's say you have a class for a car. Doesn't even show the car, just has info about the car. You have a boolean variable for each seat saying whether there's a person there (true) or not (false), and an int for the number of passengers.
Would you rather code <!--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--> myCar.passengerSeat = true; myCar.passengers++; <!--c2--></td></tr></table><div class='postcolor'><!--ec2--> and have to remember the myCar.passengers++; every time you directly set the variable to true, or would you rather code <!--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-->myCar.setPassengerSeat(true);<!--c2--></td></tr></table><div class='postcolor'><!--ec2--> and then have methods like setPassengerSeat(boolean here) remember to always change both the boolean and int for you at the same time, preventing synchronization problems?
For my CSC classes here at NCSU I've been using nedit on the unix machines to code in JAVA since they require us to do everything in a unix environment. Not a big deal though. For assembler I've used DOS's Edit program. In high level languages it's generally considered poor programming to use goto but in Assembler it's the only thing you have.
On your randomizer thing, I know several other people have commented but this is what I use.
<!--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-->int randomInt(Random r, int low, int high) { return low+(int)(r.nextDouble()*(high-low+1); }<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
I use the Random class from the util package and assign it a seed value outside the class since for most of my projects we're supposed to use a specific seed to generate results that we can repeat. You could do something similar for a die roller.
Also I would say since you're working with JAVA which is completely OO, I would suggest that you isolate all your class variables from other classes and instead use accessor methods. Let me give you an example.
instead of using <!--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-->object.value=10<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
I find this makes coding easier for me since I can pull out a class and work on just it and keep all the error checking inside my class to help with data integrity. I'm probably rambling on now but feel free to ask me to clarify any of my points since I'm sure I did a poor job of explaining myself. (It's late and I have a headache and a Data Structures test in the morning)
Let me know when you get to GUIs. They're fun and I have some ways that I've found to make them easy to work with.
Typicially, you will set all the variables in a class to be private just to make sure you cannot change them from outside the class. You then use "getters" and "setters" to change the values indirectly. This seems tedious, but you can use Eclipse's automatic code generation to do this for you, it is actually no extra work for you.
As for setting hp values, you would most likely have a method for each object that can lose HP. You would call this method whenever something loses hp.
By the way, you might want to read up on inheritance and interfaces. At first, it looks like a lot of troubly, but can save you a lot of work later on. For instance, suppose you have several different player and monster types that behave somewhat differently. Obviously, they will share a lot of methods, such as losing/gaining hp, but may vary a lot in other ways, such as how they attack/interact. Without inheritance, you would be forced to code each object seperately (which will cause a lot of trouble when you want to make changes to some of the "shared" methods) or somehow code eerything into one object (which will be very troublesome).
Using inheritance, it is possible to have the differnt objects actually share the same methods. You can also treat them similarly, so you can teat them the same in loops and function calls, which is also nice. This does take a bit of reading (but mostly a lot of thinking and planning), but if plan to make this even a somewhat complex project, it's something you may want to look into.
ThansalThe New ScumJoin Date: 2002-08-22Member: 1215Members, Constellation
for now, the entire get/set command thing is just good form.
generaly you want a class to have defined functions that you can publish. You shouldn't have defined vars that you publish.
later it gets important, though I still realy don't know much about it.
Alot of it has to do with not letting people directly futz with variables for a clas, instead they have to futz with them through the proper chanels.
I think about it like this: Do you wana even be ABLE to give your CPU direct orders in machine language? or do you think it is safer to beable to go through the proper chanels?
<!--QuoteBegin-Quaunaut+Feb 10 2005, 09:16 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Feb 10 2005, 09:16 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Is eclipse free? If so, where may I get it? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> If you're learning java, I'd stick to a text editor. You want to get your hands as dirty as possible, otherwise you might miss something (IMO).
QuaunautThe longest seven days in history...Join Date: 2003-03-21Member: 14759Members, Constellation, Reinforced - Shadow
<!--QuoteBegin-Marik Steele+Feb 10 2005, 09:05 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Marik Steele @ Feb 10 2005, 09:05 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Quaunaut+Feb 10 2005, 10:54 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Quaunaut @ Feb 10 2005, 10:54 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Well, my stuff is 100% code, more or less. That seems extra work for no payoff, at least at the moment. Is it more of a "good habit" thing? Also, how would I do that and go about taking away the HP from an attack? <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd--> Hmm...I'm trying to rethink up a better analogy by going to a previous idea, one without graphics at all.
Let's say you have a class for a car. Doesn't even show the car, just has info about the car. You have a boolean variable for each seat saying whether there's a person there (true) or not (false), and an int for the number of passengers.
Would you rather code <!--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--> myCar.passengerSeat = true; myCar.passengers++; <!--c2--></td></tr></table><div class='postcolor'><!--ec2--> and have to remember the myCar.passengers++; every time you directly set the variable to true, or would you rather code <!--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-->myCar.setPassengerSeat(true);<!--c2--></td></tr></table><div class='postcolor'><!--ec2--> and then have methods like setPassengerSeat(boolean here) remember to always change both the boolean and int for you at the same time, preventing synchronization problems? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd--> Or I could just use overload constructors, which are much easier than using a method to set every little thing.
I was taught that using private variables in subclasses is good practice. Get methods are more useful in inheritance, IIRC, although like Marik says, they help to avoid consistency boo-boos. For example, if certain monsters have special attributes, it's easier to have overriden methods for them rather than have code checking each case.
Comments
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-->
Never, ever, ever <i>ever</i>, <i>ever</i> use such a command. It violates every rule of good programming practice and in the long run will turn your code to crap.
Seriously. People in programming are always saying "never do this" or "always do this". Normally, there are no hard and fast rules; sometimes you have to break OO, sometimes you have to make a mess. <i>GOTO is the exception!</i>
Just trust me on this and it'll be far less painful in the long run. In your specific case enclose the <span style='font-family:courier'>for</span> inside another loop.
then create a function that handles combat by being passed 2 (or possibly more) characters for combat.
alow a simple alignment tag to decide how characters will react to each other (thus alowing 2 monsters to attack the PC and leave each other alone, or to have the PC be given back up by town guards).
weeee <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
so many fun tihngs to do.
and in your combat function you can simply call a killed function that accepts 2 characters (the killer and the slain) to properly handel rewards <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
oo is fun <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
then create a function that handles combat by being passed 2 (or possibly more) characters for combat.
alow a simple alignment tag to decide how characters will react to each other (thus alowing 2 monsters to attack the PC and leave each other alone, or to have the PC be given back up by town guards).
weeee <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
so many fun tihngs to do.
and in your combat function you can simply call a killed function that accepts 2 characters (the killer and the slain) to properly handel rewards <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
oo is fun <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo--> <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
Actually, thats what I've changed my code to end up doing. Its easier. A *lot* easier.
Edit: So, how do you exactly use that random thing? I (yeah, I know I suck) sadly couldn't figure out how to use them.
<!--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-->
that will create a new object of type random and name it r
then it will create a new int (named randomInt) and give it a random value between 0 (inclusive)and n (exclusive).
If you want to make it between 1 and n (inclusive on both sides you simply add one to it)
so if you wanted to roll a d6 you would use r.nextInt(6) + 1
Do I have to insert the entire thing the java API had, *then* do that?
as I havn't done any code in a year or so...
did you load up java.util? (or is it one of the auto loaded ones?)
www.jcreator.com
That kind of thing? I also use JBuilder.
I need help.... D:
www.jcreator.com
That kind of thing? I also use JBuilder.
I need help.... D: <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
I'm a JCreator-->JCreator Pro-->JBuilder (for a <i>very</i> short time period)-->Eclipse convert. My last computer science teacher tried to switch the whole class over to JGrasp.
For Java coding, I haven't found anything that'll pull me from Eclipse.
import java.util.Random;
Btw, you should really have accessor methods to your object properties, not accessing them directly
i.e. player.getStrength(), not player.strength.
emacs is great, if you want to spend the 3-6 months ramp up time to be comfortable with it. <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
WARNING :this is not an open invitation for an EMACS vs VI vs VIM vs WHATEVER debate.
import java.util.Random; <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
import java.util.*;
will work but rember never do
import java.*.*;
emacs is great, if you want to spend the 3-6 months ramp up time to be comfortable with it. <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
WARNING :this is not an open invitation for an EMACS vs VI vs VIM vs WHATEVER debate. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
hehe, the CS department at my college had a *nix/emacs night to get all of the new majors (and any one else) ussed to it.
also we have a great settings file that most of the department usses (and with some interesting modifications from various alum and visiting people <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->)
As I am getting tempted to finish teaching myself to program I might grab one of those other editors (yay for college drop outs!)
Btw, you should really have accessor methods to your object properties, not accessing them directly
i.e. player.getStrength(), not player.strength. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
Is eclipse free? If so, where may I get it?
Also, why should I be using methods instead of direct access? I was planning on switching to them to add weapon damage and item buffing, but what is your reason?
Btw, you should really have accessor methods to your object properties, not accessing them directly
i.e. player.getStrength(), not player.strength. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
Is eclipse free? If so, where may I get it?
Also, why should I be using methods instead of direct access? I was planning on switching to them to add weapon damage and item buffing, but what is your reason? <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
It's so free, <a href='http://www.eclipse.org' target='_blank'>its url ends in .org</a>
As for why not to use direct access...it gets important when stuff is related to other stuff. Hopefully this analogy will get across;
[edit]Scratch this whole thing, I have a simpler, easier to understand one further below.
Hmm...I'm trying to rethink up a better analogy by going to a previous idea, one without graphics at all.
Let's say you have a class for a car. Doesn't even show the car, just has info about the car. You have a boolean variable for each seat saying whether there's a person there (true) or not (false), and an int for the number of passengers.
Would you rather code
<!--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-->
myCar.passengerSeat = true;
myCar.passengers++;
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
and have to remember the myCar.passengers++; every time you directly set the variable to true, or would you rather code
<!--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-->myCar.setPassengerSeat(true);<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
and then have methods like setPassengerSeat(boolean here) remember to always change both the boolean and int for you at the same time, preventing synchronization problems?
On your randomizer thing, I know several other people have commented but this is what I use.
<!--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-->int randomInt(Random r, int low, int high)
{
return low+(int)(r.nextDouble()*(high-low+1);
}<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
I use the Random class from the util package and assign it a seed value outside the class since for most of my projects we're supposed to use a specific seed to generate results that we can repeat. You could do something similar for a die roller.
Also I would say since you're working with JAVA which is completely OO, I would suggest that you isolate all your class variables from other classes and instead use accessor methods. Let me give you an example.
instead of using
<!--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-->object.value=10<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
code something like
<!--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-->object.setValue(10)
variable = object.getValue()<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
I find this makes coding easier for me since I can pull out a class and work on just it and keep all the error checking inside my class to help with data integrity. I'm probably rambling on now but feel free to ask me to clarify any of my points since I'm sure I did a poor job of explaining myself. (It's late and I have a headache and a Data Structures test in the morning)
Let me know when you get to GUIs. They're fun and I have some ways that I've found to make them easy to work with.
As for setting hp values, you would most likely have a method for each object that can lose HP. You would call this method whenever something loses hp.
By the way, you might want to read up on inheritance and interfaces. At first, it looks like a lot of troubly, but can save you a lot of work later on. For instance, suppose you have several different player and monster types that behave somewhat differently. Obviously, they will share a lot of methods, such as losing/gaining hp, but may vary a lot in other ways, such as how they attack/interact. Without inheritance, you would be forced to code each object seperately (which will cause a lot of trouble when you want to make changes to some of the "shared" methods) or somehow code eerything into one object (which will be very troublesome).
Using inheritance, it is possible to have the differnt objects actually share the same methods. You can also treat them similarly, so you can teat them the same in loops and function calls, which is also nice. This does take a bit of reading (but mostly a lot of thinking and planning), but if plan to make this even a somewhat complex project, it's something you may want to look into.
generaly you want a class to have defined functions that you can publish. You shouldn't have defined vars that you publish.
later it gets important, though I still realy don't know much about it.
Alot of it has to do with not letting people directly futz with variables for a clas, instead they have to futz with them through the proper chanels.
I think about it like this:
Do you wana even be ABLE to give your CPU direct orders in machine language?
or do you think it is safer to beable to go through the proper chanels?
If you're learning java, I'd stick to a text editor. You want to get your hands as dirty as possible, otherwise you might miss something (IMO).
Hmm...I'm trying to rethink up a better analogy by going to a previous idea, one without graphics at all.
Let's say you have a class for a car. Doesn't even show the car, just has info about the car. You have a boolean variable for each seat saying whether there's a person there (true) or not (false), and an int for the number of passengers.
Would you rather code
<!--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-->
myCar.passengerSeat = true;
myCar.passengers++;
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
and have to remember the myCar.passengers++; every time you directly set the variable to true, or would you rather code
<!--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-->myCar.setPassengerSeat(true);<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
and then have methods like setPassengerSeat(boolean here) remember to always change both the boolean and int for you at the same time, preventing synchronization problems? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
Or I could just use overload constructors, which are much easier than using a method to set every little thing.
You're bad at analogies, Marik <3