Mythruna
April 24, 2024, 07:00:31 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)  (Read 22068 times)
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« on: December 19, 2012, 07:53:43 PM »

Ok, I am making a text adventure with actual knowledge, as you know I am beginner (or some may know.) I have made a GUI window JFrame swing thing.

Now the problem. Putting the text and features INTO the window. I have heard that you use the JLabel to show text on the window (GUI) but I cannot do so, because the screen is blank:



I do have the game running in the background (on the console) but hidden. Here is my code:

Quote

Game.java
Code:
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) {
}

}
   
}


Variables.java
Code:
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;
     
    public static void sleep() {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
     
    public static void space() {
        System.out.println("");
    }
}


Main.java
Code:
package main;

import javax.swing.JLabel;
 
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 = false;

    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 = true;
        if(stickObject = true) {
        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;
    }
}

Want to test it yourself? go ahead: http://www.mediafire.com/download.php?9l4gea5ty8ms80l
Source code to check it yourself? go ahead: http://www.mediafire.com/download.php?dsz4d58za5rzbpv
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #1 on: December 20, 2012, 06:55:04 AM »

You will find this much easier if you do it as a command line based app now and worry about a real window later.

I'm going to be exceedingly generous and show a block of code for reading commands from the command line:

Code:
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
String line = null;
while( (line = in.readLine() ) {
    System.out.println( "You entered:" + line );
}

In a simple text adventure, that is your game loop.
Logged
Moonkey
Hero Member
*****
Posts: 1587

This is probably a picture.


View Profile
« Reply #2 on: December 20, 2012, 12:06:35 PM »

Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)
Logged

Mythruna: Don't you dare read any posts I made before 2014.
Moonkey
Hero Member
*****
Posts: 1587

This is probably a picture.


View Profile
« Reply #3 on: December 20, 2012, 12:08:32 PM »

Oh, and it's a bit confusing. And it locked up when I typed west at the rope part. Lol.
Logged

Mythruna: Don't you dare read any posts I made before 2014.
Sean
Donators
Hero Member
***
Posts: 598



View Profile
« Reply #4 on: December 20, 2012, 01:00:20 PM »

Listen to Paul, text adventures should be done in the command prompt.
Logged

"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
Iggyjeckel
Donators
Hero Member
***
Posts: 510


View Profile
« Reply #5 on: December 20, 2012, 01:01:28 PM »

With programa in c++ if it asks for an integer value, and you put lets say 'y' it breaks it. One of the things i noticed from programming so far is "program for the trolls....they will try anything and everything to break your program" lol
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #6 on: December 20, 2012, 01:54:12 PM »

Ah, I see you are using Scanner to read std in.  That's ok, too.  Don't worry about a GUI yet.  The whole point of the text adventure exercise is to not have to worry about that stuff.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #7 on: December 20, 2012, 02:29:32 PM »

i'm trying to get ahead of myself... oh boy. Smiley
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #8 on: December 20, 2012, 03:07:43 PM »

Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)

Not my fault, mediafire does that itself Tongue
Logged
Moonkey
Hero Member
*****
Posts: 1587

This is probably a picture.


View Profile
« Reply #9 on: December 20, 2012, 04:45:22 PM »

Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)

Not my fault, mediafire does that itself Tongue
I've downloaded tons of Minecraft mods from Mediafire that give me a .zip and not a .ZIP... Oh well *goes away*
Logged

Mythruna: Don't you dare read any posts I made before 2014.
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #10 on: December 20, 2012, 05:05:53 PM »

Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)

Not my fault, mediafire does that itself Tongue
I've downloaded tons of Minecraft mods from Mediafire that give me a .zip and not a .ZIP... Oh well *goes away*

The real issue is that your system doesn't recognize ZIP as zip.  Windows is case insensitive so there is something funny with that software's setup.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #11 on: December 20, 2012, 05:15:21 PM »

I do
RIGHT CLICK -> New -> Compressed (zipped) folder
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #12 on: December 20, 2012, 08:01:54 PM »

I do
RIGHT CLICK -> New -> Compressed (zipped) folder

Yeah, this time I wasn't picking on you.  .zip, .ZIP, .ZiP, .Zip should all be valid zip files on Windows.  If not then something is messed up on the person's computer who is trying to extract them.  Or the files are not really . zip at all.

On Windows you shouldn't have to use WinRAR anyway since windows can handle .zip files natively.
Logged
Iggyjeckel
Donators
Hero Member
***
Posts: 510


View Profile
« Reply #13 on: December 20, 2012, 08:30:42 PM »

Unless its "old" windows lol
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #14 on: December 20, 2012, 09:11:05 PM »

Unless its "old" windows lol

Like, earlier than Windows XP.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!