package klassid; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.PrintWriter; public class Proov6 { public static void main(String[] args) throws Exception{ String failinimi="seisund.dat"; Takisti t1=new Takisti(220); t1.uusPinge(5); EnergiaArvutaja mootja=new EnergiaArvutaja(t1); BufferedReader klaver=new BufferedReader(new InputStreamReader(System.in)); if(new File(failinimi).exists()){ ObjectInputStream ois=new ObjectInputStream(new FileInputStream(failinimi)); t1=(Takisti)ois.readObject(); ois.close(); } boolean veel=true; while(veel){ mootja.lisaEnergia(1); System.out.println(mootja + " "+ t1.kysiVoimsus()); if(klaver.ready()){ String rida=klaver.readLine(); if(rida.equals("+")){t1.uusPinge(t1.kysiPinge()+1);} if(rida.equals("-")){t1.uusPinge(t1.kysiPinge()-1);} if(rida.equals("")){veel=false;} } Thread.sleep(1000); } ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(failinimi)); oos.writeObject(t1); oos.close(); } }