Jump to content

  • Log In with Google      Sign In   
  • Create Account


Java help with Text-based adventure game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Veymex   Members   -  Reputation: 100

Like
0Likes
Like

Posted 22 January 2012 - 02:06 PM

I'm very new to game development so i thought I would start out with a text-based adventure game. I know how to set up displaying the text and giving you options and things like that. But i wish to display it in a frame. I believe it's a Jframe i'm supposed to use? I also wish to maybe have like a title screen and a "game over" screen and a "you win" screen.

Can anyone help?

Sponsor:

#2 CryoGenesis   Members   -  Reputation: 495

Like
0Likes
Like

Posted 22 January 2012 - 03:31 PM

Hey, I started out writing a text based adventure game like yourself Posted Image

Anyway, to make a JFrame is very simple:

class whatever{
public static void main(String[] args){
JFrame frame = new JFrame("Name of your window");
frame.setSize(width,Height);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE)
//stops the program when the jframe is closed
frame.setLocation(x,y);
frame.setVisible(true)
}
}


but from there you have to populate the window like so:

Add this line of code to your main method
frame.add(new update());

Your update class could be this:
(btw Im using a thread for this class. you can use a Timer if you want just search it in google or something)
public class Update extends JPanel implements Runnable, KeyListener{
//The key listener so your program can take key input
Thread thread;
boolean gameover;
public Update(){
addKeyListener(this);
setFocusable(true);
thread = new Thread(this);
thread.start();
}
public void update(){}
public void paint(Graphics g){}
public void run(){
while(!gameover){
//game loop
update();
repaint();

thread.sleep(insert sleep time in millis here);

}
//display game over screen
}
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}

}


This just sets up a nice framework for you text adventure game..
But I would recommend just having a console so you wont have to bother having to do switches for the key inputs etc...
Although you could probably make the whole adventure game a lot better with JFrame because you could have puzzles and stuff that would involve colour.

Hope it helped.
Gen..

#3 Matthewj234   Members   -  Reputation: 793

Like
0Likes
Like

Posted 22 January 2012 - 05:00 PM

Dont look into JFrames yet. To start with make use of you IDE's cosole, then look into a JFrame based console. purely because as far as i am aware, there isnt a built in console for JFrames.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS