Advertisement
RecklessDarph

Facade BackUp

Jul 10th, 2019
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 15.29 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.                 try {
  87.                     ((Entity)alien).startMoveLeft();
  88.                 } catch (Exception e) {
  89.                     // TODO Auto-generated catch block
  90.                     e.printStackTrace();
  91.                 }}
  92.          else if(alien.isMoving()==true){throw new ModelException("Already Moving");}
  93.     }
  94.  
  95.     @Override
  96.     public void startMoveRight(Mazub alien) throws ModelException {
  97.         if(alien.isMoving()== false) {
  98.             try {
  99.                 alien.startMoveRight();
  100.             } catch (Exception e) {
  101.                 // TODO Auto-generated catch block
  102.                 e.printStackTrace();
  103.             }}
  104.         else if(alien.isMoving()==true) {throw new ModelException("Already Moving");}
  105.     }
  106.  
  107.     @Override
  108.     public void endMove(Mazub alien) throws ModelException {
  109.         if(alien.isMoving()==true) {alien.endMove();}
  110.         else if(alien.isMoving()==false){throw new ModelException("Already Stopped Ducking");}
  111.     }
  112.  
  113.     @Override
  114.     public boolean isJumping(Mazub alien) throws ModelException {
  115.          return alien.isJumping();
  116.     }
  117.  
  118.     @Override
  119.     public void startJump(Mazub alien) throws ModelException {//Die exception moet denk ik in Mazub zelf. Zelfde in running enz
  120.         if(alien.isJumping() == false) {alien.startJump();}
  121.         else {throw new ModelException("Already Jumping");}
  122.     }
  123.  
  124.     @Override
  125.     public void endJump(Mazub alien) throws ModelException {
  126.         if(alien.isJumping() ==true) {alien.endJump();}
  127.         else {throw new ModelException("Already Stopped Jumping");}
  128.     }
  129.  
  130.     @Override
  131.     public boolean isDucking(Mazub alien) throws ModelException {
  132.          return alien.isDucking();
  133.     }
  134.  
  135.     @Override
  136.     public void startDuck(Mazub alien) throws ModelException {
  137.         if(alien.isDucking() ==false) {alien.startDucking();}
  138.     }
  139.  
  140.     @Override
  141.     public void endDuck(Mazub alien) throws ModelException {
  142.         alien.endDucking();
  143.     }
  144.  
  145.     @Override
  146.     public World createWorld(int tileSize, int nbTilesX, int nbTilesY, int[] targetTileCoordinate,
  147.             int visibleWindowWidth, int visibleWindowHeight, int... geologicalFeatures) throws ModelException {
  148.          try {World world= new World(tileSize, nbTilesX, nbTilesY,  targetTileCoordinate, visibleWindowWidth, visibleWindowHeight, geologicalFeatures );
  149.          return world;
  150.         } catch (Exception e) {
  151.             throw new ModelException(e);
  152.         }
  153.     }
  154.  
  155.     @Override
  156.     public void terminateWorld(World world) throws ModelException {
  157.         world.terminateWorld();  
  158.     }
  159.  
  160.     @Override
  161.     public int[] getSizeInPixels(World world) throws ModelException {
  162.         return world.getSizeInPixels();
  163.     }
  164.  
  165.     @Override
  166.     public int getTileLength(World world) throws ModelException {
  167.        try {return world.getTileLength();
  168.        
  169.     } catch (Exception e) {throw new ModelException(e);}
  170.         // TODO: handle exception
  171.    
  172.     }
  173.  
  174.     @Override
  175.     public int getGeologicalFeature(World world, int pixelX, int pixelY) throws ModelException {
  176.         return world.getGeologicalFeatures(pixelX, pixelY);
  177.        
  178.     }
  179.  
  180.     @Override
  181.     public void setGeologicalFeature(World world, int pixelX, int pixelY, int geologicalFeature) throws ModelException {
  182.         try{world.setGeologicalFeatures(pixelX, pixelY, geologicalFeature);}
  183.         catch(Exception e){throw new ModelException(e);}
  184.     }
  185.  
  186.     @Override
  187.     public int[] getVisibleWindowDimension(World world) throws ModelException {
  188.         try{return world.getVisibleWindowDimension();}
  189.         catch(Exception e){throw new ModelException(e);}
  190.     }
  191.    
  192.     public int[] getVisibleWindowPosition(World world) throws ModelException {
  193.         try{return world.getVisibleWindowsPosition();}
  194.         catch(Exception e){throw new ModelException(e);}
  195.     }
  196.  
  197.     @Override
  198.     public boolean hasAsGameObject(Object object, World world) throws ModelException {
  199.         try{return world.hashAsGameObject(object);}
  200.         catch(Exception e){throw new ModelException(e);}
  201.     }
  202.  
  203.     @Override
  204.     public Set<? extends Object> getAllGameObjects(World world) throws ModelException {
  205.           try{return world.getAllGameObjects();}
  206.           catch(Exception e){throw new ModelException(e);}
  207.     }
  208.  
  209.     @Override
  210.     public Mazub getMazub(World world) throws ModelException {
  211.         try{return world.getMazub();}
  212.         catch(Exception e){throw new ModelException(e);}
  213.     }
  214.  
  215.     @Override
  216.     public void addGameObject(Object object, World world) throws ModelException {
  217.         try{world.addGameObject((Entity)object, world);}
  218.         catch(Exception e){throw new ModelException(e);}
  219.     }
  220.  
  221.     @Override
  222.     public void removeGameObject(Object object, World world) throws ModelException {
  223.         try{world.terminatedGameObject((Entity)object);}
  224.         catch(Exception e){throw new ModelException(e);}
  225.     }
  226.  
  227.     @Override
  228.     public int[] getTargetTileCoordinate(World world) throws ModelException {
  229.          return world.getTargetTileCoordinate();
  230.     }
  231.  
  232.     @Override
  233.     public void setTargetTileCoordinate(World world, int[] tileCoordinate) throws ModelException {
  234.          try {world.setTargetTileCoordinate(tileCoordinate);
  235.            
  236.         } catch (Exception e) {
  237.             throw new ModelException(e);
  238.         }
  239.     }
  240.  
  241.     @Override
  242.     public void startGame(World world) throws ModelException {
  243.         try{world.startGame();}
  244.         catch(Exception e){throw new ModelException(e);}
  245.     }
  246.  
  247.     @Override
  248.     public boolean isGameOver(World world) throws ModelException {
  249.         try{return world.isGameOver();}
  250.         catch(Exception e){throw new ModelException(e);}
  251.     }
  252.  
  253.     @Override
  254.     public boolean didPlayerWin(World world) throws ModelException {
  255.         try{return world.DidPlayerWin();}
  256.         catch(Exception e){throw new ModelException(e);}
  257.     }
  258.  
  259.     @Override
  260.     public void advanceWorldTime(World world, double dt) throws ModelException {
  261.         try {
  262.             world.advancedTime(dt);
  263.         } catch (Exception e) {
  264.             Exception d = e;
  265.             // TODO Auto-generated catch block
  266.             throw new ModelException(d);
  267.         }
  268.        
  269.     }
  270.  
  271.    
  272.     @Override
  273.     public Set<School> getAllSchools(World world) throws ModelException {
  274.          try{return world.getAllSchools();}
  275.          catch(Exception e){throw new ModelException(e);}
  276.     }
  277.     /*
  278.      *************
  279.      *GameObjects*
  280.      *************
  281.      */
  282.    
  283.  
  284.     @Override
  285.     public void terminateGameObject(Object gameObject) throws ModelException {
  286.          try{if(((Entity)gameObject).getWorld() != null){((Entity)gameObject).getWorld().terminatedGameObject((Entity)gameObject);}
  287.              else {((Entity)gameObject).terminateGameObject();}}
  288.          catch(Exception e){throw new ModelException(e);}
  289.     }
  290.  
  291.     @Override
  292.     public boolean isTerminatedGameObject(Object gameObject) throws ModelException {
  293.          try{if(((Entity)gameObject).getWorld() != null&&((Entity)gameObject).getWorld().isTerminatedGameObject(gameObject)) {return true;}
  294.          else {
  295.              if(((Entity)gameObject).isTerminatedGameObject()){return true;}else {return false;}}
  296.          }
  297.          catch(Exception e){throw new ModelException(e);}
  298.     }
  299.  
  300.     @Override
  301.     public boolean isDeadGameObject(Object gameObject) throws ModelException {
  302.          try{return ((Entity)gameObject).isDeadGameObject();}
  303.          catch(Exception e){throw new ModelException(e);}
  304.     }  
  305.  
  306.     @Override
  307.     public double[] getActualPosition(Object gameObject) throws ModelException {
  308.          try{return ((Entity)gameObject).getActualPosition();}
  309.          catch(Exception e){throw new ModelException(e);}
  310.     }
  311.  
  312.     @Override
  313.     public void changeActualPosition(Object gameObject, double[] newPosition) throws ModelException {
  314.          try{((Entity)gameObject).changeActualPosition(newPosition);}
  315.          catch(Exception e){throw new ModelException(e);}
  316.        
  317.     }
  318.  
  319.     @Override
  320.     public int[] getPixelPosition(Object gameObject) throws ModelException {
  321.          try{return ((Entity)gameObject).getPixelPosition();}
  322.          catch(Exception e){throw new ModelException(e);}
  323.        
  324.     }
  325.  
  326.     @Override
  327.     public int getOrientation(Object gameObject) throws ModelException {
  328.         try{return ((Entity)gameObject).getOrientation();}
  329.         catch(Exception e){throw new ModelException(e);}
  330.     }
  331.  
  332.     @Override
  333.     public double[] getVelocity(Object gameObject) throws ModelException {
  334.         try{return ((Entity)gameObject).getVelocity();}
  335.         catch(Exception e){throw new ModelException(e);}
  336.     }
  337.  
  338.     @Override
  339.     public double[] getAcceleration(Object gameObject) throws ModelException {
  340.          try{return ((Entity)gameObject).getAcceleration();}
  341.          catch(Exception e){throw new ModelException(e);}
  342.     }
  343.  
  344.     @Override
  345.     public World getWorld(Object object) throws ModelException {
  346.         try{if(object instanceof Entity) {return ((Entity)object).getWorld();}
  347.             else if(object instanceof School) {return ((School)object).getworld();}
  348.             else {World d = null;return d;}}
  349.         catch(Exception e){throw new ModelException(e);}
  350.        
  351.     }
  352.  
  353.     @Override
  354.     public int getHitPoints(Object object) throws ModelException {
  355.          try{return ((Entity)object).getHitpoint();}
  356.          catch(Exception e){throw new ModelException(e);}
  357.     }
  358.  
  359.     @Override
  360.     public Sprite[] getSprites(Object gameObject) throws ModelException {
  361.          try{return ((Entity)gameObject).getSprites();}
  362.          catch(Exception e){throw new ModelException(e);}
  363.     }
  364.    
  365.     @Override
  366.     public Sprite getCurrentSprite(Object gameObject)throws ModelException{
  367.         try{return ((Entity)gameObject).getCurrentSprite();}
  368.         catch(Exception e){throw new ModelException(e);}
  369.     }
  370.    
  371.    
  372. // World AdvencedTime    
  373.     @Override
  374.     public void advanceTime(Object gameObject, double dt) throws ModelException {
  375.         try {((Entity)gameObject).advanceTime(dt);}
  376.         catch (Exception e) {throw new ModelException(e);}
  377.     }
  378.    
  379. // Sneezewort
  380.    
  381.     @Override
  382.     public Sneezewort createSneezewort(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  383.         try {Sneezewort Sneeze=new Sneezewort(pixelLeftX, pixelBottomY, sprites);return Sneeze;}
  384.         catch (Exception e) {throw new ModelException(e);}
  385.        
  386.     }
  387.    
  388.  // Skullcab
  389.  
  390.     @Override
  391.     public Skullcab createSkullcab(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  392.         try {Skullcab Skull=new Skullcab(pixelLeftX, pixelBottomY, sprites);return Skull;}
  393.         catch (Exception e) {throw new ModelException(e);}
  394.        
  395.     }
  396.    
  397. // Slime Facade
  398.  
  399.     @Override
  400.     public Slime createSlime(long id, int pixelLeftX, int pixelBottomY, School school, Sprite... sprites)throws ModelException {
  401.         try {Slime slime=new Slime(id, pixelLeftX, pixelBottomY, school, sprites); return slime;}
  402.         catch (Exception e) {throw new ModelException(e);}
  403.     }
  404.    
  405.     @Override
  406.     public long getIdentification(Slime slime) throws ModelException {
  407.         try {return slime.getID();}
  408.         catch (Exception e) {throw new ModelException(e);}
  409.     }
  410.  
  411.     @Override
  412.     public void cleanAllSlimeIds() {
  413.         Slime.CleanIdSet();
  414.     }
  415.    
  416.  // School Facade
  417.  
  418.     @Override
  419.     public School createSchool(World world) throws ModelException {
  420.         try {School school= new School(world);return school;}
  421.         catch (Exception e) {throw new ModelException(e);}
  422.     }
  423.  
  424.     @Override
  425.     public void terminateSchool(School school) throws ModelException {
  426.         try {school.terminateSchool();}
  427.         catch (Exception e) {throw new ModelException(e);}
  428.        
  429.     }
  430.  
  431.     @Override
  432.     public boolean hasAsSlime(School school, Slime slime) throws ModelException {
  433.         try {return school.hasAsSlime(slime);}
  434.         catch (Exception e) {throw new ModelException(e);}
  435.     }
  436.  
  437.     @Override
  438.     public Collection<? extends Slime> getAllSlimes(School school) {
  439.         try {return school.getAllSlimes();}
  440.         catch (Exception e) {throw new ModelException(e);}
  441.     }
  442.  
  443.     @Override
  444.     public void addAsSlime(School school, Slime slime) throws ModelException {
  445.         try {school.AddAsSlime(slime);}
  446.         catch (Exception e) {throw new ModelException(e);}
  447.     }
  448.  
  449.     @Override
  450.     public void removeAsSlime(School school, Slime slime) throws ModelException {
  451.         try {school.removeAsSlime(slime);}
  452.         catch (Exception e) {throw new ModelException(e);}
  453.     }
  454.  
  455.     @Override
  456.     public void switchSchool(School newSchool, Slime slime) throws ModelException {
  457.         try {newSchool.switchSchool(slime);}
  458.         catch (Exception e) {throw new ModelException(e);}
  459.     }
  460.  
  461.     @Override
  462.     public School getSchool(Slime slime) throws ModelException {
  463.         try {return slime.getSchool();}
  464.         catch (Exception e) {throw new ModelException(e);}
  465.     }
  466.    
  467. //Shark Facade
  468.    
  469.     public Shark createShark(int pixelLeftX, int pixelBottomY, Sprite... sprites) throws ModelException {
  470.        
  471.         try {Shark shark=new Shark(pixelLeftX, pixelBottomY, sprites);return shark;
  472.         } catch (Exception e) {throw new ModelException(e);}
  473.     }
  474.  
  475.     @Override
  476.     public Sprite[] getSprites(Mazub alien) throws ModelException {
  477.         return alien.getSprites();
  478.     }
  479.  
  480. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement