Results 1 to 4 of 4
  1. #1
    nielscorn is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Question [HELP]Trying to make a decision cmd adventure! How to branch decisions?

    Hello!

    This is my first post!
    I'm learning java atm(not that good yet, just really new beginner!) and try to experiment with everything i learn as i go!
    So i thought it might be fun to make a little command prompt adventure game like in the adventure books, where you can decide the fate of your character by making decisions.
    I'm really at the beginning but still encountered a problem... i have no idea how to make efficient or even working branches of my decision, i'll explain:

    Decision 1:
    1a: route A
    1b: route B
    1c: route C

    I have no idea how to effectively branch them so i can continue on with the decision the player makes first, this keeps going exponantially so there must be something out there right?
    so decision 1 = 3 options! Fine no problem! i just use a switch statement! Seems good! but wait... now how will i let them continue on 1 path?

    tl;dr: Want to make little adventure text game with choices, can't seem to branch off and continue on that branch the player choses...
    How to let the program know it should continue with the choice then output text after the option has been displayed specific for that branch?
    NOTE: I use 2 classes because i was learning about using multiple classes and it seemed like a nice way to get the hang of it like this. Might not be needed but if i could i'd prefer to keep the multiple classes.

    I hope the code explains it better than me!


    Code AdventureGame mainclass:
    Java Code:
    import java.util.Scanner;
    
    public class AdventureGame {
    
    	public static void main (String[] args){
    		Scanner so = new Scanner (System.in);
    	AdventureGameChoises adventureObject = new AdventureGameChoises();
    		
    		System.out.println("Welcome to this Command prompt adventure game!" +
    				"Your choices will determine the path of your hero!");
    		System.out.println("What race are you?");
    		String race = so.next();
    		System.out.println("What sex are you? Man or Female?");
    		String sex = so.next();
    		System.out.println("How old are you?");
    		int age = so.nextInt();
    		System.out.printf("Background:\nYou are a %s of %d years old" +
    				" and you're of the proud %s race!\n", sex, age, race);
    		System.out.println("Your adventure starts! You wake up from" +
    				" a dusty cell...\nYou look around but.. wait.. " +
    				"OH NOEZ!!111!!EINZ!1 YOU ARE TRAPPED!!");
    		adventureObject.decision1();
    		// here i would like to continue with the decision 1/2 or 3 made in the other class, 
                    // make it show little text of what happens(according to the choice he made) and then present 3 more options in the other classe
    	}
    }
    Code AdventureGameChoices:
    Java Code:
    import java.util.Scanner;
    
    public class AdventureGameChoises {
    	public void decision1(){
    		Scanner sal = new Scanner (System.in);
    		
    		System.out.println("What will you do?\n1: Try to call for help.\n" +
    				"2: Try and look for a way out.\n3: Think about life, waiting to be rescued");
    		
    		int Decision1 = sal.nextInt();
    		
    		switch (Decision1){
    		case 1: 
    			System.out.println("You try to call for help! You hear something approaching.");
    			break;
    		case 2:
    			System.out.println("You look around... Your cell is very small!" +
    					"\nYou try touching some stones, one seems loose!");
    			break;
    		case 3:
    			System.out.println("You wait... is this a good idea, you ask yourself.");
    			break;
    		default:
    			System.out.println("You trip over a stone in your cell...\nYou fall in a coma!" +
    					" YOU STUPID? You only had 3 options!!!");
    			break;
    		}	
    	}
    }
    EDIT: something just popped in, i still don't know the answer but i'm pretty sure i'll have to use a different thing than 'void' in my gameadventurechoises class right? otherwise it can't send any info back? what should i use?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,418
    Rep Power
    25

    Default Re: [HELP]Trying to make a decision cmd adventure! How to branch decisions?

    Do you have a design for what you are trying to write? Can you make a list of steps or pseudo code that describes what you want your program to do?
    It looks like you are writing code before you have a design for what the code is supposed to do.

  3. #3
    nielscorn is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: [HELP]Trying to make a decision cmd adventure! How to branch decisions?

    Do you have a design for what you are trying to write? Can you make a list of steps or pseudo code that describes what you want your program to do?
    It looks like you are writing code before you have a design for what the code is supposed to do.
    Well it's just a learning program, everything i learn i'll try to incoorporate, it's not a full fledged game i'm trying to make ^^!
    But to answer to your question, no, i do not have pseudocode for the rest of my program, considering i just don't know how to overcome my first obstacle(how to get a decision answer and continue on that path)


    I wanted to create a little interactive story, where the user can only chose one of 3 options when a decision has to be made to continue the story.
    Now i've had the problem that i don't know how to get that choice(choice 1a, 1b or 1c and THEN continue on THAT choice)
    for example:
    He choses choice 1a, a corresponding story flows further from that decision( the story will be different if someone is approaching or if he finds a loose stone and breaks out that way)

    so in pseudo code i was thinking in terms like
    if user choses choice 1a
    print text of story continueing from that choice
    give 3 more choices

    and then it repeats itself i guess untill it's over.

    I hope i cleared it up a bit.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,418
    Rep Power
    25

    Default Re: [HELP]Trying to make a decision cmd adventure! How to branch decisions?

    You could use a loop for the "repeats itself" part.

Similar Threads

  1. Newton Adventure
    By java software in forum Java Software
    Replies: 0
    Last Post: 12-29-2011, 05:46 PM
  2. Decisions.
    By whateverme in forum New To Java
    Replies: 2
    Last Post: 11-20-2010, 01:52 AM
  3. Text adventure setup
    By xsimsyx in forum New To Java
    Replies: 8
    Last Post: 03-16-2010, 11:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •