Campbell Ritchie wrote:Welcome to the Ranch
I see Mohammed has added code tags, and you can see how much better your post now looks.
You are correct to use two classes; in fact you will require many classes. Use of choices, however is a very high-level subject, using “linear logic”; there are a whole officeful of people just up the corridor from me who are researching such choices. So you need to start small. if yo0u write more than about 5 lines of code, you must compile and run that code and see what happens. If you try writing any more than that, you can accumulate errors and find it difficult to understand the errors.
You need to think object-oriented. I think your Adventure class needs Choice fields, or Decision fields. There are various tools you can use, for example an enum like this one:You are right that you can use a switch block; you can in fact use enum elements for the cases (or in Java7, Strings). But I think it would be more object-oriented to have Location objects, which you get to by following directions. Each Location object can have a number of possible Choices.
Now you see, we have already got about a half-dozen classes. You need to design the classes, and what the options, hazards and benefits of different choices in those locations are. And build them little bit by little bit. This is by no means an easy task for a beginner.
It is also worth finding about Tree and Graph structures; Graphs have nodes and edges, which can be modelled with Locations and Moves. Also find out about Maps; you can apply an option to a Map and get a Result back. The concept of a Graph, which your paths through the game cross, is the general design. The combinations of choices and results in each location represent data which can be added. The actual chape of the Graph is also a sort of data.
I was obviously mistaken about Mohammed’s edit. Very sorry.
niels corn wrote: . . . i thought i putted the code tags? . . .
niels corn wrote:As you can see i'm very new to java but eager to learn. I'm a little annoyed that such a 'simple' program involves difficult programming...
It’s not such a simple task. Actually it is not the programming which is difficult, but the logic behind it.
niels corn wrote: . . . I'm a little annoyed that such a 'simple' program involves difficult programming...
Thank you for replying!
niels corn wrote:I will let this sit a bit on the side then, it seems i'm not ready for encursion and such AT ALL!
Thank you and cheers!
Campbell Ritchie wrote:Are you sure he means recursion? I didn’t think that sort of game required a recursive solution.
niels corn wrote:Now i have a problem, basicly the biggest annoyances are gone, this is how i wish to continue(i just have to repeat all the code basicly :p)...
Campbell Ritchie wrote:But I think the whole thing still looks like procedural programming to me. You don’t have decision objects leading to results requiring other decisions...