RecklessDarph

School

May 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package jumpingalien.model;
  2.  
  3. import java.util.Collection;
  4. import java.util.HashSet;
  5. import java.util.Set;
  6.  
  7. public class School {
  8. public School(World world) throws Exception{
  9. if(world.SchoolSet.size()==10) {throw new Exception();}
  10. else{setWorld(world);}
  11. }
  12.  
  13. public void removeAsSlime(Slime slime) throws Exception {
  14. if(slime.getSchool()==null || !(hasAsSlime(slime))) {throw new Exception();}//FIXME modelException lukt niet
  15. else{
  16. School.remove(slime);
  17. slime.setSchool(null);
  18. }
  19. }
  20.  
  21. public Set<Object> School = new HashSet<Object>();
  22. /**
  23. *
  24. * @param slime
  25. * @post...
  26. * |School.contains(slime)
  27. */
  28. public void AddAsSlime(Slime slime)throws Exception {
  29. if((hasAsSlime(slime))|| slime.IdSet.contains(slime.getID())) {throw new Exception();}
  30. School.add(slime);
  31.  
  32. }
  33. public void switchSchool(Slime slime) {
  34. // TODO Auto-generated method stub
  35. }
  36.  
  37. public Collection<? extends Slime> getAllSlimes() {
  38. return null;
  39. }
  40.  
  41. /**
  42. * @return
  43. * |School.contains(slime)
  44. */
  45. public boolean hasAsSlime(Slime slime) {return School.contains(slime);}
  46.  
  47. /**
  48. * @post..
  49. * |new.World=null
  50. */
  51. public void terminateSchool() {setWorld(null);}
  52.  
  53. private World currentWorld;
  54. /**
  55. *
  56. * @param world
  57. * @post..
  58. * |new.World=world
  59. */
  60. public void setWorld(World world) {
  61. currentWorld=world;
  62.  
  63. }
  64.  
  65. public void removeWorld() {
  66. currentWorld.removeGameObject(this);
  67. setWorld(null);
  68.  
  69. }
  70.  
  71.  
  72. }
Add Comment
Please, Sign In to add comment