i used showtext code in my world but look like common
if i press A will be show the next text but always fail


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | 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 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 ); } |
1 | incompatibles types : java.lang.String cannot be converted to javalang.String[] |
1 | incompatibles types : java.lang.String cannot be converted to javalang.String[] |
1 2 3 4 5 6 7 | // example String[] dialog = { "Press A for next text" , "Press H to howl" }; Dialogue dialogue = new Dialogue(dialog); |
1 2 3 4 | if (!getObjects(Dialogue. class ).isEmpty() && "a" .equals(Greenfoot.getKey()) { ((Dialogue)getObjects(Dialogue. class ).get( 0 )).nextText(); } |
1 2 3 4 5 6 7 8 9 10 | 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()); } } |
1 2 3 | World pgh = new PlaygameHome(); pgh.removeObjects(pgh.getObjects(Dialogue. class )); Greenfoot.setWorld(pgh); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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 )) { } } } |