Zdravim...zadam napr . "vychod" ...do arraylistu by malo ulozit vychod...
ten vychod po stlaceni enter vypise kedze som dal do addP este System.out...ale potom hed zadam historia tak nevypise cely list
cely kod triedy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package textovka;
import java.util.ArrayList;
/**
*
* @author Roman Málik
*/
public class History {
private ArrayList<String> prikazyH;
public History(){
prikazyH = new ArrayList<String>();
}
public void addP(String ar) {
prikazyH.add(ar);
System.out.println(ar);
}
public void returnArray() {
if (prikazyH.size() == 0) System.out.println("prazdna");
else {
for (int i=0;i<prikazyH.size();i++)
System.out.println(prikazyH.get(i));
}
}
public void clear(){
prikazyH.clear();
}
public void Save() {
}
public void Load() {
}
public void setParams(String arg0) {
}
}
toto je trieda reprezentujuca prikaz HISTORIA...cize tento ked zadam ma sa vypisat historia
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package commands;
import TextGame.Command;
import TextGame.Game;
import TextGame.GameState;
import textovka.GameImpl;
import textovka.History;
/**
*
* @author dEVIANT
*/
public class Historia implements Command {
private String name;
private String params;
public Historia() {
name = "HISTORIA";
}
public GameState execute(Game game) {
History hi = new History();
hi.returnArray();
return GameImpl.stav = GameState.PLAYING;
}
public void setParams(String arg0) {
this.params = arg0;
}
public String getParams() {
return params;
}
public String getName() {
return name;
}
public String getDescription() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
no a v hrenej slučke GameImpl to mám takto
public void play() {
createRooms();
inventar = new BackpackImpl();
while( stav == GameState.PLAYING )
{
currentRoom.show();
System.out.print("> ");
Scanner reader = new Scanner( System.in );
String line = reader.nextLine();
line=line.trim();
line=line.toUpperCase();
History historia = new History();
historia.addP(line);
Parser prikaz = new Parser(this);
prikaz.getCommand(line);
if(stav == GameState.GAMEOVER){
System.out.println("Pre zobrazenie príkazov napíš PRIKAZY");
GameImpl hra = new GameImpl();
hra.play();
}
vobec tomu nechápem prečo to nejde...tak isto mám urobený vypis predmetov v miestnosti alebo inventari...a funguje...ale toto nie...
ten Parser tam sluzi na vyhodnotenie prikazov...ak sa jedna o "historia" tak zavola metodu execute triedy Historia...ktora by mala vykonat metodu returnArray triedy History...