Results 1 to 8 of 8
  1. #1
    bluecloak is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default How do I make a simple java text game?

    So I am relatively new to Java. I've decided to make a simple text game. I want the game to be like this: a paragraph appears in a JTextArea telling you your surroundings and a few options as to what to do. Input being strings. When you input an answer into the JTextField, the text changes to something coordinating to what you typed in. Clearing the reply area for the next response also. I had a method for all of this, but you could enter an answer to a scenario 5 steps ahead and it would work. The frame I have already made up, so please make the reply based on this code. Also, I've been getting a compile error but I can't pinpoint it. Help on that would be nice too!
    Java Code:
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.net.URL;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    
    public class Lobby
    {
    	private JFrame Lobby;
    	private Container MainMenuPane;
    	private JLabel MainMenuBackground;
    	private JButton Quit, Helpbtn, Map;
    	private Insets insetsMain;
    	private JTextArea Game;
    	private JTextField reply;
    	
    	public static void main(String argv[])
    	{
    		new WarningM();
    	}
    
    	public void e()
    	{
    		reply.setText("");
    	}
    	
    	public Lobby()
    	{
    		reply = new JTextField();
    		Font font = new Font("Times New Roman", Font.ITALIC, 36);
    		Font fontone = new Font("Times New Roman", Font.ITALIC, 24);
    		//pics
    		URL A = getClass().getResource("/GamePics/Help.png");Image HelpButton = Toolkit.getDefaultToolkit().getImage(A);
    		URL B = getClass().getResource("/GamePics/Quit.png");Image QuitButton = Toolkit.getDefaultToolkit().getImage(B);
    		URL C = getClass().getResource("/GamePics/Mapbtn.png");Image MapButton = Toolkit.getDefaultToolkit().getImage(C);
    		URL D = getClass().getResource("/GamePics/Background.png");Image MMBack = Toolkit.getDefaultToolkit().getImage(D);
    		
    		//error handlers
    		try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
    		catch (ClassNotFoundException e) {System.out.println("Class not Found");}
    		catch (InstantiationException e) {System.out.println("InstantiationException");}
    		catch (IllegalAccessException e) {System.out.println("Illegal Access");}
    		catch (UnsupportedLookAndFeelException e) {System.out.println("LaF not supported");}
    
    		//Create the frame
    		Lobby = new JFrame ("The game of quests");
    		Lobby.setSize(1100, 700);
    	    Lobby.setLocationRelativeTo(null);
    	    Lobby.setResizable(false);
    		MainMenuPane = Lobby.getContentPane();
    		insetsMain = MainMenuPane.getInsets();
    		MainMenuPane.setLayout (null);
    
    /////////////////////////////////////////Create controls///////////////////////////////////////////////////
    		Game = new JTextArea("Please enter your name. Please note that all answers are case sensitive.");
    		Quit = new JButton(new ImageIcon(QuitButton));
    		Map = new JButton(new ImageIcon(MapButton));
    		Helpbtn = new JButton(new ImageIcon(HelpButton));
    		MainMenuBackground = new JLabel(new ImageIcon(MMBack));
    		
    /////////////////////////////////////////Add all components to panel///////////////////////////////////////
    		MainMenuPane.add (Game);
    		MainMenuPane.add (reply);
    		MainMenuPane.add (Map);
    		MainMenuPane.add (Quit);
    		MainMenuPane.add (Helpbtn);
    		MainMenuPane.add (MainMenuBackground);
    		
    ////////////////////////////////////////Place all components///////////////////////////////////////////////
    		Game.setBounds(240, 40, 800, 500);
    		Game.setOpaque(false);
    		Game.setLineWrap(true);
    		Game.setWrapStyleWord(true);
    		Game.setFont(font);
    		Game.setForeground(Color.WHITE);
    		Game.setEditable(false);
    		
    		reply.setBounds(240, 600, 770, 30);
    		reply.setFont(fontone);
    		reply.setBackground(Color.WHITE);
    		reply.setForeground(Color.BLACK);
    		
    		Map.setBounds(30, 130, 150, 50);
    		Quit.setBounds(30, 220, 150, 50);
    		Helpbtn.setBounds(30, 40, 150, 50);
    		
    		MainMenuBackground.setBounds(-2, 0, 1300, 800);
    ////////////////////////////////////////Set frame visible//////////////////////////////////////////////////
    		Lobby.setVisible (true);
    
    		//Button's action(ActionListener for each specific button)
    		reply.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent evt){
    		               
    }});
    		Quit.addActionListener(new ActionListener()
    		{
    			@Override
    			public void actionPerformed(ActionEvent i)
    			{
    				System.exit(0);
    			}
    		});
    		Helpbtn.addActionListener(new ActionListener()
    		{
    			@Override
    			public void actionPerformed(ActionEvent i)
    			{
    				new Help();
    			}
    		});
    		Map.addActionListener(new ActionListener()
    		{
    			@Override
    			public void actionPerformed(ActionEvent i)
    			{
    				new AreaMap();
    			}
    		});
        }
    }

  2. #2
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: How do I make a simple java text game?

    Hi, can you tell us what errors you are getting when you run your code? What is it that is not working as expected?

  3. #3
    bluecloak is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: How do I make a simple java text game?

    Everything works perfectly fine and no errors are presented. When I export it just says compile warnings.

  4. #4
    bluecloak is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: How do I make a simple java text game?

    bump

  5. #5
    bluecloak is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: How do I make a simple java text game?

    Anyone?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I make a simple java text game?

    What exactly is your question? You state that the code compiles and that it works, so I'm at a loss to know what specific question you're asking.

  7. #7
    bluecloak is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: How do I make a simple java text game?

    I want to know a way to set up a text game that works like how I described it above. The compile error I fixed so ignore that part. Sorry if the question was that confusing.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I make a simple java text game?

    Quote Originally Posted by bluecloak View Post
    I want to know a way to set up a text game that works like how I described it above. The compile error I fixed so ignore that part. Sorry if the question was that confusing.
    In other words your question is how to implement this?:

    I want the game to be like this: a paragraph appears in a JTextArea telling you your surroundings and a few options as to what to do. Input being strings. When you input an answer into the JTextField, the text changes to something coordinating to what you typed in. Clearing the reply area for the next response also. I had a method for all of this, but you could enter an answer to a scenario 5 steps ahead and it would work.
    In my opinion this question is a very broad one, and no it may be difficult to tell you all the details necessary without writing a complete tutorial from scratch. I would suggest that you break down the project into smaller steps, work on each small step one at a time, and then if you get stuck you can ask a much more specific and answerable question. I see two main keys towards success for this project: a) getting a very good grasp of Java fundamentals including how to design well-crafted object oriented classes, and b) making sure to separate data from code well meaning that which should remain unchanged -- your main user GUI interface for instance -- will be defined in code, while things that can and will change frequently such as the level maps, the items and characters on the map, will be stored as data in files that the program reads.

Similar Threads

  1. want to make a simple game in java
    By Tarasj in forum New To Java
    Replies: 1
    Last Post: 03-26-2012, 09:54 PM
  2. Make the game: chapeau with Java
    By brenje in forum New To Java
    Replies: 3
    Last Post: 11-23-2011, 05:37 PM
  3. Replies: 1
    Last Post: 08-30-2011, 02:28 PM
  4. Make a 3D java game
    By Nuclear Mosquito in forum Java Gaming
    Replies: 7
    Last Post: 12-08-2010, 10:07 AM
  5. Simple Text race game
    By Inf1nity in forum New To Java
    Replies: 2
    Last Post: 03-16-2009, 03:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •