Advertisement
RedVinck

Facade 4.0

May 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.23 KB | None | 0 0
  1. package jumpingalien.facade;
  2.  
  3.  
  4. import java.util.Collection;
  5. import java.util.Set;
  6. import be.kuleuven.cs.som.annotate.Raw;
  7. import jumpingalien.facade.IFacade;
  8. //import jumpingalien.internal.gui.painters.GameObjectPainter;
  9. //import jumpingalien.internal.gui.sprites.JumpingAlienSprites;
  10. import jumpingalien.util.ModelException;
  11. import jumpingalien.util.Sprite;
  12. import jumpingalien.model.*;
  13.  
  14.  
  15.  
  16. public class Facade implements IFacade{
  17.  
  18.     @Override
  19.     public boolean isTeamSolution() {
  20.         return true;
  21.     }
  22.  
  23.     @Override
  24.     public boolean isLateTeamSplit() {
  25.         //To good of a team
  26.         return false;
  27.     }
  28.  
  29.     @Override
  30.     public boolean hasImplementedWorldWindow() {
  31.         return true;
  32.     }
  33.  
  34.     @Override
  35.     public Mazub createMazub(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  36.         try {Mazub alien = new Mazub(pixelLeftX, pixelBottomY, sprites); return alien;}
  37.         catch (Exception e) {throw new ModelException(e);}
  38.     }
  39.  
  40.     @Override
  41.     public double[] getActualPosition(Mazub alien) throws ModelException {
  42.         return alien.getActualPosition();
  43.     }
  44.  
  45.     @Override
  46.     public void changeActualPosition(Mazub alien, double[] newPosition) throws ModelException {
  47.          try {alien.changeActualPosition(newPosition);
  48.            
  49.         } catch (Exception e) {
  50.             throw new ModelException(e);
  51.         }
  52.     }
  53.  
  54.     @Override
  55.     public int[] getPixelPosition(Mazub alien) throws ModelException {
  56.         return alien.getPixelPosition();
  57.     }
  58.  
  59.     @Override
  60.     public int getOrientation(Mazub alien) throws ModelException {
  61.         return alien.getOrientation();
  62.     }
  63.    
  64.     public Sprite getCurrentSprite(Mazub alien) throws ModelException {
  65.         return alien.getCurrentSprite();
  66.     }
  67.  
  68.     @Override
  69.     public double[] getVelocity(Mazub alien) throws ModelException {
  70.         return alien.getVelocity();
  71.     }
  72.  
  73.     @Override
  74.     public double[] getAcceleration(Mazub alien) throws ModelException {
  75.         return alien.getAcceleration();
  76.     }
  77.  
  78.     @Override
  79.     public boolean isMoving(Mazub alien) throws ModelException {
  80.          return alien.isMoving();
  81.     }
  82.  
  83.     @Override
  84.     public void startMoveLeft(Mazub alien) throws ModelException {
  85.          if(alien.isMoving()== false) {
  86.                 ((Entity)alien).startMoveLeft();}
  87.          else if(alien.isMoving()==true){throw new ModelException("Already Moving");}
  88.     }
  89.  
  90.     @Override
  91.     public void startMoveRight(Mazub alien) throws ModelException {
  92.         if(alien.isMoving()== false) {
  93.             alien.startMoveRight();}
  94.         else if(alien.isMoving()==true) {throw new ModelException("Already Moving");}
  95.     }
  96.  
  97.     @Override
  98.     public void endMove(Mazub alien) throws ModelException {
  99.         if(alien.isMoving()==true) {alien.endMove();}
  100.         else if(alien.isMoving()==false){throw new ModelException("Already Stopped Ducking");}
  101.     }
  102.  
  103.     @Override
  104.     public boolean isJumping(Mazub alien) throws ModelException {
  105.          return alien.isJumping();
  106.     }
  107.  
  108.     @Override
  109.     public void startJump(Mazub alien) throws ModelException {//Die exception moet denk ik in Mazub zelf. Zelfde in running enz
  110.         if(alien.isJumping() == false) {alien.startJump();}
  111.         else {throw new ModelException("Already Jumping");}
  112.     }
  113.  
  114.     @Override
  115.     public void endJump(Mazub alien) throws ModelException {
  116.         if(alien.isJumping() ==true) {alien.endJump();}
  117.         else {throw new ModelException("Already Stopped Jumping");}
  118.     }
  119.  
  120.     @Override
  121.     public boolean isDucking(Mazub alien) throws ModelException {
  122.          return alien.isDucking();
  123.     }
  124.  
  125.     @Override
  126.     public void startDuck(Mazub alien) throws ModelException {
  127.         if(alien.isDucking() ==false) {alien.startDucking();}
  128.     }
  129.  
  130.     @Override
  131.     public void endDuck(Mazub alien) throws ModelException {
  132.         alien.endDucking();
  133.     }
  134.  
  135.     @Override
  136.     public World createWorld(int tileSize, int nbTilesX, int nbTilesY, int[] targetTileCoordinate,
  137.             int visibleWindowWidth, int visibleWindowHeight, int... geologicalFeatures) throws ModelException {
  138.          World world= new World(tileSize, nbTilesX, nbTilesY,  targetTileCoordinate, visibleWindowWidth, visibleWindowHeight, geologicalFeatures );
  139.          return world;
  140.     }
  141.  
  142.     @Override
  143.     public void terminateWorld(World world) throws ModelException {
  144.         world.terminateWorld();  
  145.     }
  146.  
  147.     @Override
  148.     public int[] getSizeInPixels(World world) throws ModelException {
  149.         return world.getSizeInPixels();
  150.     }
  151.  
  152.     @Override
  153.     public int getTileLength(World world) throws ModelException {
  154.         return world.getTileLength();
  155.     }
  156.  
  157.     @Override
  158.     public int getGeologicalFeature(World world, int pixelX, int pixelY) throws ModelException {
  159.         return world.getGeologicalFeatures(pixelX, pixelY);
  160.        
  161.     }
  162.  
  163.     @Override
  164.     public void setGeologicalFeature(World world, int pixelX, int pixelY, int geologicalFeature) throws ModelException {
  165.         try{world.setGeologicalFeatures(pixelX, pixelY, geologicalFeature);}
  166.         catch(Exception e){throw new ModelException(e);}
  167.     }
  168.  
  169.     @Override
  170.     public int[] getVisibleWindowDimension(World world) throws ModelException {
  171.         try{return world.getVisibleWindowDimension();}
  172.         catch(Exception e){throw new ModelException(e);}
  173.     }
  174.    
  175.     public int[] getVisibleWindowPosition(World world) throws ModelException {
  176.         try{return world.getVisibleWindowsPosition();}
  177.         catch(Exception e){throw new ModelException(e);}
  178.     }
  179.  
  180.     @Override
  181.     public boolean hasAsGameObject(Object object, World world) throws ModelException {
  182.         try{return world.hashAsGameObject(object);}
  183.         catch(Exception e){throw new ModelException(e);}
  184.     }
  185.  
  186.     @Override
  187.     public Set<? extends Object> getAllGameObjects(World world) throws ModelException {
  188.           try{return world.getAllGameObjects();}
  189.           catch(Exception e){throw new ModelException(e);}
  190.     }
  191.  
  192.     @Override
  193.     public Mazub getMazub(World world) throws ModelException {
  194. //        //world.getGameObjects();//FIXME zet in vq\ariabeler
  195. //        Mazub CurrentMazub = null;
  196. //        int i =0;
  197. //        return CurrentMazub;
  198. //      Object[] ObjectArray = (world).getGameObjects().toArray(new Object[(world).getGameObjects().size()]);
  199. //      while(i<ObjectArray.length && false == (CurrentMazub instanceof Mazub )){
  200. //              CurrentMazub=(Mazub) ObjectArray[i];
  201. //          i++;}
  202.         try{return world.getMazub();}
  203.         catch(Exception e){throw new ModelException(e);}
  204.     }
  205.  
  206.     @Override
  207.     public void addGameObject(Object object, World world) throws ModelException {
  208.         try{world.addGameObject((Entity)object,world);}
  209.         catch(Exception e){throw new ModelException(e);}
  210.     }
  211.  
  212.     @Override
  213.     public void removeGameObject(Object object, World world) throws ModelException {
  214.         try{world.removeGameObject((Entity)object);world.terminatedGameObject((Entity)object);}
  215.         catch(Exception e){throw new ModelException(e);}
  216.     }
  217.  
  218.     @Override
  219.     public int[] getTargetTileCoordinate(World world) throws ModelException {
  220.          return world.getTargetTileCoordinate();
  221.     }
  222.  
  223.     @Override
  224.     public void setTargetTileCoordinate(World world, int[] tileCoordinate) throws ModelException {
  225.          world.setTargetTileCoordinate(tileCoordinate);
  226.     }
  227.  
  228.     @Override
  229.     public void startGame(World world) throws ModelException {
  230.         try{world.startGame();}
  231.         catch(Exception e){throw new ModelException(e);}
  232.     }
  233.  
  234.     @Override
  235.     public boolean isGameOver(World world) throws ModelException {
  236.         try{return world.isGameOver();}
  237.         catch(Exception e){throw new ModelException(e);}
  238.     }
  239.  
  240.     @Override
  241.     public boolean didPlayerWin(World world) throws ModelException {
  242.         try{return world.DidPlayerWin();}
  243.         catch(Exception e){throw new ModelException(e);}
  244.     }
  245.  
  246.     @Override
  247.     public void advanceWorldTime(World world, double dt) throws ModelException {
  248.         try {
  249.             world.advancedTime(dt);
  250.         } catch (Exception e) {
  251.             Exception d = e;
  252.             // TODO Auto-generated catch block
  253.             throw new ModelException(d);
  254.         }
  255.        
  256.     }
  257.  
  258.    
  259.     @Override
  260.     public Set<School> getAllSchools(World world) throws ModelException {
  261.          try{return world.getAllSchools();}
  262.          catch(Exception e){throw new ModelException(e);}
  263.     }
  264.     /*
  265.      *************
  266.      *GameObjects*
  267.      *************
  268.      */
  269.    
  270.  
  271.     @Override
  272.     public void terminateGameObject(Object gameObject) throws ModelException {
  273.          try{if(((Entity)gameObject).getWorld() != null){((Entity)gameObject).getWorld().terminatedGameObject((Entity)gameObject);}
  274.              else {((Entity)gameObject).terminateGameObject();}}
  275.          catch(Exception e){throw new ModelException(e);}
  276.     }
  277.  
  278.     @Override
  279.     public boolean isTerminatedGameObject(Object gameObject) throws ModelException {
  280.          try{if(((Entity)gameObject).getWorld() != null&&((Entity)gameObject).getWorld().isTerminatedGameObject(gameObject)) {return true;}
  281.          else {
  282.              if(((Entity)gameObject).isTerminatedGameObject()){return true;}else {return false;}}
  283.          }
  284.          catch(Exception e){throw new ModelException(e);}
  285.     }
  286.  
  287.     @Override
  288.     public boolean isDeadGameObject(Object gameObject) throws ModelException {
  289.          try{return ((Entity)gameObject).isDeadGameObject();}
  290.          catch(Exception e){throw new ModelException(e);}
  291.     }  
  292.  
  293.     @Override
  294.     public double[] getActualPosition(Object gameObject) throws ModelException {
  295.          try{return ((Entity)gameObject).getActualPosition();}
  296.          catch(Exception e){throw new ModelException(e);}
  297.     }
  298.  
  299.     @Override
  300.     public void changeActualPosition(Object gameObject, double[] newPosition) throws ModelException {
  301.          try{((Entity)gameObject).changeActualPosition(newPosition);}
  302.          catch(Exception e){throw new ModelException(e);}
  303.        
  304.     }
  305.  
  306.     @Override
  307.     public int[] getPixelPosition(Object gameObject) throws ModelException {
  308.          try{return ((Entity)gameObject).getPixelPosition();}
  309.          catch(Exception e){throw new ModelException(e);}
  310.        
  311.     }
  312.  
  313.     @Override
  314.     public int getOrientation(Object gameObject) throws ModelException {
  315.         try{return ((Entity)gameObject).getOrientation();}
  316.         catch(Exception e){throw new ModelException(e);}
  317.     }
  318.  
  319.     @Override
  320.     public double[] getVelocity(Object gameObject) throws ModelException {
  321.         try{return ((Entity)gameObject).getVelocity();}
  322.         catch(Exception e){throw new ModelException(e);}
  323.     }
  324.  
  325.     @Override
  326.     public double[] getAcceleration(Object gameObject) throws ModelException {
  327.          try{return ((Entity)gameObject).getAcceleration();}
  328.          catch(Exception e){throw new ModelException(e);}
  329.     }
  330.  
  331.     @Override
  332.     public World getWorld(Object object) throws ModelException {
  333.         try{return ((Entity)object).getWorld();}
  334.         catch(Exception e){throw new ModelException(e);}
  335.        
  336.     }
  337.  
  338.     @Override
  339.     public int getHitPoints(Object object) throws ModelException {
  340.          try{return ((Entity)object).getHitpoint();}
  341.          catch(Exception e){throw new ModelException(e);}
  342.     }
  343.  
  344.     @Override
  345.     public Sprite[] getSprites(Object gameObject) throws ModelException {
  346.          try{return ((Entity)gameObject).getSprites();}
  347.          catch(Exception e){throw new ModelException(e);}
  348.     }
  349.    
  350.     @Override
  351.     public Sprite getCurrentSprite(Object gameObject)throws ModelException{
  352.         try{return ((Entity)gameObject).getCurrentSprite();}
  353.         catch(Exception e){throw new ModelException(e);}
  354.     }
  355.    
  356.    
  357. // World AdvencedTime    
  358.     @Override
  359.     public void advanceTime(Object gameObject, double dt) throws ModelException {
  360.         try {
  361.             ((Entity)gameObject).advanceTime(dt);
  362.         } catch (Exception e) {
  363.             // TODO Auto-generated catch block
  364.             throw new ModelException(e);
  365.         }
  366.        
  367.     }
  368.    
  369. // Sneezewort
  370.    
  371.     @Override
  372.     public Sneezewort createSneezewort(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  373.         try {Sneezewort Sneeze=new Sneezewort(pixelLeftX, pixelBottomY, sprites);return Sneeze;}
  374.         catch (Exception e) {throw new ModelException(e);}
  375.        
  376.     }
  377.    
  378.  // Skullcab
  379.  
  380.     @Override
  381.     public Skullcab createSkullcab(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  382.         try {Skullcab Skull=new Skullcab(pixelLeftX, pixelBottomY, sprites);return Skull;}
  383.         catch (Exception e) {throw new ModelException(e);}
  384.        
  385.     }
  386.    
  387. // Slime Facade
  388.  
  389.     @Override
  390.     public Slime createSlime(long id, int pixelLeftX, int pixelBottomY, School school, Sprite... sprites)throws ModelException {
  391.         try {Slime slime=new Slime(id, pixelLeftX, pixelBottomY, school, sprites); return slime;}
  392.         catch (Exception e) {throw new ModelException(e);}
  393.     }
  394.    
  395.     @Override
  396.     public long getIdentification(Slime slime) throws ModelException {
  397.         try {return slime.getID();}
  398.         catch (Exception e) {throw new ModelException(e);}
  399.     }
  400.  
  401.     @Override
  402.     public void cleanAllSlimeIds() {
  403.         Slime.CleanIdSet();
  404.     }
  405.    
  406.  // School Facade
  407.  
  408.     @Override
  409.     public School createSchool(World world) throws ModelException {
  410.         try {School school= new School(world);return school;}
  411.         catch (Exception e) {throw new ModelException(e);}
  412.     }
  413.  
  414.     @Override
  415.     public void terminateSchool(School school) throws ModelException {
  416.         try {school.terminateSchool();}
  417.         catch (Exception e) {throw new ModelException(e);}
  418.        
  419.     }
  420.  
  421.     @Override
  422.     public boolean hasAsSlime(School school, Slime slime) throws ModelException {
  423.         try {return school.hasAsSlime(slime);}
  424.         catch (Exception e) {throw new ModelException(e);}
  425.     }
  426.  
  427.     @Override
  428.     public Collection<? extends Slime> getAllSlimes(School school) {
  429.         try {return school.getAllSlimes();}
  430.         catch (Exception e) {throw new ModelException(e);}
  431.     }
  432.  
  433.     @Override
  434.     public void addAsSlime(School school, Slime slime) throws ModelException {
  435.         try {school.AddAsSlime(slime);}
  436.         catch (Exception e) {throw new ModelException(e);}
  437.     }
  438.  
  439.     @Override
  440.     public void removeAsSlime(School school, Slime slime) throws ModelException {
  441.         try {school.removeAsSlime(slime);}
  442.         catch (Exception e) {throw new ModelException(e);}
  443.     }
  444.  
  445.     @Override
  446.     public void switchSchool(School newSchool, Slime slime) throws ModelException {
  447.         try {newSchool.switchSchool(slime);}
  448.         catch (Exception e) {throw new ModelException(e);}
  449.     }
  450.  
  451.     @Override
  452.     public School getSchool(Slime slime) throws ModelException {
  453.         try {return slime.getSchool();}
  454.         catch (Exception e) {throw new ModelException(e);}
  455.     }
  456.    
  457. //¨Shark Facade
  458.    
  459.     public Shark createShark(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  460.        
  461.         try {Shark shark=new Shark(pixelLeftX, pixelBottomY, sprites);return shark;
  462.         } catch (Exception e) {throw new ModelException(e);}
  463.     }
  464.  
  465.     @Override
  466.     public Sprite[] getSprites(Mazub alien) throws ModelException {
  467.         // TODO Auto-generated method stub
  468.         return alien.getSprites();
  469.     }
  470.  
  471. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement