So since I last posted I've been doing my best to broaden my Java horizons. For those who weren't kind enough to respond to my first question here: I've been programming about a week now and Java is my first language. With that in mind I hope this doesn't sound like a silly question.
In the interest of consolidating what I've learned in the last week I'm turning my hand to a really simple text adventure game as a means of experimenting with variables, conditions, loops and input. Thus far all I've designed is a start 'screen' and the output I want once the user types 'start'. However I seem to be having some problems in achieving this. Maybe if I post the code it'll make it clearer:
import java.util.Scanner;
public class TextAdventure {
public static void main(String[] args) {
// Display 'Dragon Quest IV: The Hunt For Red October' and advise user of input to start game. When user types start this should invoke method 'Adventure'
System.out.println("DUNGEON QUEST IV:");
System.out.println();
System.out.println("The Hunt For Red October");
System.out.println();
System.out.println("Please type 'start' to begin your adventure");
Scanner scan = new Scanner (System.in);
String start = scan.nextLine();
if (start =="start") {
adventure();
}
}
public static void adventure() {
// Screen 1. Description and options.
System.out.println("You wake from a largley sleepless night in a dark room. Through the haze you can make out a table beside you, a door across from you and a wardrobe in the corner.")
System.out.println();
System.out.println("Will you:")
System.out.println();
System.out.println("a) Examine the table");
System.out.println("b) Look at the wardrobe");
System.out.println("c) Try the door");
}
}
So at the end of the main method I'm trying to get my programme to invoke the method adventure() if the user types start. However when I run it and type 'start' I get no response whatsoever. I'm assuming there's another way to tell your programme to expect a certain kind of input that I'm not aware of. Either way: could someone tell me what I'm doing wrong?
Thanks,
Dev.


Sign In
Create Account


Back to top









