问题描述
最近在学array,在作业中碰到一个问题:在arrayUI的class里,为什么complie之后说在:intposition=game.getEnemies().getPosition();"找不到符号符号:方法getPosition()位置:类Enemy[]"求高人指点,并给出解决办法。这是classgame里的代码:publicclassGame{privateUIui;privatePlayerplayer;privateExitexit;//Deletethese//privateItemitem1;//privateItemitem2;//privateItemitem3;//privateEnemyenemy1;//privateEnemyenemy2;privateItem[]item;privateEnemy[]enemy;publicGame(UIui){this.ui=ui;ui.setGame(this);Modemode=ui.readMode();intnumItems=ui.readNumItems();item=newItem[numItems];for(inti=0;i<numItems;i++)item[i]=ui.readItem();/*item1=ui.readItem();item2=ui.readItem();item3=ui.readItem();*/if(mode==Mode.HARD){intnumEnemies=ui.readNumEnemies();enemy=newEnemy[numEnemies];for(inti=0;i<numEnemies;i++)enemy[i]=ui.readEnemy();/*enemy1=ui.readEnemy();enemy2=ui.readEnemy();*/}exit=ui.readExit();player=ui.readPlayer();}publicPlayergetPlayer(){returnplayer;}publicExitgetExit(){returnexit;}publicItem[]getItems(){returnitem;}publicEnemy[]getEnemies(){if(enemy==null)returnnull;elsereturnenemy;}publicvoidplay(){ui.updateScreen();while(!isOver()){turn();ui.updateScreen();}if(won())ui.win();elseui.lose();}publicbooleanisOver(){return!player.isAlive()||won();}publicbooleanitemsCollected(){booleancheckItems=true;for(inti=0;i<item.length;i++){if(item[i].exists()){checkItems=false;}}returncheckItems;//return!(item1.exists()||item2.exists()||item3.exists());}publicbooleanwon(){returnexit.isTaken();}publicvoidturn(){Movemove=ui.nextMove();if(move==Move.LEFT||move==Move.RIGHT){player.move(move.dx);if(player.isAlive()&&exit.found(player)&&itemsCollected())exit.take();}elseif(move==Move.DOWN){for(inti=0;i<item.length;i++){player.pickup(item[i]);}//player.pickup(item1);//player.pickup(item2);//player.pickup(item3);}if(enemy!=null){for(inti=0;i<enemy.length;i++){enemy[i].attack(player);}//enemy1.attack(player);//enemy2.attack(player);}}publicStringtoString(){Strings="";for(inti=0;i<item.length;i++){s+=space(item[i]);}if(enemy!=null){for(inti=0;i<enemy.length;i++){s+=space(enemy[i]);}}s+=space(player);if(itemsCollected())s+=space(exit);returns;}privateStringspace(Objecto){returno+"";}}这是ArrayUI的代码:publicclassArrayUIextendsUI{publicstaticvoidmain(String[]args){newGame(newArrayUI()).play();}privateGamegame;privatechar[]output;publicArrayUI(){output=newchar[15];//Constructor.Fillinmissingcode}publicvoidupdateScreen(){outputGround();outputPlayer();outputExit();outputEnemies();outputItems();System.out.println(output);}publicvoidsetGame(Gamegame){super.setGame(game);this.game=game;}publicchar[]getOutput(){returnoutput;}privatevoidoutputGround(){for(inti=0;i<15;i++){output[i]='_';}}privatevoidoutputPlayer(){intposition=game.getPlayer().getPosition();output[position]='P';}privatevoidoutputExit(){intposition=game.getExit().getPosition();output[position]='X';}privatevoidoutputEnemies(){intposition=game.getEnemies().getPosition();output[position]='e';}privatevoidoutputItems(){intposition=game.getItems().getPosition();output[position]='I';}//public//Addmissingcode}