RecklessDarph

Backup World

Jul 10th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 49.43 KB | None | 0 0
  1. package jumpingalien.model;
  2.  
  3. import java.math.BigDecimal;
  4. import java.math.RoundingMode;
  5. import java.util.ArrayList;
  6. import java.util.Currency;
  7. import java.util.HashSet;
  8. import java.util.Iterator;
  9. import java.util.Set;
  10. import java.util.Timer;
  11. import javax.xml.crypto.dsig.spec.ExcC14NParameterSpec;
  12. import org.junit.FixMethodOrder;
  13. import be.kuleuven.cs.som.annotate.Raw;
  14. import jumpingalien.facade.Facade;
  15. import jumpingalien.model.Mazub;
  16. import jumpingalien.util.ModelException;
  17.  
  18.  
  19. /**
  20.  * A class for creating the game world, get the images and coordinates, and make the world change depending on the pixelposition of Mazub
  21.  * and the advance time.
  22.  * The world has passable and impassable terains.
  23.  *
  24.  * @version  2.0
  25.  * @author   Thierry Klougbo & Jordi De Pau
  26.  */
  27. public class World {
  28.     // Precision constants for checks involving floating point numbers.
  29.         public final static double HIGH_PRECISION = 0.1E-10;
  30.         public final static double LOW_PRECISION = 0.01;
  31.  
  32.  
  33.     public int VisibleWindowX, VisibleWindowY, TileLength ,nmbTilesX, nmbTilesY;
  34.      /**
  35.     *  
  36.     * @param pixelSize
  37.     *       The actual size of the pixels.
  38.     * @param nbTilesX
  39.     *       The number of tiles in the visible window of the world's x-axis.
  40.     * @param nbTilesY
  41.     *       The number of tiles in the visible window of the world's y-axis.
  42.     * @param targetTileCoordinate
  43.     * @param visibleWindowWidth
  44.     *       The actual width of the visible window.
  45.     * @param visibleWindowHeight
  46.     *       The actual height of the visible window.
  47.     * @param geologicalFeatures
  48.     *       An integer for representing every geological feature:
  49.     *                           AIR = 0;
  50.     *                           SOLID_GRO;UND = 1;
  51.     *                           WATER = 2;
  52.     *                           MAGMA = 3;
  53.     *                           GAS = 4;.
  54.     *                           ICE = 5;
  55.     */
  56.     public World(int pixelSize, int nbTilesX, int nbTilesY, int[] targetTileCoordinate, int visibleWindowWidth, int visibleWindowHeight, int...geologicalFeatures) throws Exception{
  57.         if(pixelSize<0) {pixelSize=pixelSize*(-1);}
  58.         if(nbTilesX<0) {nbTilesX=nbTilesX*(-1);}
  59.         if(nbTilesY<0) {nbTilesY=nbTilesY*(-1);}
  60.         setTileLength(pixelSize);
  61.         setSizeInPixels(nbTilesX*pixelSize,nbTilesY*pixelSize);
  62.         setVisibleWindowDimension(visibleWindowWidth,visibleWindowHeight);
  63.         setTargetTileCoordinate(targetTileCoordinate);
  64.         setGeologicalFeaturesSize(nbTilesX, nbTilesY);
  65.         createGeologicalFeatures(nbTilesX, nbTilesY, geologicalFeatures);}
  66.    
  67.     /**
  68.      * Sets the Tile Length to the given pixelsize.
  69.      *
  70.      * @param pixelSize
  71.      *          given size of the length of a Tile
  72.      * @effect if the given pixelsize is larger then zero the tile length will be set to the given pixelsize
  73.      *          | if(pixelSize >0)
  74.      *          | then TileLength = pixelSize
  75.      * @effect else the given pixelsize is lower or equal then/to zero the tile length will be set to 1
  76.      *          |TileLenght = 1
  77.      *         
  78.      */
  79.     private void setTileLength(int pixelSize) {
  80.         if(pixelSize >0) {TileLength=pixelSize;}
  81.         else {TileLength=1;}
  82.        
  83.     }
  84.     /*
  85.      *******************************
  86.      * *Tiles Total programming. *
  87.      * *****************************  
  88.      */
  89.    
  90.     /**
  91.      * SizeInPixels= Pixel size of the world with an array of 2.
  92.      */
  93.     public int [] SizeInPixels= new int[2] ;
  94.  
  95.     /**
  96.      *  Returns the size of the game world in pixels.
  97.      *  
  98.      *  @post SizeInPixels contains respectively the visible window length and the
  99.      *  visible window height.
  100.      *      | SizeInPixels[0]=VisibleWindowX; SizeInPixels[1]=VisibleWindowY;
  101.      * @return SizeInPixels
  102.      */
  103.     public int[] getSizeInPixels() {return SizeInPixels;}
  104.    
  105.     /**
  106.      * sets the given width and Height inside an integer array of index 2 with name SizeInPixels
  107.      *
  108.      * @param Width
  109.      *      given width of the given world in integers.
  110.      * @param Height
  111.      *      given height of the given world in integers.
  112.      * @effect
  113.      *      If the width is lower then zero the will be zero
  114.      *      | if(Width<0)
  115.      *      | then SizeInPixels[0]=0
  116.      * @effect
  117.      *      If the width is equal or higher then zero this SizeinPixels horizontal will be set to the given width
  118.      *      |SizeInPixels[0]=Width
  119.      * @effect
  120.      *      If the Height is lower then zero the will be zero
  121.      *      | if(Width<0)
  122.      *      | then SizeInPixels[1]=0
  123.      * @effect
  124.      *      If the Height is equal or higher then zero this SizeinPixels horizontal will be set to the given width
  125.      *      |SizeInPixels[1]=Height
  126.      *
  127.      */
  128.     public void setSizeInPixels(int Width, int Height) {
  129.         if(Width<0) {SizeInPixels[0]=0;}
  130.         else {SizeInPixels[0] =Width;}
  131.         if(Height<0){SizeInPixels[1] = 0;}
  132.         else{SizeInPixels[1] =Height;}}
  133.    
  134.     /**
  135.      * @return the length of a tile
  136.      *          |return TileLength
  137.      */
  138.     public int getTileLength(){return TileLength;}
  139.     /*
  140.      * ***********************
  141.      *  Geological features  *
  142.      * ***********************/
  143.    
  144.     /**
  145.      * Is an Integer array of the world's geologicalFeatures in Tile's
  146.      */
  147.     public int[][] GeologicalFeaturesCanvas;
  148.  
  149.     /**
  150.      * Sets the GeologicalCanvas with coloms and rows
  151.      *
  152.      * @param GeoRow
  153.      *      Is the value of how many rows there has to be in GeologicalFeatures
  154.      * @param GeoCol
  155.      *      Is the value of how many Coloms there has to be in GeologicalFeatuers
  156.      * @effect
  157.      *      sets GeologicalFeaturesCanvas with the rows and coloms.
  158.      *      |this.GeologicalFeaturesCanvas = new int[GeoRow][GeoCol]
  159.      */
  160.     public void setGeologicalFeaturesSize(int GeoRow,int GeoCol) {this.GeologicalFeaturesCanvas = new int[GeoRow][GeoCol];}
  161.    
  162.     /**
  163.      * sets the geologicalfeatures of the world by putting every position with a feature
  164.      *
  165.      * @param X
  166.      *      a given X value that is a pixel & Integer.
  167.      * @param Y
  168.      *      a given Y value that is a pixel & Integer
  169.      * @param geoFeature
  170.      *      a geological Feature that is Integer
  171.      * @effect
  172.      *      if the given x (that is calculatet to a tile) or y(that is calculatet to a tile) is outside the border the feature should be 0
  173.      *      |if(X > ((SizeInPixels[0]/this.getTileLength())-1) || Y > ((SizeInPixels[0]/this.getTileLength())-1)
  174.      *      |then this.GeologicalFeaturesCanvas[GeoX][GeoY] =0
  175.      *@effect
  176.      *      else the given x (that is calculatet to a tile) and y(that is calculatet to a tile) is set with the given feature in geologicalCanvas
  177.      *      |this.GeologicalFeaturesCanvas[GeoX][GeoY] = geoFeature
  178.      */
  179.     public void setGeologicalFeatures(int X, int Y, int geoFeature) {
  180.       int GeoX = calculateInFeature(X);
  181.       int GeoY = calculateInFeature(Y);
  182.       if (X > ((SizeInPixels[0]/this.getTileLength())-1) || Y > ((SizeInPixels[0]/this.getTileLength())-1) || X<0 || Y<0) {this.GeologicalFeaturesCanvas[GeoX][GeoY] =0;}
  183.       this.GeologicalFeaturesCanvas[GeoX][GeoY] = geoFeature;
  184.     }
  185.    
  186.     /**
  187.      * returns the geological feature with the given x and y calculated in a tile.
  188.      *
  189.      * @param pixelX
  190.      *          is the value of the pixel x-value
  191.      * @param pixelY
  192.      *          is the value of the pixel y-value
  193.      * @return
  194.      *      if the x value or the y value is larger then the world itself it returns 0
  195.      *      |return 0
  196.      * @return
  197.      *      returns feature of the position calculated in tile. (T
  198.      *      |GeologicalFeaturesCanvas[GeoX][GeoY]
  199.      */
  200.     public int getGeologicalFeatures(int pixelX, int pixelY) {
  201.         if (pixelX >= this.getSizeInPixels()[0] || pixelY >= this.getSizeInPixels()[1]) {return 0;}
  202.       int GeoX = calculateInFeature(pixelX);
  203.       int GeoY = calculateInFeature(pixelY);
  204.  
  205.       return GeologicalFeaturesCanvas[GeoX][GeoY];
  206.     }
  207.    
  208.    
  209.     /**
  210.      * @param X
  211.      *      is the given value of the pixel of x-value
  212.      * @param Y
  213.      *      is the given value of the pixel of y-value
  214.      * @param F
  215.      *      is the given feature
  216.      *@effect
  217.      *      sets the positions feature
  218.      *      |this.GeologicalFeaturesCanvas[X][Y] = F
  219.      */
  220.     public void setFeature(int X, int Y, int F) {
  221.           this.GeologicalFeaturesCanvas[X][Y] = F;
  222.     }
  223.    
  224.    
  225.     /**
  226.      * calculates the pixel position into the position of the tile.
  227.      *
  228.      * @param aPixel
  229.      *      is the given value of a pixel
  230.      * @effect
  231.      *      sets the variable resultpixel in the pixel divide by the tile length       
  232.      *      |int resultPixel = (int)((aPixel)/getTileLength()
  233.      * @return
  234.      *      the result of the pixel
  235.      */
  236.     public int calculateInFeature(int aPixel) {
  237.         int resultPixel = (int)((aPixel)/getTileLength());
  238.         return resultPixel;}
  239.    
  240.    
  241.     /**
  242.      * sets all the geological in canvas with the given amount tiles in x and the given amount tiles in y with the given feature in an array.
  243.      *
  244.      * @param nbTilesX
  245.      *      is the given amount of tiles for x value.
  246.      * @param nbTilesY
  247.      *      is the given amount of tiles for y-value
  248.      * @param geologicalFeatures
  249.      *      is an array of feature
  250.      *@effect
  251.      *      if the geologicalfeature length of the array is bigger then zero sets all the features are set in a nested loop for each position
  252.      *      |if(geologicalFeatures.length>0)
  253.      *      |then   for (int  y= 0; y < nbTilesY; y++) {
  254.      *      |       for (int x = 0; x< nbTilesX; x++) {
  255.      *                  int counter =y*nbTilesX + x;
  256.      *                  setFeature(x, y,geologicalFeatures[counter]);}}
  257.      *@effect
  258.      *      if the geologicalfeature length of the array is zero sets all the features to zero in a nested loop for each position
  259.      *      |if(geologicalFeatures.length==0)
  260.      *      |then   for (int  y= 0; y < nbTilesY; y++) {
  261.      *      |       for (int x = 0; x< nbTilesX; x++) {
  262.      *                  int counter =y*nbTilesX + x;
  263.      *                  setFeature(x, y,geologicalFeatures[0]);}}
  264.      *
  265.      */
  266.     public void createGeologicalFeatures(int nbTilesX, int nbTilesY,int... geologicalFeatures) {
  267.         if(geologicalFeatures.length>0) {
  268.             for (int  y= 0; y < nbTilesY; y++) {
  269.             for (int x = 0; x< nbTilesX; x++) {
  270.                 int counter =y*nbTilesX + x;
  271.                 setFeature(x, y,geologicalFeatures[counter]);}}}
  272.        
  273.         else {for (int  y= 0; y < nbTilesY; y++) {
  274.             for (int x = 0; x< nbTilesX; x++) {
  275.                 setFeature(x, y,0);}}}
  276.     }
  277.  
  278.     /*
  279.      **********************************
  280.      *Visible Window Defensive program*
  281.      **********************************
  282.      */
  283.     //FIXME To do 400 pixel groter dan mazub
  284.     //FIXME Make adaptor in advanced time
  285.    
  286.     /**
  287.      * VisibleWindowDimension is the dimension that is visible for your screen
  288.      */
  289.     public int[] VisibleWindowDimension=new int[2];
  290.    
  291.     /**
  292.      * sets the visible window with the given weight and height
  293.      * @param weight
  294.      *      is the given weight of the window position
  295.      * @param height
  296.      *      is the given height of the window position
  297.      * @throws Exception
  298.      *      if the weight or the height is bigger then the dimension of the world
  299.      *      |if(weight>getSizeInPixels()[0]||height>getSizeInPixels()[1])
  300.      *      |then throw new Exception("To big window compared to actualworld");
  301.      * @throws Exception
  302.      *      if the weight or the height is lower then the universe (= the universe is everything above 0 for both x & y)
  303.      *      |if(weight <0 && height <0)
  304.      *      |then throw new Exception("Illegal Window");
  305.      * @effect
  306.      *      sets the given visible dimensioen with the weight and the height
  307.      *      |if(weight >0 && height >0)
  308.      *      |then weight;VisibleWindowDimension[1] = height;
  309.      */
  310.     public void setVisibleWindowDimension(int weight , int height) throws Exception{
  311.         if(weight>getSizeInPixels()[0]||height>getSizeInPixels()[1]) {throw new Exception("To big window compared to actualworld");}
  312.     else if(weight >0 && height >0) {
  313.         VisibleWindowDimension[0] = weight;VisibleWindowDimension[1] = height;}
  314.         else {throw new Exception("Illegal Window");}}
  315.     /**
  316.      * gets visible window dimensions.
  317.      * @return
  318.      *      |result=VisibleWindowDimension
  319.      */
  320.     public int[] getVisibleWindowDimension() {
  321.         return VisibleWindowDimension;
  322.     }
  323.    
  324.    
  325.     /**
  326.      * gets the visible window dimension
  327.      *
  328.      * @return
  329.      *      if there isn't a mazub return a dimension with values of zero's
  330.      *
  331.      * @return
  332.      *      if mazub pixel position is smaller then the world size of x sets x window position to the visibleposition adaptor
  333.      *      | if(mazub.getPixelPosition()[0]<getSizeInPixels()[0]-mazub.getCurrentSprite().getWidth()&& visibleMazubCanMove(0))
  334.      *      | then VisibleWindowPosition[0]=(int)(VisiblePositionAdaptor);
  335.      * @return
  336.      *      if mazub pixel position is smaller then the world size of y sets y window position to the visibleposition adaptor
  337.      *      | if(mazub.getPixelPosition()[1]<getSizeInPixels()[1]-mazub.getCurrentSprite().getWidth()&& visibleMazubCanMove(1))
  338.      *      | then VisibleWindowPosition[1]=(int)(VisiblePositionAdaptor);
  339.      * @return
  340.      *      if the size is bigger then the world size x sets the windows position to max possible
  341.      *      |if(VisibleWindowPosition[0] >SizeInPixels[0]-getVisibleWindowDimension()[0])
  342.      *      |then VisibleWindowPosition[0] =SizeInPixels[0]-getVisibleWindowDimension()[0];
  343.      * @return
  344.      *      if the size is bigger then the world size y sets the windows position to max possible
  345.      *      |if(VisibleWindowPosition[1] >SizeInPixels[1]-getVisibleWindowDimension()[1])
  346.      *      |then VisibleWindowPosition[1] =SizeInPixels[1]-getVisibleWindowDimension()[1];
  347.      *
  348.      */
  349.     public int[] getVisibleWindowsPosition() {
  350.         if(mazub == null) {VisibleWindowPosition[0] =0; VisibleWindowPosition[1]=0; return VisibleWindowPosition;}
  351.         if(mazub.getPixelPosition()[0]<getSizeInPixels()[0]-mazub.getCurrentSprite().getWidth()&& visibleMazubCanMove(0)){
  352.             VisibleWindowPosition[0]=(int)(VisiblePositionAdaptor);}
  353.         if (mazub.getPixelPosition()[1]<getSizeInPixels()[1] &&visibleMazubCanMove(1)) {
  354.             VisibleWindowPosition[1]=(int)(VisiblePositionAdaptor);}
  355.         if(VisibleWindowPosition[0] >SizeInPixels[0]-getVisibleWindowDimension()[0]) {VisibleWindowPosition[0] =SizeInPixels[0]-getVisibleWindowDimension()[0];}
  356.         if(VisibleWindowPosition[1] >SizeInPixels[1]-getVisibleWindowDimension()[1]) {VisibleWindowPosition[1] =SizeInPixels[1]-getVisibleWindowDimension()[1];}
  357.         return VisibleWindowPosition;
  358.     }
  359.    
  360.     /**
  361.      * Is the new windows position that sometimes is the windows position or -200 of the windows position that mazub is not near the wall while moving
  362.      */
  363.     public int VisiblePositionAdaptor;
  364.    
  365.    
  366.     /**
  367.      * is the position of the visible window.
  368.      */
  369.     public int[]VisibleWindowPosition=new int[2];
  370.    
  371.    
  372.     /**
  373.      * returns if mazub its visibleposition can move but also adapts visiblepositionadaptor
  374.      *
  375.      * @param direction
  376.      *      is 0 or 1 that equals x or y
  377.      * @return
  378.      *      if the mazub is not near 200  pixels near the world borders visiblePositionAdaptor will be the position minus 200 and returns true
  379.      *      |if(newPos > 200 && newPos < SizeInPixels[direction]-200 )
  380.      *      |then VisiblePositionAdaptor = newPos -200; return true;
  381.      * @return
  382.      *      if the mazub is 200 or less pixels near the wall and returns false
  383.      *      |if(newPos <= 200 && newPos >= SizeInPixels[direction]-200 )
  384.      *      |then VisiblePositionAdaptor = 0; return false;
  385.      */
  386.     public boolean visibleMazubCanMove(int direction) {
  387.         int newPos = mazub.getPixelPosition()[direction];
  388.         if(newPos > 200 && newPos < SizeInPixels[direction]-200 ) {VisiblePositionAdaptor = newPos -200; return true;}
  389.         else {VisiblePositionAdaptor = 0; return false;}
  390.         }
  391.        
  392.    
  393.     /**
  394.      *sets the visibleadaptor with the given integer visiblePositionAdaptor
  395.      *
  396.      * @param visiblePositionAdaptor
  397.      *@effect
  398.      *      sets the visibleadaptor with the given integer visiblePositionAdaptor
  399.      *      |VisiblePositionAdaptor = visiblePositionAdaptor;
  400.      */
  401.     public void setVisiblePositionAdaptor(int visiblePositionAdaptor) {
  402.         VisiblePositionAdaptor = visiblePositionAdaptor;
  403.     }
  404.    
  405.     /*
  406.     ************************************
  407.     | Target tiles Nominal programming |
  408.     ************************************
  409.      */
  410.    
  411.     /**
  412.      * sets the targetTileCoordinates
  413.      */
  414.     public int[] targetTileCoordinates = new int[2];
  415.    
  416.    
  417.     /**
  418.      * Set the coordinate of the target tile in the given world to the given
  419.      * tile coordinate.
  420.      */
  421.     public void setTargetTileCoordinate(int[] tileCoordinate) throws Exception{
  422.         if(tileCoordinate.length == 2 || tileCoordinate ==null) {
  423.         targetTileCoordinates = tileCoordinate;}
  424.         else {throw new Exception("Invalid coordinates");}
  425.            
  426.        
  427.     }
  428.    
  429.     /**
  430.      * Return the coordinate of the target tile in the given world.
  431.      *   Returns an array of 2 integers {x, y} that represents the tile coordinate
  432.      *   of the target tile.
  433.      *   */
  434.     public int[] getTargetTileCoordinate() throws ModelException{
  435.         return targetTileCoordinates;}
  436.     /*
  437.      ************************************
  438.      | Collision |
  439.      ************************************
  440.       */
  441.    
  442.    
  443.     /**
  444.      * returns of the the given currentEntity interactes with the given geologicalFeature
  445.      *
  446.      * @param currentEntity
  447.      *      is the given Entity
  448.      * @param GeologicalFeature
  449.      *      is the given geologicalFeature
  450.      * @return
  451.      *      if the Entity interactes with the given geologicalfeature by calculateing the corners of the given Entity returns true
  452.      *      |if(getGeologicalFeatures(X, Y)==GeologicalFeature
  453.      *      |   || getGeologicalFeatures((X+SpriteX), Y + SpriteY)==GeologicalFeature
  454.      *      |    || getGeologicalFeatures((X+SpriteX), Y)==GeologicalFeature
  455.      *      |    || getGeologicalFeatures(X+SpriteX, Y+SpriteY)==GeologicalFeature
  456.      *      |then touch=true;
  457.      * @return
  458.      *      if the Entity is not interactes with the given geologicalfeature by calculateing the corners of the given Entity returns false
  459.      *      |if(getGeologicalFeatures(X, Y)!=GeologicalFeature
  460.      *      |   || getGeologicalFeatures((X+SpriteX), Y + SpriteY)!=GeologicalFeature
  461.      *      |    || getGeologicalFeatures((X+SpriteX), Y)!=GeologicalFeature
  462.      *      |    || getGeologicalFeatures(X+SpriteX, Y+SpriteY)!=GeologicalFeature
  463.      *      |then touch=false;
  464.      */
  465.     public boolean Element(Entity currentEntity,int GeologicalFeature) {
  466.         boolean touch=false;
  467.         int X=currentEntity.getPixelPosition()[0],Y =currentEntity.getPixelPosition()[1],SpriteX= currentEntity.getCurrentSprite().getWidth()-1,SpriteY=currentEntity.getCurrentSprite().getHeight()-1;
  468.         if(getGeologicalFeatures(X, Y)==GeologicalFeature
  469.                 || getGeologicalFeatures((X+SpriteX), Y + SpriteY)==GeologicalFeature
  470.                 || getGeologicalFeatures((X+SpriteX), Y)==GeologicalFeature
  471.                 || getGeologicalFeatures(X+SpriteX, Y+SpriteY)==GeologicalFeature
  472.             ){touch=true;}
  473.         else {touch=false;}
  474.         return touch;
  475.     }
  476.    
  477.    
  478.     /**
  479.      * calculates if the entity will collide with earth with the given time
  480.      *
  481.      * @param currentEntity
  482.      *      is a given Entity
  483.      * @param time
  484.      *      is a given time in double
  485.      * @return
  486.      *      if the entity will collide with earth with the given time
  487.      *
  488.      */
  489.     public boolean futureEarth(Entity currentEntity,double time) throws Exception {
  490.         int[] pos =
  491.             {mazub.calculateToPixel(BigDecimal.valueOf(
  492.             (BigDecimal.valueOf(currentEntity.actualPosition[0])
  493.                     .add (BigDecimal.valueOf(currentEntity.Velocity[0]).multiply(BigDecimal.valueOf(time)))
  494.                     .add(BigDecimal.valueOf(currentEntity.getAcceleration()[0]).multiply(BigDecimal.valueOf(0.5))
  495.                     .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue()),
  496.             mazub.calculateToPixel(BigDecimal.valueOf(
  497.             (BigDecimal.valueOf(currentEntity.actualPosition[1])
  498.                     .add (BigDecimal.valueOf(currentEntity.Velocity[1]).multiply(BigDecimal.valueOf(time)))  
  499.                     .add(BigDecimal.valueOf(currentEntity.getAcceleration()[1]).multiply(BigDecimal.valueOf(0.5))
  500.                     .multiply(BigDecimal.valueOf(Math.pow(time, 2))))).doubleValue()).doubleValue())};
  501.        
  502.         boolean touch=false;
  503.         int X=pos[0]+1,Y = pos[1]+1,SpriteX=currentEntity.getCurrentSprite().getWidth()-2,SpriteY= currentEntity.getCurrentSprite().getHeight()-2;
  504.         if(getGeologicalFeatures(X, Y)==1
  505.                 || getGeologicalFeatures(X+SpriteX, Y)== 1
  506.                 || getGeologicalFeatures(X, Y+SpriteY)==1
  507.                 || getGeologicalFeatures(X+SpriteX, Y+SpriteY)==1
  508.             ){touch=true;}
  509.         else {touch=false;}
  510.        return touch;
  511.     }
  512.    
  513.    
  514.     /**
  515.      * Collides with earth
  516.      *
  517.      * @param currentEntity
  518.      * @throws Exception
  519.      */
  520.     public void Earth(Entity currentEntity) throws Exception {
  521.         int X=currentEntity.getPixelPosition()[0]+1,Y =currentEntity.getPixelPosition()[1]+1,SpriteX= currentEntity.getCurrentSprite().getWidth()-2,SpriteY= currentEntity.getCurrentSprite().getHeight()-2;
  522.         //TopPixels = Left Up & Right Up
  523.         if((getGeologicalFeatures(X, Y+SpriteY)==1||getGeologicalFeatures(X+SpriteX,Y+SpriteY)==1 ) && mazub.isJumping()) {
  524.           currentEntity.falling();}
  525.         else {currentEntity.stopDuckingIsEnabled();}
  526.         //BottomPixels = Left Bottom & Right Bottom
  527.         if((getGeologicalFeatures(X, Y-1)==1 || getGeologicalFeatures(X+SpriteX, Y-1)==1) && currentEntity.getVelocity()[1]<0 ) {
  528.             currentEntity.endJump();}
  529.         else {currentEntity.falling();} //;throw new Exception(Integer.toString(X-1)+" "+Integer.toString(Y-1));}
  530.         //RightPixels= alleen rechtsboven want als je linksonder doet kan hij niet meer bewegen door het verplaatsung
  531.         if((getGeologicalFeatures(X+SpriteX, Y+SpriteX-1)==1 || getGeologicalFeatures(X+SpriteX, Y)==1) && currentEntity.getOrientation()==1 && currentEntity.getVelocity()[0]>=0) {
  532.             currentEntity.endMove();throw new Exception(Integer.toString(X-1)+" "+Integer.toString(Y-1));
  533.             }
  534.         //LeftPixels
  535.         if((getGeologicalFeatures(X, Y+SpriteY-1)==1||getGeologicalFeatures(X, Y)==1 )&& currentEntity.getOrientation()==-1) {
  536.             currentEntity.endMove();throw new Exception(Integer.toString(X-1)+" "+Integer.toString(Y-1));}
  537.        
  538.        
  539.     }
  540.    
  541.    
  542.     /**
  543.      * returns a boolean if mazub is in the targetcoordinate
  544.      *
  545.      * @param currentEntity
  546.      *      is a given Entity
  547.      *
  548.      * @return
  549.      *      if mazub's corners are touching the tile of the targetcoordinate
  550.      *      |if(calculateInFeature(X)== getTargetTileCoordinate()[0] && calculateInFeature(Y) == getTargetTileCoordinate()[1]
  551.      *      |      || calculateInFeature(X+SpriteX)== getTargetTileCoordinate()[0] && calculateInFeature(Y) == getTargetTileCoordinate()[1]
  552.      *      |       || calculateInFeature(X)== getTargetTileCoordinate()[0] && calculateInFeature(Y+SpriteY) == getTargetTileCoordinate()[1]
  553.      *      |       || calculateInFeature(X+SpriteX)== getTargetTileCoordinate()[0] && calculateInFeature(Y+SpriteY) == getTargetTileCoordinate()[1])
  554.      *      |then return true
  555.      * @return
  556.      *      if mazub's corners are not touching the tile of the targetcoordinate
  557.      *      |if(calculateInFeature(X)== getTargetTileCoordinate()[0] && calculateInFeature(Y) != getTargetTileCoordinate()[1]
  558.      *      |      || calculateInFeature(X+SpriteX)== getTargetTileCoordinate()[0] && calculateInFeature(Y) != getTargetTileCoordinate()[1]
  559.      *      |       || calculateInFeature(X)== getTargetTileCoordinate()[0] && calculateInFeature(Y+SpriteY) != getTargetTileCoordinate()[1]
  560.      *      |       || calculateInFeature(X+SpriteX)== getTargetTileCoordinate()[0] && calculateInFeature(Y+SpriteY) != getTargetTileCoordinate()[1])
  561.      *      |then return false
  562.      *
  563.      */
  564.     public boolean mazubInTarget(Entity currentEntity) {
  565.            boolean touch=false;
  566.         int X=currentEntity.getPixelPosition()[0]+1,Y = currentEntity.getPixelPosition()[1]+1,SpriteX= currentEntity.getCurrentSprite().getWidth()-2,SpriteY= currentEntity.getCurrentSprite().getHeight()-2;
  567.            if(calculateInFeature(X)== getTargetTileCoordinate()[0] && calculateInFeature(Y) == getTargetTileCoordinate()[1]
  568.                    || calculateInFeature(X+SpriteX)== getTargetTileCoordinate()[0] && calculateInFeature(Y) == getTargetTileCoordinate()[1]
  569.                    || calculateInFeature(X)== getTargetTileCoordinate()[0] && calculateInFeature(Y+SpriteY) == getTargetTileCoordinate()[1]
  570.                    || calculateInFeature(X+SpriteX)== getTargetTileCoordinate()[0] && calculateInFeature(Y+SpriteY) == getTargetTileCoordinate()[1]
  571.                )
  572.            {touch=true;}
  573.            else {touch=false;}
  574.            return touch;
  575.     }
  576.    
  577.    
  578.      /*
  579.     ************************************
  580.     | Advenced time Defensieve program |
  581.     ************************************
  582.      */
  583.     //After Ducking
  584. //FIXME  if(!(mazub.isDucking()) && getGeologicalFeatures(PosMZx+(mazub.getSpriteDimention()[0]-1), PosMZy+(mazub.getSpriteDimention()[1]-1))==1) {mazub.Ducking=true;}
  585. //FIXME  if(getGeologicalFeatures(PosMZx+(mazub.getSpriteDimention()[0]-1), PosMZy+(mazub.getSpriteDimention()[1]-1))==0 && mazub.isDucking()==true ) {mazub.endDucking();}
  586.  
  587.    
  588.     /**
  589.      * In-game-time timer
  590.      */  
  591.     public double AFithOfAsecond=0.0;
  592.     /**
  593.      * Advances the time for the world and all its objects by the given amount.
  594.      * @param dt
  595.      * The in game time.
  596.      * @throws IllegalArgumentException
  597.      */
  598.  
  599.     public double lessThenTwo = 0.0;
  600.     public boolean canBeDamaged=true;
  601.     public void advancedTime(double dt) throws Exception { if(dt<0 || dt > 0.2) {throw new IllegalArgumentException();}
  602.         Iterator<Object> itr = object_set.iterator();
  603.         while(itr.hasNext()){
  604.             Entity currentEntity=(Entity)itr.next();
  605.             if(currentEntity instanceof Mazub) {
  606.                 BigDecimal time = timePerCm(dt, currentEntity);
  607.                 for (BigDecimal i = BigDecimal.valueOf(0.00); i.compareTo(BigDecimal.valueOf(dt))==-1; i = BigDecimal.valueOf(i.add(time).doubleValue()) ) {
  608.                     if(hashAsGameObject(currentEntity)) {
  609.                     if(mazubInTarget(currentEntity)==true) {didPlayerReachedTarget=true;}else {didPlayerReachedTarget=false;}  
  610.                    
  611.                     currentEntity.advanceTime(time.doubleValue());Earth(currentEntity);
  612.                     isGameOver();
  613.                    
  614.                 }
  615.                 if(currentEntity.getWorld()!= null && OutsideWorldBorder(currentEntity.getActualPosition())) {terminatedGameObject(currentEntity);;}
  616.                
  617.                
  618. //                  if(mazub.isMoving() || mazub.isJumping()) {time = CollisionDetectTime(time,currentEntity);}
  619.                 if(OutsideWorldBorder(currentEntity.getActualPosition())) {terminatedGameObject(currentEntity);;}}}
  620.             else {currentEntity.advanceTime(dt);
  621.                     if(currentEntity instanceof Sneezewort) {MethabolismeSneeze(dt, currentEntity);}
  622.                     if(currentEntity instanceof Skullcab) {MethabolismeSkull(dt, currentEntity);}
  623.                     if(currentEntity instanceof Slime) {MethabolismeSlime(dt, currentEntity);}
  624.                     if(currentEntity instanceof Shark) {MethabolismeShark(dt, currentEntity);}
  625.                     if(currentEntity.getHitpoint()==0) {currentEntity.terminateGameObject();}
  626.                 }
  627.             if(OutsideWorldBorder(currentEntity.getActualPosition())) {currentEntity.setHitPoint(0);}
  628.             }
  629.            
  630.        }
  631.            
  632.     double sneezeTime=0, skullTime=0, slimeTime=0, sharkTime=0;
  633.     int sneezecount=0, skullcount=0, slimecount=0, sharkcount=0;
  634.     /**
  635.      * Sees if mazub and sneezewort collide or not.
  636.      * @param dt
  637.      *      time to be used to advance the time of the given game object.
  638.      * @param currentEntity
  639.      *      The given game object
  640.      * @effect...
  641.      *  Mazub and given game object do not collide
  642.      *      |if(PosMZx+(mazub.getSpriteDimention()[0]-1)<sneeze.getPixelPosition()[0]
  643.      *            || sneeze.getPixelPosition()[0]+(sneeze.getCurrentSprite().getWidth()-1)<PosMZx
  644.      *            || PosMZy+(mazub.getSpriteDimention()[1]-1)<sneeze.getPixelPosition()[1]
  645.      *            || sneeze.getPixelPosition()[1]+(sneeze.getCurrentSprite().getHeight()-1)<mazub.getPixelPosition()[1]
  646.      *            ){}
  647.      *   Else they do collide
  648.      *      |else (if(!(sneeze.isDeadGameObject()) && mazub.getHitpoint()+50<=500  && sneezeTime==0 && sneezecount<4)
  649.      *              |then (mazub.new.getHitPoint()+=50, sneeze.new.getHitPoint()-=1, snew.neezecount+=1;])
  650.      *    Mazub will only gain hitpoint if sneezeTime>=0.6
  651.      *      |if(sneezeTime >=0.6)
  652.      *          |then (new.sneezeTime=0)
  653.      *      |else(new.sneezeTime+=dt)
  654.      */
  655.     public void MethabolismeSneeze(double dt, Entity currentEntity) {
  656.     int PosMZx=mazub.getPixelPosition()[0], PosMZy=mazub.getPixelPosition()[1];
  657.     if(currentEntity instanceof Sneezewort) {
  658.        Sneezewort sneeze=((Sneezewort)currentEntity);
  659.          if(PosMZx+(mazub.getSpriteDimention()[0]-1)<sneeze.getPixelPosition()[0]
  660.                  || sneeze.getPixelPosition()[0]+(sneeze.getCurrentSprite().getWidth()-1)<PosMZx
  661.                  || PosMZy+(mazub.getSpriteDimention()[1]-1)<sneeze.getPixelPosition()[1]
  662.                  || sneeze.getPixelPosition()[1]+(sneeze.getCurrentSprite().getHeight()-1)<mazub.getPixelPosition()[1]
  663.                  ) {}
  664.          else {
  665.             if(!(sneeze.isDeadGameObject()) && mazub.getHitpoint()+50<=500  && sneezeTime==0 )  {
  666.                          mazub.addHitPoint(50); sneeze.addHitPoint(-1);sneezecount+=1;}
  667.                 if(sneezeTime >=0.6) {sneezeTime=0;}
  668.                 else{sneezeTime+=dt;}}
  669.         }
  670.     }
  671.     /**
  672.      * Sees if mazub and skullcab collide or not.
  673.      * @param dt
  674.      *      time to be used to advance the time of the given game object.
  675.      * @param currentEntity
  676.      *      The given game object
  677.      * @effect...
  678.      *  Mazub and given game object do not collide
  679.      *      |if(PosMZx+(mazub.getSpriteDimention()[0]-1)<skull.getPixelPosition()[0]
  680.      *                || skull.getPixelPosition()[0]+(skull.getCurrentSprite().getWidth()-1)<PosMZx
  681.      *                || PosMZy+(mazub.getSpriteDimention()[1]-1)<skull.getPixelPosition()[1]
  682.      *                || skull.getPixelPosition()[1]+(skull.getCurrentSprite().getHeight()-1)<PosMZy
  683.      *                ) {}
  684.      *   Else they do collide
  685.      *      |else (if(!(skull.isDeadGameObject()) && mazub.getHitpoint()+50<=500  && skullTime==0 && skullcount==0)
  686.      *              |then (mazub.new.getHitPoint()+=50, skull.new.gerHitPoint()-=1, new.skullcount+=1;)
  687.      *    Mazub will only gain hitpoint if skullTime>=0.6
  688.      *      |if(skullTime >=0.6)
  689.      *          |then (skullTime=0)
  690.      *      |else(skullTime+=dt)
  691.      */
  692.     public void MethabolismeSkull(double dt, Entity currentEntity) {
  693.         int PosMZx=mazub.getPixelPosition()[0], PosMZy=mazub.getPixelPosition()[1];
  694.         if(currentEntity instanceof Skullcab) {
  695.             Skullcab skull=((Skullcab)currentEntity);
  696.              if(PosMZx+(mazub.getSpriteDimention()[0]-1)<skull.getPixelPosition()[0]
  697.                      || skull.getPixelPosition()[0]+(skull.getCurrentSprite().getWidth()-1)<PosMZx
  698.                      || PosMZy+(mazub.getSpriteDimention()[1]-1)<skull.getPixelPosition()[1]
  699.                      || skull.getPixelPosition()[1]+(skull.getCurrentSprite().getHeight()-1)<PosMZy
  700.                      ) {}
  701.              else {
  702.              if(!(skull.isDeadGameObject()) && mazub.getHitpoint()+50<=500  && skullTime==0 )  {
  703.                  mazub.addHitPoint(50); skull.addHitPoint(-1); skullcount+=1;}
  704.                         if(skullTime >=0.6) {skullTime=0;}
  705.                         else{skullTime+=dt;}}
  706.             }
  707.     }
  708.                  
  709.     /**
  710.      * Sees if mazub and slime collide or not.
  711.      * @param dt
  712.      *      time to be used to advance the time of the given game object.
  713.      * @param currentEntity
  714.      *      The given game object
  715.      * @effect...
  716.      *  Mazub and given game object do not collide
  717.      *      if(PosMZx+(mazub.getSpriteDimention()[0]-1)<slime.getPixelPosition()[0]
  718.      *                || slime.getPixelPosition()[0]+(slime.getCurrentSprite().getWidth()-1)<PosMZx
  719.      *                || PosMZy+(mazub.getSpriteDimention()[1]-1)<slime.getPixelPosition()[1]
  720.      *                || slime.getPixelPosition()[1]+(slime.getCurrentSprite().getHeight()-1)<PosMZy
  721.      *                ||PosMZx+(mazub.getSpriteDimention()[0]-1)<slime.getPixelPosition()[0]
  722.      *                || slime.getPixelPosition()[0]+(slime.getCurrentSprite().getWidth()-1)<PosMZx
  723.      *                || PosMZy+(mazub.getSpriteDimention()[1]-1)<slime.getPixelPosition()[1]
  724.      *                || slime.getPixelPosition()[1]+(slime.getCurrentSprite().getHeight()-1)<PosMZy
  725.      *                ) {}
  726.      *  Else they do collide
  727.      *      |else (if(!(slime.isDeadGameObject()) && mazub.getHitpoint()+50<=500  && slimeTime==0 && slimecount==0)
  728.      *              |then (mazub.new.getHitPoint()-=20, slime.new.gerHitPoint()-=30, new.slimecount+=1;)
  729.      *    Mazub will only lose hitpoint if sneezeTime>=0.6
  730.      *      |if(slimeTime >=0.6)
  731.      *          |then (slimeTime=0)
  732.      *      |else(slimeTime+=dt)
  733.      */
  734.     public void MethabolismeSlime(double dt, Entity currentEntity) {
  735.         int PosMZx=mazub.getPixelPosition()[0], PosMZy=mazub.getPixelPosition()[1];
  736.        
  737.         if(currentEntity instanceof Slime) {
  738.             Slime slime=((Slime)currentEntity);
  739.              if(PosMZx+(mazub.getSpriteDimention()[0]-1)<slime.getPixelPosition()[0]
  740.                      || slime.getPixelPosition()[0]+(slime.getCurrentSprite().getWidth()-1)<PosMZx
  741.                      || PosMZy+(mazub.getSpriteDimention()[1]-1)<slime.getPixelPosition()[1]
  742.                      || slime.getPixelPosition()[1]+(slime.getCurrentSprite().getHeight()-1)<PosMZy
  743.                      || PosMZx+(mazub.getSpriteDimention()[0]-1)<slime.getPixelPosition()[0]
  744.                      || slime.getPixelPosition()[0]+(slime.getCurrentSprite().getWidth()-1)<PosMZx
  745.                      || PosMZy+(mazub.getSpriteDimention()[1]-1)<slime.getPixelPosition()[1]
  746.                      || slime.getPixelPosition()[1]+(slime.getCurrentSprite().getHeight()-1)<PosMZy
  747.                      ) {}
  748.              else {if(!(slime.isDeadGameObject()) && mazub.getHitpoint()+50<=500 && slimeTime==0 && slimecount==0) {
  749.                              Iterator<Object> itr = ((Set<Object>) slime.getSchool()).iterator();
  750.                              mazub.addHitPoint(-20); slime.addHitPoint(-30);
  751.                              while(itr.hasNext())   {((Slime)itr.next()).addHitPoint(-1);}
  752.                              slimecount+=1;
  753.                         }
  754.                     if(slimeTime>=0.6) {slimeTime=0;}
  755.                     else {slimeTime+=dt;}}
  756.           }
  757.     }
  758.    
  759.     /**
  760.      * Sees if mazub and shark collide or not.
  761.      * @param dt
  762.      *      time to be used to advance the time of the given game object.
  763.      * @param currentEntity
  764.      *      The given game object
  765.      * @effect...
  766.      *  Mazub and given game object do not collide
  767.      *      if(PosMZx+(mazub.getSpriteDimention()[0]-1)<shark.getPixelPosition()[0]
  768.      *                || shark.getPixelPosition()[0]+(shark.getCurrentSprite().getWidth()-1)<PosMZx
  769.      *                || PosMZy+(mazub.getSpriteDimention()[1]-1)<shark.getPixelPosition()[1]
  770.      *                || shark.getPixelPosition()[1]+(shark.getCurrentSprite().getHeight()-1)<PosMZy
  771.      *                ) {}
  772.      *  Else they do collide
  773.      *      |else (if(!(shark.isDeadGameObject()) && mazub.getHitpoint()+50<=500  && sharkTime==0 && sharkcount==0)
  774.      *              |then (mazub.new.getHitPoint()-=50, shark.new.gerHitPoint()-=50, new.sharkcount+=1;)
  775.      *    Mazub will only lose hitpoint if sneezeTime>=0.6
  776.      *      |if(sharkTime >=0.6)
  777.      *          |then (sharkTime=0)
  778.      *      |else(sharkTime+=dt)
  779.      */
  780.     public void MethabolismeShark(double dt, Entity currentEntity) {
  781.         int PosMZx=mazub.getPixelPosition()[0], PosMZy=mazub.getPixelPosition()[1];
  782.         if(currentEntity instanceof Shark) {
  783.             Shark shark=((Shark)currentEntity);
  784.              if(PosMZx+(mazub.getSpriteDimention()[0]-1)<shark.getPixelPosition()[0]
  785.                      || shark.getPixelPosition()[0]+(shark.getCurrentSprite().getWidth()-1)<PosMZx
  786.                      || PosMZy+(mazub.getSpriteDimention()[1]-1)<shark.getPixelPosition()[1]
  787.                      || shark.getPixelPosition()[1]+(shark.getCurrentSprite().getHeight()-1)<PosMZy
  788.                      ) {}
  789.              else {if(!(shark.isDeadGameObject()) && mazub.getHitpoint()+50<=500 && sharkTime==0 && sharkcount==0) {
  790.                              shark.addHitPoint(-50); mazub.setHitPoint(-50); sharkcount+=1;}
  791.                     if(sharkTime>=0.6) {sharkTime=0;}
  792.                     else{sharkTime+=dt;}}
  793.             }
  794.     }
  795.  
  796.  
  797.    public int hitsChanged = 0;
  798.    public int totalChanged = 0;
  799.    
  800.    
  801.     /**
  802.     * Collision detect with geologicalfeatures
  803.     */
  804.     public int ElementCollison(Entity currentEntity) {
  805.         if(Element(currentEntity,3)==true){hitsChanged+=-50;totalChanged+=-50;}// 3=Magma
  806.         else if(Element(currentEntity,5)==true){hitsChanged+=-4;totalChanged+=-4;}
  807.         else if(Element(currentEntity,2)==true){hitsChanged+=-2;totalChanged+=-2;} // 2=Water
  808.        
  809.         return hitsChanged;
  810.     }
  811.  /*
  812.      * *****************
  813.      * Collision Detect*
  814.      * *****************
  815.    */
  816.  
  817.  
  818.     /**
  819.      * Boolean value that is true if Mazub will collide with something, and false if not.
  820.      */
  821.     public boolean Overlap;
  822.  
  823.     /**
  824.      * calculates the given time with the entity to a double that gives a time for each cm that changed
  825.      *
  826.      * @param time
  827.      *      is the given time that has to be calculated
  828.      * @param currentEntity
  829.      *      is the given Entity where his time per cm
  830.      * @return
  831.      *   the time per centimeter
  832.      *
  833.      */
  834.     public BigDecimal timePerCm(double time,Entity currentEntity) {
  835.        
  836.         //Calculation of time fragments with given acceleration, velocity and time.
  837.         BigDecimal currentVelocityX= BigDecimal.valueOf(currentEntity.getVelocity()[0]), currentVelocityY= BigDecimal.valueOf(currentEntity.getVelocity()[1]), currentAccelerationX= BigDecimal.valueOf(currentEntity.getAcceleration()[0]),currentAccelerationY= BigDecimal.valueOf(currentEntity.getAcceleration()[1]);
  838.         BigDecimal cm= BigDecimal.valueOf(0.01);
  839.         BigDecimal timedt = BigDecimal.valueOf(time);
  840.         BigDecimal mathsqr1=BigDecimal.valueOf(Math.sqrt((currentAccelerationX.pow(2).add(currentAccelerationY.pow(2))).doubleValue()));
  841.         BigDecimal mathsqr2=BigDecimal.valueOf(Math.sqrt((currentVelocityX.pow(2).add(currentVelocityY.pow(2))).doubleValue()));
  842.         BigDecimal divider = mathsqr1.add(mathsqr2.multiply(timedt));
  843.         if(divider.compareTo(BigDecimal.valueOf(0.0))==0) {return BigDecimal.valueOf(time);}
  844.         BigDecimal dt= BigDecimal.valueOf(cm.divide((divider), 16, RoundingMode.HALF_UP).doubleValue());
  845.         return dt;
  846.            
  847.     }
  848.  
  849.    
  850.    
  851.      /*
  852.      * *************
  853.      * Game Objects*
  854.      * *************
  855.      */
  856. //    public boolean isDeadGameObject()
  857.    
  858.     /**
  859.      * is the set of all objects inside the world.
  860.      */
  861.     public  Set<Object> object_set = new HashSet<Object>();
  862.    
  863.     /**
  864.      * @return
  865.      *      returns a set of all game objects
  866.      *      |return object_set;
  867.      */
  868.     public Set<Object> getAllGameObjects(){return object_set;}
  869.    
  870.    
  871.     /**
  872.      * sets the set of all game objects of this world to the given set
  873.      *
  874.      * @param newSet
  875.      *      a set of objects
  876.      * @effect
  877.      *      sets the set of all game objects of this world to the given set
  878.      *      |object_set = newSet;
  879.      */
  880.     public void setAllGameObjects(Set<Object> newSet){object_set = newSet;}
  881.    
  882.     /**
  883.      * Remove the given object to the given world.
  884.      * @effect
  885.      *      Remove the given object to the given world.
  886.      *      |object_set.remove(object);
  887.      */
  888.     public void removeGameObject(Object object){
  889.         object_set.remove(object);}
  890.    
  891.  
  892.     /**
  893.      * add a gameObject inside the set of all given objects.
  894.      *
  895.      * @param gameObject
  896.      *      a given gameObject
  897.      *      |
  898.      * @param world
  899.      * @effect
  900.      *      if the gameObject is an instance of mazub and mazub  
  901.      * @throws Exception
  902.      *      if the world already has 100 gameObject throw a exception
  903.      *      |if(object_set.size()>=100)
  904.      *      |then throw new Exception("Already 100 gameObjects");
  905.      * @effect
  906.      *      if the world has less then 100 gameObject add the gameObject inside the set of all given objects and if gameObject has no world,
  907.      *      set the world of the gameObject to this world
  908.      *      | if(object_set.size()<100)
  909.      *      | then object_set.add(gameObject);
  910.      *      | if(gameObject.getWorld()!=null)
  911.      *      | then gameObject.setWorld(this);
  912.      */
  913.     public void addGameObject(Entity gameObject, World world) throws Exception {
  914. //      if(world.IsterminatedWorld && gameObject==null) {throw new Exception("Invalide arguments");}
  915.         if(gameObject.getWorld()!=null) {throw new Exception();}
  916.         if (gameObject instanceof Mazub && (mazub == null ||gameObject==null)) {mazub = (Mazub)gameObject;}
  917.         if(world.hashAsGameObject(gameObject)) {throw new Exception("...");}
  918.         else if(object_set.size()<100) {object_set.add(gameObject);gameObject.setWorld(world);}
  919.         else {throw new Exception("Already 100 gameObjects");}
  920.     }
  921.    
  922. //    public void DeathGameObject() {
  923. //        if(mazub.getPixelPosition()[0]>getSizeInPixels()[0] || mazub.getPixelPosition()[1]>getSizeInPixels()[1]) {
  924. //            mazub.setHitPoint(0);}}
  925.    
  926.     /**
  927.      * returns if the game is over
  928.      *
  929.      * @return
  930.      *      if the mazub is dead return true
  931.      *      |if(mazub.isDeadGameObject())
  932.      *      |then result = true;
  933.      * @return
  934.      *      if the mazub reached the target variable
  935.      *      |if(didPlayerReachedTarget)
  936.      *      |then result = true;
  937.      * @return
  938.      *      else the game isn't over
  939.      *      |result = false
  940.      *
  941.      */
  942.     public boolean isGameOver() {
  943.         if(mazub.isDeadGameObject()) {return true;}
  944.         if(didPlayerReachedTarget) {return true;}
  945.         return false;
  946.     }
  947.    
  948.     /**
  949.      * returns that the object is inside this world
  950.      *
  951.      * @param object
  952.      *      a given object
  953.      * @return
  954.      *      if the object is inside the set of all game object
  955.      *      |if(object_set.contains(object)) then result = true
  956.      * @return
  957.      *      if the object is not inside of the set of all game object
  958.      *      |if(!object_set.contains(object)) then result = false
  959.      */
  960.     public boolean hashAsGameObject(Object object) {if(object_set.contains(object)) {return true;}else {return false;}}
  961.     /*
  962.      *********************
  963.      * Terminate*
  964.      *********************
  965.      */
  966.     /**
  967.      * Start a game in the given world.
  968.      */
  969.     public void startGame() throws ModelException{}
  970.    
  971.     /*
  972.      *********************
  973.      * Mazub*
  974.      *********************
  975.      */
  976.       /**
  977.      * Variable storing the Mazzub of this world
  978.      */
  979.       private Mazub mazub;
  980.       private boolean didPlayerReachedTarget=false;
  981.  
  982.         /**
  983.          * returns this mazub
  984.          *
  985.          * @return
  986.          *      returns this mazub
  987.          *      |result = this.mazub
  988.          */
  989.         public Mazub getMazub() {
  990.             return mazub;
  991.         }  
  992.        
  993.         /**
  994.          * set this mazub of the world to the given newmazub
  995.          *
  996.          * @param newMazub
  997.          * @effect
  998.          *      set this mazub of the world to the given newmazub
  999.          *      |mazub=newmazub
  1000.          */
  1001.         public void setMazub(Mazub newMazub) {
  1002.             mazub=newMazub;
  1003.         }  
  1004.        
  1005.         /**
  1006.          *returns if the player has won
  1007.          *
  1008.          * @return
  1009.          *      if the played reached the target return true
  1010.          *      |if(didPlayerReachedTarget) then result = true
  1011.          * @return
  1012.          *      if the mazubb is dead return false
  1013.          *      |else if(mazub.isDeadGameObject()==true) then result= false
  1014.          * @return
  1015.          *      otherwise false
  1016.          *      |else result= false
  1017.          *     
  1018.          */
  1019.         public boolean DidPlayerWin() {
  1020.             if(didPlayerReachedTarget) {return true;}
  1021.             else if(mazub.isDeadGameObject()==true) {return false;}
  1022.             else {return false;}
  1023.         }
  1024.  
  1025.     /*
  1026.      *********************
  1027.      * School*
  1028.      *********************
  1029.      */
  1030.  
  1031.    
  1032.     /**
  1033.      * results either false or true weither the gameobject is removed or not
  1034.      *
  1035.      * @param gameObject
  1036.      *      the given game object
  1037.      * @return
  1038.      *      if given object is terminated and it doesn't contain in the world
  1039.      *      | if(((Entity)gameObject).isTerminatedGameObject()==true||hashAsGameObject(gameObject))
  1040.      *          |then (result= false)
  1041.      * @return
  1042.      *      if the given object is terminated or it does contain in the world
  1043.      *      |if(((Entity)gameObject).isTerminatedGameObject()==false||!hashAsGameObject(gameObject))
  1044.      *          |then (result==false)
  1045.      */
  1046.     public boolean isTerminatedGameObject(Object gameObject) {
  1047.         if(((Entity)gameObject).isTerminatedGameObject()==true||hashAsGameObject(gameObject)){return false;}
  1048.         else {return true;}}
  1049.        
  1050.     /**
  1051.      * terminate the game object
  1052.      *
  1053.      * @param gameObject
  1054.      *      The game object that has to be terminated
  1055.      * @effect
  1056.      *  If game objec is of type Mazub
  1057.      *      |if(gameObject instanceof Mazub)
  1058.      *  If the game object belong to a world that is not equal to null
  1059.      *          |then if(gameObject.getWorld()!=null)
  1060.      *              |then (((Mazub) gameObject).terminateGameObject(((Entity)gameObject)))
  1061.      *          |then (mazub = null;removeGameObject(gameObject))
  1062.      *  Else if the game object belong to a world that is not equal to null
  1063.      *       |else(if(gameObject.getWorld()!=null))
  1064.      *          |then (gameObject.terminateGameObject(((Entity)gameObject));)
  1065.      *       |removeGameObject(gameObject)
  1066.      */
  1067.     public void terminatedGameObject(Entity gameObject) {
  1068.         if(gameObject instanceof Mazub) {if(gameObject.getWorld()!=null) {((Mazub) gameObject).terminateGameObject();}
  1069.             mazub = null; removeGameObject(gameObject);}
  1070.         else {if(gameObject.getWorld()!=null) {gameObject.terminateGameObject();removeGameObject(gameObject);}
  1071.         removeGameObject(gameObject);}
  1072.     }
  1073.    
  1074.     /**
  1075.      * Calculate if mazub will still be in world after it has been set to newpos
  1076.      * @param newpos
  1077.      *      new position for mazub
  1078.      * @effect if newpos is smaller than smalles wolrdboundries or larger than largest worldboundries
  1079.      *      |if(newpos[0]<0||newpos[0]>getSizeInPixels()[0]||newpos[1]<0||newpos[1]>getSizeInPixels()[1])
  1080.      *          |then(result==true)
  1081.      *      |else(result==false)
  1082.      * @return
  1083.      *      |result==true ||
  1084.      *      |result==false
  1085.      */
  1086.     public boolean calculateInsideOfWorld(int[] newpos) {
  1087.         if(newpos[0]<0||newpos[0]>getSizeInPixels()[0]||newpos[1]<0||newpos[1]>getSizeInPixels()[1]) {return true;}
  1088.         else {return false;}
  1089.     }
  1090.    
  1091.    
  1092.     public Set<School> SchoolSet=new HashSet<School>();
  1093.     /**
  1094.      * @post...
  1095.      *      |new.getSchool().contains(school)==true
  1096.      */
  1097.     public void setSchools(Set<School> school) {
  1098.         SchoolSet=school;
  1099.     }
  1100.     /**
  1101.      *
  1102.      * @param newSchool
  1103.      *      new school to be added
  1104.      * @throws Exception
  1105.      *      If the SchoolSet already has the elemnents
  1106.      *          |if(SchoolSet.size()==10)
  1107.      *              |then (throw new Exception("To many School in world."))
  1108.      */
  1109.     public void addSchool(School newSchool)throws Exception {
  1110.         if(SchoolSet.size()<10) {
  1111.         SchoolSet.add(newSchool);}
  1112.         else {throw new Exception("To many School in world.");}
  1113.     }
  1114.  
  1115.     /**
  1116.      *
  1117.      * @return...
  1118.      *      |result ==SchoolSet
  1119.      */
  1120.     public Set<School> getAllSchools() {
  1121.         return SchoolSet;
  1122.     }
  1123.    
  1124.    public boolean OutsideWorldBorder(double[] newPosition){
  1125.        if(newPosition[0] < 0 || newPosition[0] > calculateToActual(getSizeInPixels()[0]) || newPosition[1] <0 || newPosition[1] > calculateToActual(getSizeInPixels()[1]) ) {return true;}
  1126.        else {return false;}}
  1127.    
  1128.    /**
  1129.     * True is world got terminated. False if not.
  1130.     */
  1131.    public boolean IsterminatedWorld=false;
  1132.    /**
  1133.     * Method to terminate current world of object
  1134.     *
  1135.     */
  1136.     public void terminateWorld() {
  1137.         Iterator<Object> itr = object_set.iterator();
  1138.         while(itr.hasNext()){
  1139.             Entity currentEntity=(Entity)itr.next();
  1140.             (currentEntity).terminateGameObject();}
  1141.             object_set.clear();
  1142.             IsterminatedWorld=true;
  1143.     }
  1144.    
  1145.     /**
  1146.      * Calculate actual to pixel
  1147.      * @param actual
  1148.      * @return
  1149.      *      |result==((int)(actual*100))
  1150.      */
  1151.     public int calculateToPixel (double actual) {return ((int)(actual*100));}
  1152.     /**
  1153.      * Calculate pixle to actual
  1154.      * @param pixel
  1155.      * @return
  1156.      *      |result==((double)(pixel/100))
  1157.      */
  1158.     public double calculateToActual (int pixel) {return ((double)(pixel/100));}
  1159.    
  1160. }
Advertisement
Add Comment
Please, Sign In to add comment