Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java Game Help
#2
So what you want to do is get the users input directly after you ask what direction they want to go. That can be done using your Scanner variable: sc. So I have created a new code snippet that does exactly this. Then, we analyze the user's input to see if it contains directional information using the .equalsIgnoreCase() - if it corresponds to a certain direction (left or right) we then send the program to methods corresponding with that direction.

[code2=java]import java.util.Scanner;
public class Island {

static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws InterruptedException{
System.out.println("You awake to find yourself on an island in the middle of the sea.");
Thread.sleep(3000);
System.out.println("You then walk around the island, in which you find two paths.");
Thread.sleep(3000);
System.out.println("Choose from the left cobble path, or the right class path.");
//here we need to get the user's input
String direction = sc.nextLine(); //this holds the direction that the user chose
if (direction.equalsIgnoreCase("left"))
GoLeft();
else if (direction.equalsIgnoreCase("right"))
GoRight();
else
System.out.println("That is not a valid direction!");
}

//this method holds all of the information chosen if the user goes left
public void GoLeft()
{
System.out.println("You go left and find a trapdoor. What do you do?");
}

//this method holds all of the info chosen if the user goes right
public void GoRight()
{
System.out.println("You go right and find a dead end. Boo hoo.");
}
}[/code2]

This should be what you are looking for.
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Java Game Help - by ThreeLeBlancs - 07-28-2013, 04:21 PM
Re: Java Game Help - by brandonio21_phpbb3_import2 - 08-04-2013, 11:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Platformer game stefanbanu 2 12,175 04-06-2014, 11:46 AM
Last Post: brandonio21
  What is required to run the Java Framework? Derek275 1 10,768 01-07-2013, 07:04 PM
Last Post: WitherSlayer
  New Java Game - Space Thrashers Y brandonio21 2 13,137 01-03-2013, 12:40 AM
Last Post: brandonio21
  Java and Ubuntu? Derek275 0 6,463 12-04-2012, 04:54 AM
Last Post: Derek275
  New to Java vijayraj34 8 27,019 07-23-2012, 10:40 PM
Last Post: brandonio21
  Cool Little Game - tArena brandonio21 2 12,685 06-18-2012, 05:54 PM
Last Post: brandonio21
  Java and JavaScript Vinwarez 2 12,347 03-12-2012, 10:00 PM
Last Post: Vinwarez
  Conway's Game of Life brandonio21 0 6,678 12-30-2011, 12:10 AM
Last Post: brandonio21
  Need Java Help? vbcodegeek 2 11,634 08-20-2011, 03:03 AM
Last Post: vbcodegeek

Forum Jump:


Users browsing this thread: 1 Guest(s)