Need help with text adventure game

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

79 Replies - 4676 Views - Last Post: 25 September 2016 - 02:51 PM Rate Topic: -----

Poll: Title of my rpg (3 member(s) have cast votes)

What should the title of my rpg be? (Scary/Mystery Genre)

  1. The Room (0 votes [0.00%])

    Percentage of vote: 0.00%

  2. Deserted (2 votes [66.67%])

    Percentage of vote: 66.67%

  3. Dont care as long as its a cool game (1 votes [33.33%])

    Percentage of vote: 33.33%

Vote Guests cannot vote

#16 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 02:18 PM

View PostNormR, on 23 September 2016 - 03:07 PM, said:

Quote

how to check the users input

Mostly that is done with if statements that compare the user's input against valid values.

Quote

make it loop back

The code inside of the while loop will loop back as long as the variable: badInput is true.
Setting badInput to false will allow the execution to exit the while loop.


so what would be a correct way to say if the choice does not equal. Like normally the if statement would be if(choice.equals("bababa")) but what if I wanted it to not equal that. That way I could make it so if it does not equal that then system...("Input invalid") and end while loop?
Was This Post Helpful? 0
  • +
  • -

#17 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Need help with text adventure game

Posted 23 September 2016 - 02:20 PM

Quote

way to say if the choice does not equal

Use the ! (NOT) operator: !x.equals(y)

This post has been edited by NormR: 23 September 2016 - 02:21 PM

Was This Post Helpful? 0
  • +
  • -

#18 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 02:30 PM

View PostNormR, on 23 September 2016 - 03:20 PM, said:

Quote

way to say if the choice does not equal

Use the ! (NOT) operator: !x.equals(y)



OKAY THANK YOU SO MUCH! So i did some messing around and ending up with this

boolean badInput = true;
        while(badInput) {
        	if(!choice.equals("SCREAM"))
            System.out.println("Not a valid command");
        	choice = scan.nextLine();
        if(choice.equals("SCREAM")){ 

            place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

            System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

            choice = scan.nextLine(); 
        }
       } 


which then if I type somthing thats not a choice prints not a valid command.
Now if I want to make more than one choice available so if the choice is SCREAM the user can either type SCREAM, scream, Scream. How would I do that? I tried this if(!choice.equals("SCREAM" || "Scream")) but it does not work.
Was This Post Helpful? 0
  • +
  • -

#19 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 02:37 PM

View PostToshritzy, on 23 September 2016 - 03:30 PM, said:

View PostNormR, on 23 September 2016 - 03:20 PM, said:

Quote

way to say if the choice does not equal

Use the ! (NOT) operator: !x.equals(y)



OKAY THANK YOU SO MUCH! So i did some messing around and ending up with this

boolean badInput = true;
        while(badInput) {
        	if(!choice.equals("SCREAM"))
            System.out.println("Not a valid command");
        	choice = scan.nextLine();
        if(choice.equals("SCREAM")){ 

            place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

            System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

            choice = scan.nextLine(); 
        }
       } 


which then if I type somthing thats not a choice prints not a valid command.
Now if I want to make more than one choice available so if the choice is SCREAM the user can either type SCREAM, scream, Scream. How would I do that? I tried this if(!choice.equals("SCREAM" || "Scream")) but it does not work.



Actually I got the same result by using multiple if statements however is there any easier ways to do this?
Was This Post Helpful? 0
  • +
  • -

#20 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Need help with text adventure game

Posted 23 September 2016 - 02:38 PM

Quote

if the choice is SCREAM the user can either type SCREAM, scream, Scream. How would I do that?

Read the API doc for the String class. It has a method to compare Strings and ignore their case.

Link for the API doc: http://docs.oracle.c.../api/index.html

Quote

using multiple if statements however is there any easier ways to do this?

