Guest User

Untitled

a guest
Jan 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.io.Serializable;
  2.  
  3. public class Game implements Serializable{
  4.  
  5. private static final long serialVersionUID = -4795536311274486893L;
  6. protected int SHOT_SPEED;
  7. protected int PLAYER_SPEED;
  8. Player player;
  9. ArrayList<SpaceObject> objects;
  10. int level, score;
  11. Dimension resolution;
  12. and so on...
  13.  
  14. public boolean saveGame(Game game) {
  15. try {
  16. FileOutputStream fileOut = new FileOutputStream(defaultDataName+".ser");
  17. ObjectOutputStream out = new ObjectOutputStream(fileOut);
  18.  
  19. out.writeObject(game);
  20.  
  21. out.close();
  22. fileOut.close();
  23. return true;
  24. }
  25. catch (IOException i) {
  26. return false;
  27. }
  28.  
  29. }
  30.  
  31. public Game loadGame() throws IOException {
  32. if (readRawData(defaultDataName) == "") throw new IOException("Data was deleted");
  33. Game game = null;
  34. try {
  35. FileInputStream fileIn = new FileInputStream(defaultDataName+".ser");
  36. ObjectInputStream in = new ObjectInputStream(fileIn);
  37.  
  38. game = (Game) in.readObject();
  39.  
  40. in.close();
  41. fileIn.close();
  42. }
  43. catch (ClassNotFoundException e) {
  44. throw new IOException("Class not Found: " + e.getMessage());
  45. }
  46. return game;
  47. }
Add Comment
Please, Sign In to add comment