我目前正在开发一款游戏,可以教孩子们某种编码。我的问题是我只能在文本区域中“访问”或使用第一个String。我想实现一种解决方案,该解决方案可以将textarea作为游戏角色的动作来运行。
public void show() {
spriteBatch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("images/player.png"));
sprite = new Sprite(texture);
camera = new OrthographicCamera();
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.update();
//player = new playerClass(1, 1);
gameMap = new TiledGameMap();
textInputField = new TextInputField();
sprite.setSize(32,32);
sprite.setX(2*32);
sprite.setY(2*32);
touch.set(sprite.getX(),sprite.getY());
textInputField.textButton.addListener(new ClickListener(){
@Override
public void clicked(InputEvent e, float x, float y){
for (String line : textInputField.textArea.getText().split("\\n")){
textInputField.textButton.setText("Compiling!");
String textStr = textInputField.textArea.getText();
Matcher matcher = Pattern.compile("\\d+").matcher(textStr);
matcher.find();
int i = Integer.valueOf(matcher.group());
textStr = line;
if(line.equals("walk("+ i + ");")) {
touch.set(sprite.getX()+i*32,sprite.getY());
System.out.println(i);
}
if(line.equals("walk -"+ i)) {
touch.set(sprite.getX()+-i*32,sprite.getY());
System.out.println(i);
}