Yes, the condition inside the ()s can be several boolean expressions connected by boolean operators:
   if ((a > c) && x.equals(y) && (f != 44) ) {


This post has been edited by NormR: 23 September 2016 - 02:42 PM

Was This Post Helpful? 0
  • +
  • -

#21 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 02:49 PM

View PostNormR, on 23 September 2016 - 03:38 PM, said:

Quote

if the choice is SCREAM the user can either type SCREAM, scream, Scream. How would I do that?

Read the API doc for the String class. It has a method to compare Strings and ignore their case.

Link for the API doc: http://docs.oracle.c.../api/index.html

Quote

using multiple if statements however is there any easier ways to do this?

Yes, the condition inside the ()s can be several boolean expressions connected by boolean operators:
   if ((a > c) && x.equals(y) && (f != 44) ) {




Ok so now im having a problem where if I type one of the choices it doesnt even print the appropriate response. Here is my newest copy of the code...


import java.util.Scanner;

public class Main

{
		//Creating the method for places
		private static void place(String place, String description){

        System.out.println(place + "\n"+description);
        
		}
		//main method/whole game
		public static void main(String[] args) {
			
        String choice;

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		
		boolean badInput = true;
				
		System.out.println("\n\n\n ▄▀▀█▄▄   ▄▀▀█▄▄▄▄  ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄▀▀▀▄  ▄▀▀▀█▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀█▄▄ ");
		System.out.println("█ ▄▀   █ ▐  ▄▀   ▐ █ █   ▐ ▐  ▄▀   ▐ █   █   █ █    █  ▐ ▐  ▄▀   ▐ █ ▄▀   █ ");
		System.out.println("▐ █    █   █▄▄▄▄▄     ▀▄     █▄▄▄▄▄  ▐  █▀▀█▀  ▐   █       █▄▄▄▄▄  ▐ █    █ ");
		System.out.println("  █    █   █    ▌  ▀▄   █    █    ▌   ▄▀    █     █        █    ▌    █    █ ");
		System.out.println(" ▄▀▄▄▄▄▀  ▄▀▄▄▄▄    █▀▀▀    ▄▀▄▄▄▄   █     █    ▄▀        ▄▀▄▄▄▄    ▄▀▄▄▄▄▀ ");
		System.out.println("█     ▐   █    ▐    ▐       █    ▐   ▐     ▐   █          █    ▐   █     ▐  ");
		System.out.println("▐         ▐                 ▐                  ▐          ▐        ▐        \n\n\n");
		place("== Dark Room ==","");
		System.out.println("You have just awoken and you cannont see anything around you. The only thing you notice is a small hole of light in the corner of the room.\n");
		System.out.println("You are badly injured and can hardly walk. Seems as though your left ankle is sprained.\n\n");
		System.out.println("*^* Do you SCREAM for help or STUMBLE around the dark room? *^*");
		
		//Getting user input.
        choice = scan.nextLine();

        /*
         * What happens after that choice. 
         */
        while(badInput) {
        	if(!choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("scream"))
        	if(!choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble"))
        		
            System.out.println("Not a valid command");
        	choice = scan.nextLine();
        	//Scream choice
        		if(choice.equals("SCREAM")){ 
        			if(choice.equals("Scream"))
        				if(choice.equals("scream"))
        					
        			place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

        			System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

        			choice = scan.nextLine(); 
        	//Stumble choice
        			if(choice.equals("STUMBLE")) {
        	        	if(!choice.equals("Stumble"))
        	            if(!choice.equals("stumble"))
        	        		
        	        		place("\n== Dark Room ==","You stumble around finding nothing but the room around you. As your eyes adjust you can see a figure lying on the ground under the source of light.");
        	        		
        	        		System.out.println("Do you CRAWL towards the figure or STAY where you are?");
        	        		
        	        		choice = scan.nextLine();
        	        	   
        			}
        		}
        	}        
    	}
}

Was This Post Helpful? 0
  • +
  • -

#22 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Need help with text adventure game

Posted 23 September 2016 - 02:52 PM

I see there are missing {}s following some if statements. Make sure ALL of the if statements enclose the code they control inside of {}s

This post has been edited by NormR: 23 September 2016 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

#23 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 02:58 PM

View PostToshritzy, on 23 September 2016 - 03:49 PM, said:

View PostNormR, on 23 September 2016 - 03:38 PM, said:

Quote

if the choice is SCREAM the user can either type SCREAM, scream, Scream. How would I do that?

Read the API doc for the String class. It has a method to compare Strings and ignore their case.

Link for the API doc: http://docs.oracle.c.../api/index.html

Quote

using multiple if statements however is there any easier ways to do this?

Yes, the condition inside the ()s can be several boolean expressions connected by boolean operators:
   if ((a > c) && x.equals(y) && (f != 44) ) {




Ok so now im having a problem where if I type one of the choices it doesnt even print the appropriate response. Here is my newest copy of the code...


import java.util.Scanner;

public class Main

{
		//Creating the method for places
		private static void place(String place, String description){

        System.out.println(place + "\n"+description);
        
		}
		//main method/whole game
		public static void main(String[] args) {
			
        String choice;

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		
		boolean badInput = true;
				
		System.out.println("\n\n\n ▄▀▀█▄▄   ▄▀▀█▄▄▄▄  ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄▀▀▀▄  ▄▀▀▀█▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀█▄▄ ");
		System.out.println("█ ▄▀   █ ▐  ▄▀   ▐ █ █   ▐ ▐  ▄▀   ▐ █   █   █ █    █  ▐ ▐  ▄▀   ▐ █ ▄▀   █ ");
		System.out.println("▐ █    █   █▄▄▄▄▄     ▀▄     █▄▄▄▄▄  ▐  █▀▀█▀  ▐   █       █▄▄▄▄▄  ▐ █    █ ");
		System.out.println("  █    █   █    ▌  ▀▄   █    █    ▌   ▄▀    █     █        █    ▌    █    █ ");
		System.out.println(" ▄▀▄▄▄▄▀  ▄▀▄▄▄▄    █▀▀▀    ▄▀▄▄▄▄   █     █    ▄▀        ▄▀▄▄▄▄    ▄▀▄▄▄▄▀ ");
		System.out.println("█     ▐   █    ▐    ▐       █    ▐   ▐     ▐   █          █    ▐   █     ▐  ");
		System.out.println("▐         ▐                 ▐                  ▐          ▐        ▐        \n\n\n");
		place("== Dark Room ==","");
		System.out.println("You have just awoken and you cannont see anything around you. The only thing you notice is a small hole of light in the corner of the room.\n");
		System.out.println("You are badly injured and can hardly walk. Seems as though your left ankle is sprained.\n\n");
		System.out.println("*^* Do you SCREAM for help or STUMBLE around the dark room? *^*");
		
		//Getting user input.
        choice = scan.nextLine();

        /*
         * What happens after that choice. 
         */
        while(badInput) {
        	if(!choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("scream"))
        	if(!choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble"))
        		
            System.out.println("Not a valid command");
        	choice = scan.nextLine();
        	//Scream choice
        		if(choice.equals("SCREAM")){ 
        			if(choice.equals("Scream"))
        				if(choice.equals("scream"))
        					
        			place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

        			System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

        			choice = scan.nextLine(); 
        	//Stumble choice
        			if(choice.equals("STUMBLE")) {
        	        	if(!choice.equals("Stumble"))
        	            if(!choice.equals("stumble"))
        	        		
        	        		place("\n== Dark Room ==","You stumble around finding nothing but the room around you. As your eyes adjust you can see a figure lying on the ground under the source of light.");
        	        		
        	        		System.out.println("Do you CRAWL towards the figure or STAY where you are?");
        	        		
        	        		choice = scan.nextLine();
        	        	   
        			}
        		}
        	}        
    	}
}



So actually the scream choice is working but only after I type somthing before it. However the scream choice does not work if I use a lowercase form of it. The stumble choice just does not work at all.

Ok so here is all of the code in my current project.



import java.util.Scanner;

public class Main

{
		//Creating the method for places
		private static void place(String place, String description){

        System.out.println(place + "\n"+description);
        
		}
		//main method/whole game
		public static void main(String[] args) {
			
        String choice;

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		
		boolean badInput = true;
				
		System.out.println("\n\n\n ▄▀▀█▄▄   ▄▀▀█▄▄▄▄  ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄▀▀▀▄  ▄▀▀▀█▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀█▄▄ ");
		System.out.println("█ ▄▀   █ ▐  ▄▀   ▐ █ █   ▐ ▐  ▄▀   ▐ █   █   █ █    █  ▐ ▐  ▄▀   ▐ █ ▄▀   █ ");
		System.out.println("▐ █    █   █▄▄▄▄▄     ▀▄     █▄▄▄▄▄  ▐  █▀▀█▀  ▐   █       █▄▄▄▄▄  ▐ █    █ ");
		System.out.println("  █    █   █    ▌  ▀▄   █    █    ▌   ▄▀    █     █        █    ▌    █    █ ");
		System.out.println(" ▄▀▄▄▄▄▀  ▄▀▄▄▄▄    █▀▀▀    ▄▀▄▄▄▄   █     █    ▄▀        ▄▀▄▄▄▄    ▄▀▄▄▄▄▀ ");
		System.out.println("█     ▐   █    ▐    ▐       █    ▐   ▐     ▐   █          █    ▐   █     ▐  ");
		System.out.println("▐         ▐                 ▐                  ▐          ▐        ▐        \n\n\n");
		place("== Dark Room ==","");
		System.out.println("You have just awoken and you cannont see anything around you. The only thing you notice is a small hole of light in the corner of the room.\n");
		System.out.println("You are badly injured and can hardly walk. Seems as though your left ankle is sprained.\n\n");
		System.out.println("*^* Do you SCREAM for help or STUMBLE around the dark room? *^*");
		
		//Getting user input.
        choice = scan.nextLine();

        /*
         * What happens after that choice. 
         */
        while(badInput) {
        	if(!choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble")) {
        	if(!choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("screaSm")) {
        	
        		
            System.out.println("That does not work");
        	choice = scan.nextLine();
        	//Scream choice
        		if(choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("scream"))
        					
        			place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

        			System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

        			choice = scan.nextLine(); 
        	}
        	//Stumble choice
        			if(choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble")) 
        				
        	        place("\n== Dark Room ==","You stumble around finding nothing but the room around you. As your eyes adjust you can see a figure lying on the ground under the source of light.");
        	        		
        	        System.out.println("Do you CRAWL towards the figure or STAY where you are?");
        	        		
        	        choice = scan.nextLine();
        	}
        	        	   
        			
        		
        	}        
    	}
	}



with this code there are an unbelievable amount of bugs that I do not understand how to fix. All of this is still very confusing.
Was This Post Helpful? 0
  • +
  • -

#24 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Need help with text adventure game

Posted 23 September 2016 - 03:03 PM

You need to read the API doc for the String class like I suggested in post#20 for a method to use that ignores case.

There are still if statements without {}s. They need to be fixed.

The game logic should NOT be inside of the while loop that is only for getting valid user input.

This post has been edited by NormR: 23 September 2016 - 03:05 PM

Was This Post Helpful? 0
  • +
  • -

#25 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 03:05 PM

View PostNormR, on 23 September 2016 - 04:03 PM, said:

You need to read the API doc for the String class like I suggested in post#20 for a method to use that ignores case.

There are still if statements without {}s. They need to be fixed.


I know about the ignore cases and ill look into it but where do the {}s need to be I dont understand.
Was This Post Helpful? 0
  • +
  • -

#26 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Need help with text adventure game

Posted 23 September 2016 - 03:08 PM

Quote

where do the {}s need to be

After all the if statements. Colored in red here:
if (some condition) {
// ...
}
Was This Post Helpful? 0
  • +
  • -

#27 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 03:11 PM

View PostNormR, on 23 September 2016 - 04:08 PM, said:

Quote

where do the {}s need to be

After all the if statements. Colored in red here:
if (some condition) {
// ...
}



yes so this is what I have with {}s around all the if statements still nothing is working




import java.util.Scanner;

public class Main

{
		//Creating the method for places
		private static void place(String place, String description){

        System.out.println(place + "\n"+description);
        
		}
		//main method/whole game
		public static void main(String[] args) {
			
        String choice;

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		
		boolean badInput = true;
				
		System.out.println("\n\n\n ▄▀▀█▄▄   ▄▀▀█▄▄▄▄  ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄▀▀▀▄  ▄▀▀▀█▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀█▄▄ ");
		System.out.println("█ ▄▀   █ ▐  ▄▀   ▐ █ █   ▐ ▐  ▄▀   ▐ █   █   █ █    █  ▐ ▐  ▄▀   ▐ █ ▄▀   █ ");
		System.out.println("▐ █    █   █▄▄▄▄▄     ▀▄     █▄▄▄▄▄  ▐  █▀▀█▀  ▐   █       █▄▄▄▄▄  ▐ █    █ ");
		System.out.println("  █    █   █    ▌  ▀▄   █    █    ▌   ▄▀    █     █        █    ▌    █    █ ");
		System.out.println(" ▄▀▄▄▄▄▀  ▄▀▄▄▄▄    █▀▀▀    ▄▀▄▄▄▄   █     █    ▄▀        ▄▀▄▄▄▄    ▄▀▄▄▄▄▀ ");
		System.out.println("█     ▐   █    ▐    ▐       █    ▐   ▐     ▐   █          █    ▐   █     ▐  ");
		System.out.println("▐         ▐                 ▐                  ▐          ▐        ▐        \n\n\n");
		place("== Dark Room ==","");
		System.out.println("You have just awoken and you cannont see anything around you. The only thing you notice is a small hole of light in the corner of the room.\n");
		System.out.println("You are badly injured and can hardly walk. Seems as though your left ankle is sprained.\n\n");
		System.out.println("*^* Do you SCREAM for help or STUMBLE around the dark room? *^*");
		
		//Getting user input.
        choice = scan.nextLine();

        /*
         * What happens after that choice. 
         */
        while(badInput) {
        	if(!choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble")) {
        	if(!choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("screaSm")) {
        		
        		System.out.println("That does not work");
            	choice = scan.nextLine();
        	
        	//Scream choice
        		if(choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("scream")) {
        					
        			place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

        			System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

        			choice = scan.nextLine(); 
        	
        	//Stumble choice
        			if(choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble")) {
        				
        	        place("\n== Dark Room ==","You stumble around finding nothing but the room around you. As your eyes adjust you can see a figure lying on the ground under the source of light.");
        	        		
        	        System.out.println("Do you CRAWL towards the figure or STAY where you are?");
        	        		
        	        choice = scan.nextLine();
        			}
        		}
        	}
        }
    }
} 
}

Was This Post Helpful? 0
  • +
  • -

#28 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 03:18 PM

View PostToshritzy, on 23 September 2016 - 04:11 PM, said:

View PostNormR, on 23 September 2016 - 04:08 PM, said:

Quote

where do the {}s need to be

After all the if statements. Colored in red here:
if (some condition) {
// ...
}



yes so this is what I have with {}s around all the if statements still nothing is working




import java.util.Scanner;

public class Main

{
		//Creating the method for places
		private static void place(String place, String description){

        System.out.println(place + "\n"+description);
        
		}
		//main method/whole game
		public static void main(String[] args) {
			
        String choice;

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		
		boolean badInput = true;
				
		System.out.println("\n\n\n ▄▀▀█▄▄   ▄▀▀█▄▄▄▄  ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄▀▀▀▄  ▄▀▀▀█▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀█▄▄ ");
		System.out.println("█ ▄▀   █ ▐  ▄▀   ▐ █ █   ▐ ▐  ▄▀   ▐ █   █   █ █    █  ▐ ▐  ▄▀   ▐ █ ▄▀   █ ");
		System.out.println("▐ █    █   █▄▄▄▄▄     ▀▄     █▄▄▄▄▄  ▐  █▀▀█▀  ▐   █       █▄▄▄▄▄  ▐ █    █ ");
		System.out.println("  █    █   █    ▌  ▀▄   █    █    ▌   ▄▀    █     █        █    ▌    █    █ ");
		System.out.println(" ▄▀▄▄▄▄▀  ▄▀▄▄▄▄    █▀▀▀    ▄▀▄▄▄▄   █     █    ▄▀        ▄▀▄▄▄▄    ▄▀▄▄▄▄▀ ");
		System.out.println("█     ▐   █    ▐    ▐       █    ▐   ▐     ▐   █          █    ▐   █     ▐  ");
		System.out.println("▐         ▐                 ▐                  ▐          ▐        ▐        \n\n\n");
		place("== Dark Room ==","");
		System.out.println("You have just awoken and you cannont see anything around you. The only thing you notice is a small hole of light in the corner of the room.\n");
		System.out.println("You are badly injured and can hardly walk. Seems as though your left ankle is sprained.\n\n");
		System.out.println("*^* Do you SCREAM for help or STUMBLE around the dark room? *^*");
		
		//Getting user input.
        choice = scan.nextLine();

        /*
         * What happens after that choice. 
         */
        while(badInput) {
        	if(!choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble")) {
        	if(!choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("screaSm")) {
        		
        		System.out.println("That does not work");
            	choice = scan.nextLine();
        	
        	//Scream choice
        		if(choice.equals("SCREAM") && !choice.equals("Scream") && !choice.equals("scream")) {
        					
        			place("\n== Dark Room ==","The scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.");

        			System.out.println("Do you CRAWL towards the figure or STUMBLE around the room?");

        			choice = scan.nextLine(); 
        	
        	//Stumble choice
        			if(choice.equals("STUMBLE") && !choice.equals("Stumble") && !choice.equals("stumble")) {
        				
        	        place("\n== Dark Room ==","You stumble around finding nothing but the room around you. As your eyes adjust you can see a figure lying on the ground under the source of light.");
        	        		
        	        System.out.println("Do you CRAWL towards the figure or STAY where you are?");
        	        		
        	        choice = scan.nextLine();
        			}
        		}
        	}
        }
    }
} 
}



Nevermind I got it all to work thank you so much for all your help
Was This Post Helpful? 0
  • +
  • -

#29 Toshritzy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 22-September 16

Re: Need help with text adventure game

Posted 23 September 2016 - 03:37 PM

View PostNormR, on 23 September 2016 - 04:08 PM, said:

Quote

where do the {}s need to be

After all the if statements. Colored in red here:
if (some condition) {
// ...
}



okay so more problems...I got the whole no capital thing working however one of my choices does not work. It would be great if you could point out exactly where I went wrong.

import java.util.Scanner;

public class Main

{
		//Creating the method for places
		private static void place(String place, String description){

        System.out.println(place + "\n"+description);
        
		}
		//main method/whole game
		public static void main(String[] args) {
			
        String choice;

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		
		boolean badInput = true;
				
		System.out.println("\n\n\n ▄▀▀█▄▄   ▄▀▀█▄▄▄▄  ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄▀▀▀▄  ▄▀▀▀█▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀█▄▄ ");
		System.out.println("█ ▄▀   █ ▐  ▄▀   ▐ █ █   ▐ ▐  ▄▀   ▐ █   █   █ █    █  ▐ ▐  ▄▀   ▐ █ ▄▀   █ ");
		System.out.println("▐ █    █   █▄▄▄▄▄     ▀▄     █▄▄▄▄▄  ▐  █▀▀█▀  ▐   █       █▄▄▄▄▄  ▐ █    █ ");
		System.out.println("  █    █   █    ▌  ▀▄   █    █    ▌   ▄▀    █     █        █    ▌    █    █ ");
		System.out.println(" ▄▀▄▄▄▄▀  ▄▀▄▄▄▄    █▀▀▀    ▄▀▄▄▄▄   █     █    ▄▀        ▄▀▄▄▄▄    ▄▀▄▄▄▄▀ ");
		System.out.println("█     ▐   █    ▐    ▐       █    ▐   ▐     ▐   █          █    ▐   █     ▐  ");
		System.out.println("▐         ▐                 ▐                  ▐          ▐        ▐        \n\n\n");
		place("== Dark Room ==","");
		System.out.println("You have just awoken and you cannont see anything around you. The only thing you notice is a small hole of light in the corner of the room.\n");
		System.out.println("You are badly injured and can hardly walk. Seems as though your left ankle is sprained.\n\n");
		System.out.println("** Do you SCREAM for help or STUMBLE around the dark room? **\n");
		
		//Getting user input.
		System.out.print("Choice: ");
        choice = scan.nextLine();

        /*
         * What happens after that choice. 
         */
        while(badInput) {
        	if(!choice.equalsIgnoreCase("STUMBLE")) {
        	if(!choice.equalsIgnoreCase("SCREAM")) {
        		
        		System.out.println("\nThat does not work\n");
        		
        		System.out.print("Choice: ");
            	choice = scan.nextLine();
        	}
        }
        	//Scream choice
        		if(choice.equalsIgnoreCase("SCREAM")) {
        					
        			place("\n\n\n== Dark Room ==","\nThe scream does not echo and cannot be heard by anyone. As your eyes adjust you can see a figure lying on the ground under the source of light.\n\n");

        			System.out.println("** Do you CRAWL towards the figure or STUMBLE around the room? **\n");
        			
        			System.out.print("Choice: ");
        			choice = scan.nextLine(); 
        	
        	//Stumble choice
        			if(choice.equalsIgnoreCase("STUMBLE")) 
        				
        	        place("\n\n\n== Dark Room ==","You stumble around finding nothing but the room around you. As your eyes adjust you can see a figure lying on the ground under the source of light.\n\n");
        	        		
        	        System.out.println("** Do you CRAWL towards the figure or STAY where you are? **\n");
        	        
        	        System.out.print("Choice: ");
        	        choice = scan.nextLine();
        			
        		}
        	}
        }
    }

Was This Post Helpful? 0
  • +
  • -

#30 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Need help with text adventure game

Posted 23 September 2016 - 03:53 PM

Quote

one of my choices does not work

Please explain.
Copy the full contents of the command prompt console and paste here from when you execute the program. Add some comments saying what it wrong.

Note: The code doesn't follow the logic for getting valid input from the user that I suggested in post#13

This post has been edited by NormR: 23 September 2016 - 03:56 PM

Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »