I have made a text-adventure, I got text, input, ect. I have a window that pops up now, but I want to know how to put the text into the console.
Game.java
package main; /* * Shzylo's Text Adventure v1.0 * */ import java.util.Scanner; import java.awt.*; import javax.swing.*; public class Game extends Variables implements Runnable { private static final long serialVersionUID = 1L; private JFrame frame = new JFrame(); public int height = 350; public int width = 650; public Game() { Dimension size = new Dimension( width, height); setPreferredSize(size); } public static void main(String[] args) { Game game = new Game(); game.frame.setResizable(false); game.frame.setTitle("Shzylo's Text Adventure v0.1 BETA"); game.frame.add(game); game.frame.pack(); game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); game.frame.setLocationRelativeTo(null); game.frame.setVisible(true); Main.start(); } public void run() { while(running) { } } }
Main.java
package main; public class Main extends Variables { private static final long serialVersionUID = 1L; static int x = 0; static int y = 0; static int stickValue = 1; static boolean stickObject = true; public static void start() { running = true; System.out.println("You wake up lost, washed ashore on a beach. All you see in sight is a stick, a rock, and lots of sand."); System.out.println("Where would you like to go? North, South, East, West"); System.out.println("type 'help' if you need help."); string = i.nextLine(); do { if(string.equalsIgnoreCase("north")) { north(); } else if(string.equalsIgnoreCase("south")) { south(); } else if(string.equalsIgnoreCase("east")) { east(); } else if(string.equalsIgnoreCase("west")) { stickValue--; if(stickValue == 0) { stickObject = false; if(stickObject = false) { west(); } } } else if(string.equalsIgnoreCase("help")) { help(); } else { System.out.println("I do not recognize that command.."); sleep(); System.out.println("Please choose an action:"); string = i.nextLine(); } } while(x == y); } public static void north() { System.out.println("You have traveled north into a forest, where you see a turtle resting on a rock, nothing special in this direction."); sleep(); System.out.println("Please choose an action:"); string = i.nextLine(); } public static void south() { System.out.println("I wouldn't go that way, there is an aweful lot of water there."); sleep(); System.out.println("Please choose an action:"); string = i.nextLine(); } public static void east() { System.out.println("Oh, a snake, it's staring and hissing at you. I would get some defense before I go there."); sleep(); System.out.println("Please choose an action:"); string = i.nextLine(); } public static void west() { System.out.println("I see rope, and some bass in a small pool of water"); sleep(); System.out.println("Please choose an action:"); string = i.nextLine(); } public static void help() { System.out.println("Where would you like to go? North, South, East, West"); sleep(); string = i.nextLine(); } public static void stop() { running = false; } }
Variables.java
package main; import java.awt.Canvas; import java.util.Scanner; public class Variables extends Canvas { private static final long serialVersionUID = 1L; static Scanner i = new Scanner(System.in); public static String string = ""; private Thread thread; protected static boolean running = false; String itemName; int value; public static void sleep() { try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } public static void space() { System.out.println(""); } }