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?
Java help with Text-based adventure game
Started by Veymex, Jan 22 2012 02:06 PM
2 replies to this topic
Ad:
#2 Members - Reputation: 434
Posted 22 January 2012 - 03:31 PM
Hey, I started out writing a text based adventure game like yourself 
Anyway, to make a JFrame is very simple:
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)
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..
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..






