i used showtext code in my world but look like common
if i press A will be show the next text but always fail
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class PlaygameHome here.
*
* @author (Muhamad Ariq Rasyid)
* @version (1.0 19 Feb 2021)
*/
public class PlaygameHome extends World
{
/**
* Constructor for objects of class PlaygameHome.
*
*/
public PlaygameHome()
{
// Create a new world with 800x600 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
/**
* NPC
*/
//WolfLink
WolfLink wolfLink = new WolfLink();
addObject(wolfLink,419,68);
//Cerberus
Cerberus cerberus = new Cerberus();
addObject(cerberus,704,525);
Werewolf werewolf = new Werewolf();
addObject(werewolf,33,533);
Ryuza ryuza = new Ryuza();
addObject(ryuza,451,535);
/**
* Dens
*/
//Player home
Den den = new Den();
addObject(den,65,67);
//Pack Den
Den2 den2 = new Den2();
addObject(den2,764,38);
/**
* Player
*/
//Player
Player player = new Player();
addObject(player,291,163);
/**
* MapsAttribute
*/
//River
River river = new River();
addObject(river,238,564);
//Stone
Stone stone = new Stone();
addObject(stone,386,577);
Stone2 stone2 = new Stone2();
addObject(stone2,384,534);
Stone3 stone3 = new Stone3();
addObject(stone3,351,509);
Stone4 stone4 = new Stone4();
addObject(stone4,304,508);
Stone5 stone5 = new Stone5();
addObject(stone5,254,510);
Stone6 stone6 = new Stone6();
addObject(stone6,205,513);
Stone7 stone7 = new Stone7();
addObject(stone7,155,517);
Stone9 stone9 = new Stone9();
addObject(stone9,106,513);
Stone10 stone10 = new Stone10();
addObject(stone10,86,550);
Stone11 stone11 = new Stone11();
addObject(stone11,86,580);
//Trees
Pine1 pine1 = new Pine1();
addObject(pine1,109,19);
Pine2 pine2 = new Pine2();
addObject(pine2,13,48);
//Flatfrom
Flatfrom1 flatfrom1 = new Flatfrom1();
addObject(flatfrom1,24,582);
Flatfrom2 flatfrom2 = new Flatfrom2();
addObject(flatfrom2,452,582);
Flatfrom3 flatfrom3 = new Flatfrom3();
addObject(flatfrom3,701,578);
Flatfrom4 flatfrom4 = new Flatfrom4();
addObject(flatfrom4,416,21);
//WolfSatue
WolfStatue wolfStatue = new WolfStatue();
addObject(wolfStatue,426,254);
//dialog
addObject(new Label("",60),24,513);
}
}
public Dialogue(String text)
{
GreenfootImage img = new GreenfootImage (text.length()*20,50);
img.drawString(text, 30, 20);
setImage(img);
}
public void setText(String text)
{
GreenfootImage img = getImage();
img.clear();
img.drawString (text, 30, 20);
}private String[] dialogue;
private int index;
public Dialogue(String[] dialogue)
{
this.dialogue = dialogue;
index = 0;
setText();
}
private void setText()
{
setImage(new GreenfootImage(dialogue[index], 28, Color.BLACK, Color.WHITE));
}
public void nextText()
{
if (++index < dialogue.length) setText();
else getWorld().removeObject(this);
}incompatibles types : java.lang.String cannot be converted to javalang.String[]
incompatibles types : java.lang.String cannot be converted to javalang.String[]
// example
String[] dialog =
{
"Press A for next text",
"Press H to howl"
};
Dialogue dialogue = new Dialogue(dialog);if (!getObjects(Dialogue.class).isEmpty() && "a".equals(Greenfoot.getKey())
{
((Dialogue)getObjects(Dialogue.class).get(0)).nextText();
} public void DigimonandPokemon() {
String input = Greenfoot.ask("Rayquaza : 'Are You Sure Want To Digimon And Pokemon World, Alpha?'");
if ("yes".equals(input)) {
if (getWorld() instanceof PlaygameHome)
((PlaygameHome)getWorld()).Back.stop();
Greenfoot.setWorld (new DigimonandPokemon());}
else
if("no".equals(input)){
Greenfoot.setWorld(new PlaygameHome()); }
}World pgh = new PlaygameHome(); pgh.removeObjects(pgh.getObjects(Dialogue.class)); Greenfoot.setWorld(pgh);
public class WolfStatue extends Freature
{ String[] dialog3 =
{
"The Greatest of Alpha\n Blizzard Wolf Smith."
};
/**
* Act - do whatever the WolfStatue wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{touch();
}
public void touch()
{if(isTouching(Player.class))
{
}
}
}