Jump to content
  • Advertisement
Sign in to follow this  
Veymex

Java help with Text-based adventure game

This topic is 2515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Hey, I started out writing a text based adventure game like yourself smile.png

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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!