Need help with text adventure game

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • 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

#31 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 - 04:03 PM

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

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



ok so heres what I get when I run that code and try to type some stuff



scream command works completely fine :

== Dark Room ==

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.

You are badly injured and can hardly walk. Seems as though your left ankle is sprained.


** Do you SCREAM for help or STUMBLE around the dark room? **

Choice: scream



== 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.


** Do you CRAWL towards the figure or STUMBLE around the room? **

Choice:

-----------------------------------------------------------------------------------------------------------------------------------

now if I try to type stumble this is what i get...

== Dark Room ==

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.

You are badly injured and can hardly walk. Seems as though your left ankle is sprained.


** Do you SCREAM for help or STUMBLE around the dark room? **

Choice: stumble
Stumble
STUMBLE

-----------------------------------------------------------------------------------------------------------------------------------

however when I type scream and then stumble it goes to my stumble if statement that should be in the first option...

== Dark Room ==

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.

You are badly injured and can hardly walk. Seems as though your left ankle is sprained.


** Do you SCREAM for help or STUMBLE around the dark room? **

Choice: scream



== 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.


** Do you CRAWL towards the figure or STUMBLE around the room? **

Choice: stumble



== 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.


** Do you CRAWL towards the figure or STAY where you are? **

Choice:
Was This Post Helpful? 0
  • +
  • -

#32 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 - 04:19 PM

Ok, what was wrong? I didn't see where you flagged the bad sections. How do I see where the output was wrong? say like this:
<<<<*** this was wrong

Also what about:
The code doesn't follow the logic for getting valid input from the user that I suggested in post#13
Was This Post Helpful? 0
  • +
  • -

#33 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 - 04:24 PM

View PostNormR, on 23 September 2016 - 05:19 PM, said:

Ok, what was wrong? I didn't see where you flagged the bad sections. How do I see where the output was wrong? say like this:
<<<<*** this was wrong

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




scream command works completely fine :

== Dark Room ==

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.

You are badly injured and can hardly walk. Seems as though your left ankle is sprained.


** Do you SCREAM for help or STUMBLE around the dark room? **

Choice: scream



== 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.


** Do you CRAWL towards the figure or STUMBLE around the room? **

Choice:

-----------------------------------------------------------------------------------------------------------------------------------

now if I try to type stumble this is what i get...

== Dark Room ==

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.

You are badly injured and can hardly walk. Seems as though your left ankle is sprained.


** Do you SCREAM for help or STUMBLE around the dark room? **

Choice: stumble <<<<*** this was wrong
Stumble
STUMBLE

-----------------------------------------------------------------------------------------------------------------------------------

however when I type scream and then stumble it goes to my stumble if statement that should be in the first option...

== Dark Room ==

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.

You are badly injured and can hardly walk. Seems as though your left ankle is sprained.


** Do you SCREAM for help or STUMBLE around the dark room? **

Choice: scream



== 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.


** Do you CRAWL towards the figure or STUMBLE around the room? **

Choice: stumble <<<<*** this was wrong



== 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.


** Do you CRAWL towards the figure or STAY where you are? **

Choice:

View PostNormR, on 23 September 2016 - 05:19 PM, said:

Ok, what was wrong? I didn't see where you flagged the bad sections. How do I see where the output was wrong? say like this:
<<<<*** this was wrong

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


also isnt the input it is recieving and checking, the input from choice = scan.nextLine();
Was This Post Helpful? 0
  • +
  • -

#34 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 - 04:29 PM

Did you change the code?
The code doesn't follow the logic for getting valid input from the user that I suggested in post#13
Was This Post Helpful? 0
  • +
  • -

#35 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 - 04:33 PM

View PostNormR, on 23 September 2016 - 05:29 PM, said:

Did you change the code?
The code doesn't follow the logic for getting valid input from the user that I suggested in post#13



This is the full code. On line 42 you can see where I get what the user types and if it is not one of the options then it prints that does not work and gets their input again. One thing I noticed is if I need to instead put this while statement above my very first question?




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
  • +
  • -

#36 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 - 04:46 PM

Where does the code set badInput false when it finds the input is valid so the execution can exit the loop?
The end of the while loop should be BEFORE the game starts, about line 50.
Was This Post Helpful? 0
  • +
  • -

#37 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 - 04:54 PM

View PostNormR, on 23 September 2016 - 05:46 PM, said:

Where does the code set badInput false when it finds the input is valid so the execution can exit the loop?
The end of the while loop should be BEFORE the game starts, about line 50.


it doesnt need to set it to false because it has if statements on line 44 and 45 that check if the choice is not one of those then it says that does not work and gives you an oppurtunity to choose another option. however stumble is not working only scream is. And after scream is put in the choice then you can select stumble.
Was This Post Helpful? 0
  • +
  • -

#38 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 - 04:59 PM

Quote

it doesnt need to set it to false

Then the while loop to check for valid user input can be removed if it is not used.
The current program is confusing for me with the way it uses the variable: badInput.
Was This Post Helpful? 0
  • +
  • -

#39 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 - 05:38 PM

View PostNormR, on 23 September 2016 - 05:59 PM, said:

Quote

it doesnt need to set it to false

Then the while loop to check for valid user input can be removed if it is not used.
The current program is confusing for me with the way it uses the variable: badInput.


well i guess i do not need the boolean badInput but I dont know what else to put inside the while loop.
Was This Post Helpful? 0
  • +
  • -

#40 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 - 05:45 PM

What is the purpose of the loop? Why does the program need it?
Was This Post Helpful? 0
  • +
  • -

#41 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 - 06:07 PM

View PostNormR, on 23 September 2016 - 06:45 PM, said:

What is the purpose of the loop? Why does the program need it?



so that if the person types somthing that is not one of the options it loops back to the original question?
Was This Post Helpful? 0
  • +
  • -

#42 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 - 06:18 PM

This is confusing. I thought the code in post#13 did that. Then you didn't think it was needed and said this:

Quote

it doesnt need to set it to false because it has if statements on line 44 and 45


I don't know what to recommend now.
If you want to check that the user's input is valid BEFORE playing the game, see post#13
otherwise ???


Since there are many places the code needs to check for valid input, the code from post#13 should be placed in a method that is passed a list of the valid inputs and the method return which input the user selected.
Was This Post Helpful? 0
  • +
  • -

#43 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 - 06:25 PM

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

This is confusing. I thought the code in post#13 did that. Then you didn't think it was needed and said this:

Quote

it doesnt need to set it to false because it has if statements on line 44 and 45


I don't know what to recommend now.
If you want to check that the user's input is valid BEFORE playing the game, see post#13
otherwise ???


Since there are many places the code needs to check for valid input, the code from post#13 should be placed in a method that is passed a list of the valid inputs and the method return which input the user selected.


im just gonna start a new thread without the while loop and see what I can get...
Was This Post Helpful? 0
  • +
  • -

#44 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 - 06:27 PM

Try writing a method to get and check the user's input.
Was This Post Helpful? 0
  • +
  • -

#45 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Need help with text adventure game

Posted 23 September 2016 - 06:28 PM

Please do not open duplicate threads.
Was This Post Helpful? 0
  • +
  • -

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