Could you help me with my text adventure.I am looking to display the welcome message and ask the user their name only.
When the user has entered their name I would then like to display the next set of text in my adventure game which
is enter a number below and scroll with it.Then when the user has entered their number I would like to display the next paragraph,then get user input,then display the next paragraph,text adventure style.
The questions are that I am unable to get the text of the game to display in sequences,as it is displaying all in 1 go at the moment.The scrollbar works but only manually.When I try to set the input number variable as getint this is underlined in red but gettext isnt.The progress bar is for a health bar but is in its early stages yet.My main concern is displaying the text in blocks from following user input.If anyone could help me with this and keeping the code as simple as possible I would appreciate it as Ive been stuck for a while with this problem.
Many thanks
simsy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package paratrooper1;
//class libraries
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.JScrollPane;
import java.awt.*;
import javax.swing.JProgressBar;
/**
*
* @author Paul
*/
public class Paratrooper1 extends Applet implements ActionListener{
//variables
String name;
String answer1getnumber;
String block2;
JProgressBar progresshealth;
TextField userinput;
TextArea mytextarea;
JScrollPane myscrollpane;
Button Enterbutton;
public void init() {
setLayout(null);
setBackground(Color.BLUE);
userinput = new TextField("");
userinput.setBounds(110,550,180,20);
add(userinput);
Enterbutton = new Button("Enter");
Enterbutton.setBounds(290,550,60,20);
add(Enterbutton);
mytextarea = new TextArea("",80, 50,1);
mytextarea.setBounds(60,400,350,140);
mytextarea.setEditable(false);
mytextarea.setFont(new Font("Serif", Font.BOLD, 14));
// mytextarea.setLineWrap(true);
// mytextarea.setWrapStyleWord(true);
// mytextarea.add(myscrollpane);
JScrollPane myscrollpane = new JScrollPane(mytextarea);
add(myscrollpane);
add(mytextarea);
progresshealth = new JProgressBar(500,500);
progresshealth.setValue(0);
progresshealth.setMinimum(0);
progresshealth.setMaximum(100);
//progresshealth.setStringPainted(true);
add(progresshealth);
progresshealth.setVisible(true);
//I would like to add text paragraph by paragraph but settext does not allow for this???nor insert
//append..ie.mytextarea.append("string");
//Start game
//I WOULD LIKE TO DISPLAY THIS FIRST AND WAIT FOR USER TO INPUT THERE NAME
//CURRENTLY BLOCK 1 AND 2 ARE SHOWING AS WELL
mytextarea.setText(" Paratrooper \n\nPlease enter your name");
name=userinput.getText();
// if false wait;
// if true continue;
//next block of code to run after enter name
//SHOW AFTER NAME INPUT
//block1
mytextarea.append("\nPlease enter the following for your personalised adventure\nEnter a number below 20");
userinput.getText();//= answer1getnumber int;
answer1getnumber=userinput.getText();
//SHOW AFTER ENTER NUMBER.ETC.ETC.
// block2
mytextarea.append("\nNext block of code to run\nNext block of code to run\nask question");
//mytextarea.setCaretPosition(mytextarea.getDocument().getLength());
setSize(600,600);
Enterbutton.addActionListener(this);
// TODO start asynchronous download of heavy resources
}
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void actionPerformed(ActionEvent evt) {
if(evt.getSource()== Enterbutton){
if (mytextarea.getText() == name);
mytextarea.setText(mytextarea.getText()+"\n\nWelcome to Paratrooper "+userinput.getText());
userinput.setText("");
}
else
{
if (userinput.getText() == answer1getnumber);
userinput.setText("");
}
// else etc.etc
// TODO overwrite start(), stop() and destroy() methods
}
}