AutoSaveController.java 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package ui.controller;
  2. import ui.model.Model;
  3. public class AutoSaveController {
  4. private Model MODEL;
  5. private int max = Integer.MAX_VALUE;
  6. private int numberOfSaves = 20;
  7. private int currentSave;
  8. private int count = 0;
  9. private boolean isAllowed = false;
  10. public AutoSaveController(Model model) {
  11. this.MODEL = model;
  12. }
  13. public void increaseAutoSaveNr() {
  14. currentSave = MODEL.getAutoSaveNr() + 1;
  15. if (count < currentSave) {
  16. count = currentSave;
  17. }
  18. if (numberOfSaves == count) {
  19. isAllowed = true;
  20. }
  21. if (currentSave > max) {
  22. currentSave = 0;
  23. }
  24. MODEL.setAutoSaveNr(currentSave);
  25. }
  26. public void decreaseAutoSaveNr() {
  27. currentSave = MODEL.getAutoSaveNr() - 1;
  28. // if (currentSave < 0) {
  29. // currentSave = max;
  30. // }
  31. MODEL.setAutoSaveNr(currentSave);
  32. }
  33. public int getAutoSaveNr() {
  34. return MODEL.getAutoSaveNr();
  35. }
  36. public boolean allowed() {
  37. return isAllowed;
  38. }
  39. }