Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
Thread: problem with a code.
01-07-2014, 10:22 PM #1
- Join Date
- Dec 2013
- Thanked 0 Times in 0 Posts
problem with a code.
I'm attempting to to make a "chose your way" type of game, but I have 2 problems. At the beginning you get a choice of 3 options, and from one of those beginning choices, you get another option. And the way I wrote it, java can't tell which option you pick the beginning or the one after. Please help. Anyway here's the code:
public class test4
public static void main(String args)
Scanner in =new Scanner(System.in);
System.out.println("you are a knight of the kingdom of air, and your on a mission to save the princess, and deliver her to one of the three kingdoms.");
System.out.println("the kingdom of ice, the kingdom of fire, or the kingdom of earth.");
System.out.println("to get the princess, there are three routes to take from the kingdom to her.");
System.out.println("path 1, is to go up through the mountian, path 2, is to go through the vally, and path 3 is to go through the forest");
System.out.println("So... which way? only use the number of your pick.");
if (a == 1)
System.out.println("you start to run toward the mountian, and to climb to it's height but you hit a fork in the road.");
System.out.println("path 1 is to go to the high ground, and path 2 is to start going down mountianpick your way...");
if ( A== 1)
System.out.println("You keep walking up the path, heighier and heighier. But then you slip and fall, all the way down the mountian to your death. Please try agian");
if (A == 2);
System.out.println("you follow the path, going down the mountian, and at the bottom of the mountian you run into the troll, who kiddnapped the princess.");
else if (a == 2)
System.out.println("You start to run through the vally, running through tall grass, and tree. But then a river forms, and path splits and now theres two way to go around.");
System.out.println("Path 1 is to the left, and path 2 is to the right. Pick your way...");
if (B == 1)
System.out.println("As you run through the marsh. you get bit by a water snake and die. Please try agian");
if (B == 2)
System.out.println("You run through the marsh and at the end of the path, you run into the troll that kiddnapped the princess.");
System.out.println("You start to run toward the forest, in the forest a dead tree has fallen over and cleared another path.");
System.out.println("Path 1 is the freshly made path from the tree, or you can keep following path 2");
if (C == 1)
System.out.println("As you run through the new path it leads you directly into a cave. As you enter that cave you get attacked by a pack of wolfs and die. Please try agian");
if (C == 2)
System.out.println("You follow the path till your out of the forest and waiting there is the troll that kiddnapped the princess.");
Last edited by VIPStephan; 01-07-2014 at 10:40 PM. Reason: added code BB tags
01-07-2014, 10:36 PM #2
- Join Date
- Jun 2002
- London, England
- Thanked 2,555 Times in 2,533 Posts
BTW, when posting here please help us to help you by making it easier to view, copy, modify, test and debug your scripts by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
01-07-2014, 10:45 PM #3
- Join Date
- Jan 2006
- Halle (Saale), Germany
- Thanked 1,035 Times in 1,008 Posts
01-07-2014, 11:14 PM #4
your first choice is 'a' (the one that is not getting 'remembered' ... I see no reason why it would not retain the value of 'a'... but I also do not see you calling 'a' anywhere- how do you know it is not retaining the value?
01-08-2014, 12:41 AM #5
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
There's no need for most of these variables. All you need to know is the first and second chosen values since you only go two steps in depth.
For this reason, you don't even need the two variables. Instead, simply use a switch:
Of course, this handles nothing for errors, but I'd ignore that for now.PHP Code:
System.out.println("Some text here");
System.out.println("Result of 1, 1");
System.out.println("Result of 1, 2");
case 2: //. . .
I'd suggest splitting some separate methods out for these.
As your skills improve in the language, even with a cli interface using collections of collections you'll be able to embed infinite depth.
Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');
Users who have thanked Fou-Lu for this post: