1a: encapsulate classes with factory
This commit is contained in:
parent
11ee2dc2ea
commit
f0ad616ae2
@ -1,8 +1,7 @@
|
|||||||
package fr.enssat.BoulderDash.controllers;
|
package fr.enssat.BoulderDash.controllers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.models.DirtModel;
|
import fr.enssat.BoulderDash.models.displayableElement.DisplayableElementModel;
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +61,7 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
||||||
|
|
||||||
if(elementModel == null) {
|
if(elementModel == null) {
|
||||||
elementModel = new DirtModel();
|
elementModel = DisplayableElementModel.newDirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
String spriteName = elementModel.getSpriteName();
|
String spriteName = elementModel.getSpriteName();
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package fr.enssat.BoulderDash.controllers;
|
package fr.enssat.BoulderDash.controllers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
|
||||||
import fr.enssat.BoulderDash.views.MenuView;
|
import fr.enssat.BoulderDash.views.MenuView;
|
||||||
import fr.enssat.BoulderDash.views.GameView;
|
import fr.enssat.BoulderDash.views.GameView;
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package fr.enssat.BoulderDash.controllers;
|
package fr.enssat.BoulderDash.controllers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
import fr.enssat.BoulderDash.models.displayableElement.DisplayableElementModel;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.controllers.RockfordUpdateController;
|
|
||||||
import fr.enssat.BoulderDash.controllers.BoulderAndDiamondController;
|
|
||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
@ -6,10 +6,9 @@ import java.awt.event.ActionListener;
|
|||||||
import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException;
|
import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException;
|
||||||
import fr.enssat.BoulderDash.helpers.LevelRemoveHelper;
|
import fr.enssat.BoulderDash.helpers.LevelRemoveHelper;
|
||||||
import fr.enssat.BoulderDash.helpers.LevelSaveHelper;
|
import fr.enssat.BoulderDash.helpers.LevelSaveHelper;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.HelpView;
|
import fr.enssat.BoulderDash.views.HelpView;
|
||||||
import fr.enssat.BoulderDash.views.LevelEditorView;
|
import fr.enssat.BoulderDash.views.LevelEditorView;
|
||||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.enssat.BoulderDash.controllers;
|
package fr.enssat.BoulderDash.controllers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.LevelEditorView;
|
import fr.enssat.BoulderDash.views.LevelEditorView;
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
@ -4,10 +4,8 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.MenuView;
|
import fr.enssat.BoulderDash.views.MenuView;
|
||||||
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
|
||||||
import fr.enssat.BoulderDash.controllers.GameController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller to navigate between the different views
|
* Controller to navigate between the different views
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.enssat.BoulderDash.controllers;
|
package fr.enssat.BoulderDash.controllers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ElementPositionUpdateHelper
|
* ElementPositionUpdateHelper
|
||||||
|
@ -2,8 +2,8 @@ package fr.enssat.BoulderDash.helpers;
|
|||||||
|
|
||||||
import fr.enssat.BoulderDash.exceptions.UnknownModelException;
|
import fr.enssat.BoulderDash.exceptions.UnknownModelException;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.RockfordModel;
|
import fr.enssat.BoulderDash.models.displayableElement.RockfordModel;
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
import fr.enssat.BoulderDash.models.displayableElement.DisplayableElementModel;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
@ -3,8 +3,6 @@ package fr.enssat.BoulderDash.helpers;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -17,8 +15,7 @@ import org.w3c.dom.Document;
|
|||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
import fr.enssat.BoulderDash.models.displayableElement.DisplayableElementModel;
|
||||||
import fr.enssat.BoulderDash.models.DirtModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,7 +317,7 @@ public class LevelSaveHelper {
|
|||||||
|
|
||||||
// Null?
|
// Null?
|
||||||
if(curGridElement == null) {
|
if(curGridElement == null) {
|
||||||
curGridElement = new DirtModel();
|
curGridElement = DisplayableElementModel.newDirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve current values
|
// Retrieve current values
|
||||||
|
@ -2,16 +2,7 @@ package fr.enssat.BoulderDash.helpers;
|
|||||||
|
|
||||||
import fr.enssat.BoulderDash.exceptions.UnknownModelException;
|
import fr.enssat.BoulderDash.exceptions.UnknownModelException;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.ExpandingWallModel;
|
import fr.enssat.BoulderDash.models.displayableElement.DisplayableElementModel;
|
||||||
import fr.enssat.BoulderDash.models.RockfordModel;
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
import fr.enssat.BoulderDash.models.EmptyModel;
|
|
||||||
import fr.enssat.BoulderDash.models.BrickWallModel;
|
|
||||||
import fr.enssat.BoulderDash.models.BoulderModel;
|
|
||||||
import fr.enssat.BoulderDash.models.DiamondModel;
|
|
||||||
import fr.enssat.BoulderDash.models.DirtModel;
|
|
||||||
import fr.enssat.BoulderDash.models.MagicWallModel;
|
|
||||||
import fr.enssat.BoulderDash.models.SteelWallModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,19 +44,60 @@ public class ModelConvertHelper {
|
|||||||
* @return Model associated to given sprite name
|
* @return Model associated to given sprite name
|
||||||
*/
|
*/
|
||||||
public DisplayableElementModel toModel(String spriteName, boolean isConvertible) throws UnknownModelException {
|
public DisplayableElementModel toModel(String spriteName, boolean isConvertible) throws UnknownModelException {
|
||||||
// Instantiates the sprite element matching the given sprite name
|
DisplayableElementModel element;
|
||||||
return switch (spriteName) {
|
|
||||||
case "black", "Black" -> new EmptyModel();
|
// Instanciates the sprite element matching the given sprite name
|
||||||
case "boulder", "Boulder" -> new BoulderModel(isConvertible);
|
switch (spriteName) {
|
||||||
case "brickwall", "Brick Wall" -> new BrickWallModel();
|
case "black":
|
||||||
case "diamond", "Diamond" -> new DiamondModel();
|
case "Black":
|
||||||
case "dirt", "Dirt" -> new DirtModel();
|
element = DisplayableElementModel.newEmptyModel();
|
||||||
case "magicwall", "Magic Wall" -> new MagicWallModel();
|
break;
|
||||||
case "rockford", "Rockford" -> new RockfordModel();
|
|
||||||
case "steelwall", "Steel Wall" -> new SteelWallModel();
|
case "boulder":
|
||||||
case "expandingwall", "Expanding Wall" -> new ExpandingWallModel();
|
case "Boulder":
|
||||||
default -> throw new UnknownModelException("Unknown model element > " + spriteName);
|
element = DisplayableElementModel.newBoulderModel(isConvertible);
|
||||||
};
|
break;
|
||||||
|
|
||||||
|
case "brickwall":
|
||||||
|
case "Brick Wall":
|
||||||
|
element = DisplayableElementModel.newBrickWallModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "diamond":
|
||||||
|
case "Diamond":
|
||||||
|
element = DisplayableElementModel.newDiamondModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "dirt":
|
||||||
|
case "Dirt":
|
||||||
|
element = DisplayableElementModel.newDirtModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "magicwall":
|
||||||
|
case "Magic Wall":
|
||||||
|
element = DisplayableElementModel.newMagicWallModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "rockford":
|
||||||
|
case "Rockford":
|
||||||
|
element = DisplayableElementModel.newRockfordModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "steelwall":
|
||||||
|
case "Steel Wall":
|
||||||
|
element = DisplayableElementModel.newSteelWallModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "expandingwall":
|
||||||
|
case "Expanding Wall":
|
||||||
|
element = DisplayableElementModel.newExpandingWallModel();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnknownModelException("Unknown model element > " + spriteName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,15 +32,8 @@ public class BoulderModel extends DisplayableElementModel {
|
|||||||
collideSound = "die";
|
collideSound = "die";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
BoulderModel(boolean convertible) {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public BoulderModel(boolean convertible) {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound, convertible);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound, convertible);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoulderModel() {
|
|
||||||
this(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +34,7 @@ public class BrickWallModel extends DisplayableElementModel {
|
|||||||
collideSound = "touch";
|
collideSound = "touch";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
BrickWallModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public BrickWallModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +34,7 @@ public class CursorModel extends DisplayableElementModel {
|
|||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
CursorModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public CursorModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
@ -1,10 +1,8 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DiamondModel
|
* DiamondModel
|
||||||
@ -45,10 +43,7 @@ public class DiamondModel extends DisplayableElementModel {
|
|||||||
collideSound = "coin";
|
collideSound = "coin";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
DiamondModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public DiamondModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, false, collideSound);
|
||||||
|
|
||||||
this.initSprites();
|
this.initSprites();
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +37,7 @@ public class DirtModel extends DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public DirtModel() {
|
DirtModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
@ -1,4 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -68,6 +68,55 @@ public abstract class DisplayableElementModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BoulderModel newBoulderModel() {
|
||||||
|
return DisplayableElementModel.newBoulderModel(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoulderModel newBoulderModel(boolean convertible) {
|
||||||
|
return new BoulderModel(convertible);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BrickWallModel newBrickWallModel() {
|
||||||
|
return new BrickWallModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CursorModel newCursorModel() {
|
||||||
|
return new CursorModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DiamondModel newDiamondModel() {
|
||||||
|
return new DiamondModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DirtModel newDirtModel() {
|
||||||
|
return new DirtModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DoorModel newDoorModel() {
|
||||||
|
return new DoorModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EmptyModel newEmptyModel() {
|
||||||
|
return new EmptyModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExpandingWallModel newExpandingWallModel() {
|
||||||
|
return new ExpandingWallModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MagicWallModel newMagicWallModel() {
|
||||||
|
return new MagicWallModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static RockfordModel newRockfordModel() {
|
||||||
|
return new RockfordModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SteelWallModel newSteelWallModel() {
|
||||||
|
return new SteelWallModel();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the 'destructible' value
|
* Gets the 'destructible' value
|
||||||
*
|
*
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +34,7 @@ public class DoorModel extends DisplayableElementModel {
|
|||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
DoorModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public DoorModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +34,7 @@ public class EmptyModel extends DisplayableElementModel {
|
|||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
EmptyModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public EmptyModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
|
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +34,7 @@ public class ExpandingWallModel extends DisplayableElementModel {
|
|||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ExpandingWallModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public ExpandingWallModel() {
|
|
||||||
super(destructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(destructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException;
|
import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException;
|
||||||
import fr.enssat.BoulderDash.exceptions.UnknownModelException;
|
import fr.enssat.BoulderDash.exceptions.UnknownModelException;
|
||||||
import fr.enssat.BoulderDash.helpers.LevelLoadHelper;
|
import fr.enssat.BoulderDash.helpers.LevelLoadHelper;
|
||||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||||
import fr.enssat.BoulderDash.helpers.ModelConvertHelper;
|
import fr.enssat.BoulderDash.helpers.ModelConvertHelper;
|
||||||
|
import fr.enssat.BoulderDash.models.GameInformationModel;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
@ -74,7 +75,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
|
this.sizeWidth = this.levelLoadHelper.getWidthSizeValue();
|
||||||
this.sizeHeight = this.levelLoadHelper.getHeightSizeValue();
|
this.sizeHeight = this.levelLoadHelper.getHeightSizeValue();
|
||||||
|
|
||||||
this.cursorModel = new CursorModel();
|
this.cursorModel = DisplayableElementModel.newCursorModel();
|
||||||
this.gameInformationModel = new GameInformationModel(this.levelLoadHelper.getDiamondsToCatch());
|
this.gameInformationModel = new GameInformationModel(this.levelLoadHelper.getDiamondsToCatch());
|
||||||
|
|
||||||
this.createLimits();
|
this.createLimits();
|
||||||
@ -123,7 +124,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
|
|
||||||
for (int x = 0; x < levelModel.sizeWidth; x++) {
|
for (int x = 0; x < levelModel.sizeWidth; x++) {
|
||||||
for (int y = 0; y < levelModel.sizeHeight; y++) {
|
for (int y = 0; y < levelModel.sizeHeight; y++) {
|
||||||
levelModel.groundGrid[x][y] = new DirtModel();
|
levelModel.groundGrid[x][y] = DisplayableElementModel.newDirtModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,12 +157,12 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
int maxHeight = this.sizeHeight - 1;
|
int maxHeight = this.sizeHeight - 1;
|
||||||
|
|
||||||
for (int x = 0; x < this.sizeWidth; x++) {
|
for (int x = 0; x < this.sizeWidth; x++) {
|
||||||
this.groundGrid[x][0] = new SteelWallModel();
|
this.groundGrid[x][0] = DisplayableElementModel.newSteelWallModel();
|
||||||
this.groundGrid[x][maxHeight] = new SteelWallModel();
|
this.groundGrid[x][maxHeight] = DisplayableElementModel.newSteelWallModel();
|
||||||
}
|
}
|
||||||
for (int y = 0; y < this.sizeHeight; y++) {
|
for (int y = 0; y < this.sizeHeight; y++) {
|
||||||
this.groundGrid[0][y] = new SteelWallModel();
|
this.groundGrid[0][y] = DisplayableElementModel.newSteelWallModel();
|
||||||
this.groundGrid[maxWidth][y] = new SteelWallModel();
|
this.groundGrid[maxWidth][y] = DisplayableElementModel.newSteelWallModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +255,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
// Check that we are not out of bound...
|
// Check that we are not out of bound...
|
||||||
if (this.isOutOfBounds(posX, posY) == false) {
|
if (this.isOutOfBounds(posX, posY) == false) {
|
||||||
// Create a new empty model in the old pos of Rockford
|
// Create a new empty model in the old pos of Rockford
|
||||||
this.groundGrid[oldX][oldY] = new EmptyModel();
|
this.groundGrid[oldX][oldY] = DisplayableElementModel.newEmptyModel();
|
||||||
|
|
||||||
// Save the x / y pos of Rockford in the levelModel only
|
// Save the x / y pos of Rockford in the levelModel only
|
||||||
this.updateRockfordPosition(posX, posY);
|
this.updateRockfordPosition(posX, posY);
|
||||||
@ -270,7 +271,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
private void spawnExit() {
|
private void spawnExit() {
|
||||||
int x = (int) (Math.random() * (this.getSizeHeight() - 2));
|
int x = (int) (Math.random() * (this.getSizeHeight() - 2));
|
||||||
int y = (int) (Math.random() * (this.getSizeWidth() - 2));
|
int y = (int) (Math.random() * (this.getSizeWidth() - 2));
|
||||||
this.groundGrid[x + 1][y + 1] = new DoorModel();
|
this.groundGrid[x + 1][y + 1] = DisplayableElementModel.newDoorModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,7 +348,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
DisplayableElementModel elementModel = this.getDisplayableElement(x, y);
|
DisplayableElementModel elementModel = this.getDisplayableElement(x, y);
|
||||||
|
|
||||||
if(elementModel == null) {
|
if(elementModel == null) {
|
||||||
return new DirtModel().getSprite();
|
return DisplayableElementModel.newDirtModel().getSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
return elementModel.getSprite();
|
return elementModel.getSprite();
|
||||||
@ -361,7 +362,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
public BufferedImage getCursorImage() {
|
public BufferedImage getCursorImage() {
|
||||||
|
|
||||||
if (this.cursorModel == null) {
|
if (this.cursorModel == null) {
|
||||||
this.cursorModel = new CursorModel();
|
this.cursorModel = DisplayableElementModel.newCursorModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.cursorModel.getSprite();
|
return this.cursorModel.getSprite();
|
||||||
@ -484,7 +485,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void updateSprites(int x, int y) {
|
public void updateSprites(int x, int y) {
|
||||||
if(groundGrid[x][y] == null) {
|
if(groundGrid[x][y] == null) {
|
||||||
groundGrid[x][y] = new DirtModel();
|
groundGrid[x][y] = DisplayableElementModel.newDirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
groundGrid[x][y].update(System.currentTimeMillis());
|
groundGrid[x][y].update(System.currentTimeMillis());
|
||||||
@ -653,15 +654,15 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y Object vertical position
|
* @param y Object vertical position
|
||||||
*/
|
*/
|
||||||
public void exploseGround(int x, int y) {
|
public void exploseGround(int x, int y) {
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x + 1][y] = new EmptyModel();
|
this.groundGrid[x + 1][y] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x - 1][y] = new EmptyModel();
|
this.groundGrid[x - 1][y] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x][y + 1] = new EmptyModel();
|
this.groundGrid[x][y + 1] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x + 1][y + 1] = new EmptyModel();
|
this.groundGrid[x + 1][y + 1] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x - 1][y + 1] = new EmptyModel();
|
this.groundGrid[x - 1][y + 1] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x][y - 1] = new EmptyModel();
|
this.groundGrid[x][y - 1] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x + 1][y - 1] = new EmptyModel();
|
this.groundGrid[x + 1][y - 1] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x - 1][y - 1] = new EmptyModel();
|
this.groundGrid[x - 1][y - 1] = DisplayableElementModel.newEmptyModel();
|
||||||
this.rockford.setHasExplosed(true);
|
this.rockford.setHasExplosed(true);
|
||||||
|
|
||||||
// Again a sleep to notify the observers properly
|
// Again a sleep to notify the observers properly
|
||||||
@ -683,7 +684,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
public void makeThisDisplayableElementFall(int x, int y) {
|
public void makeThisDisplayableElementFall(int x, int y) {
|
||||||
this.groundGrid[x][y].setFalling(true);
|
this.groundGrid[x][y].setFalling(true);
|
||||||
this.groundGrid[x][y + 1] = this.groundGrid[x][y];
|
this.groundGrid[x][y + 1] = this.groundGrid[x][y];
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -695,7 +696,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
public void makeThisBoulderSlideLeft(int x, int y) {
|
public void makeThisBoulderSlideLeft(int x, int y) {
|
||||||
this.groundGrid[x][y].setFalling(true);
|
this.groundGrid[x][y].setFalling(true);
|
||||||
this.groundGrid[x - 1][y + 1] = this.groundGrid[x][y];
|
this.groundGrid[x - 1][y + 1] = this.groundGrid[x][y];
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -707,7 +708,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
public void makeThisBoulderSlideRight(int x, int y) {
|
public void makeThisBoulderSlideRight(int x, int y) {
|
||||||
this.groundGrid[x][y].setFalling(true);
|
this.groundGrid[x][y].setFalling(true);
|
||||||
this.groundGrid[x + 1][y + 1] = this.groundGrid[x][y];
|
this.groundGrid[x + 1][y + 1] = this.groundGrid[x][y];
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -717,8 +718,8 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y Object vertical position
|
* @param y Object vertical position
|
||||||
*/
|
*/
|
||||||
public void transformThisBoulderIntoADiamond(int x, int y) {
|
public void transformThisBoulderIntoADiamond(int x, int y) {
|
||||||
this.groundGrid[x][y + 2] = new DiamondModel();
|
this.groundGrid[x][y + 2] = DisplayableElementModel.newDiamondModel();
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -729,7 +730,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void moveThisBoulderToRight(int x, int y) {
|
public void moveThisBoulderToRight(int x, int y) {
|
||||||
this.groundGrid[x + 1][y] = this.groundGrid[x][y];
|
this.groundGrid[x + 1][y] = this.groundGrid[x][y];
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -740,7 +741,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void moveThisBoulderToLeft(int x, int y) {
|
public void moveThisBoulderToLeft(int x, int y) {
|
||||||
this.groundGrid[x - 1][y] = this.groundGrid[x][y];
|
this.groundGrid[x - 1][y] = this.groundGrid[x][y];
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -750,7 +751,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y Object vertical position
|
* @param y Object vertical position
|
||||||
*/
|
*/
|
||||||
public void deleteThisBoulder(int x, int y) {
|
public void deleteThisBoulder(int x, int y) {
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -769,8 +770,8 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y
|
* @param y
|
||||||
*/
|
*/
|
||||||
public void exploseThisBrickWall(int x, int y) {
|
public void exploseThisBrickWall(int x, int y) {
|
||||||
this.groundGrid[x][y] = new EmptyModel();
|
this.groundGrid[x][y] = DisplayableElementModel.newEmptyModel();
|
||||||
this.groundGrid[x][y + 1] = new EmptyModel();
|
this.groundGrid[x][y + 1] = DisplayableElementModel.newEmptyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -780,7 +781,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y
|
* @param y
|
||||||
*/
|
*/
|
||||||
public void expandThisWallToLeft(int x, int y) {
|
public void expandThisWallToLeft(int x, int y) {
|
||||||
this.groundGrid[x - 1][y] = new ExpandingWallModel();
|
this.groundGrid[x - 1][y] = DisplayableElementModel.newExpandingWallModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -790,7 +791,7 @@ public class LevelModel extends Observable implements Runnable {
|
|||||||
* @param y
|
* @param y
|
||||||
*/
|
*/
|
||||||
public void expandThisWallToRight(int x, int y) {
|
public void expandThisWallToRight(int x, int y) {
|
||||||
this.groundGrid[x + 1][y] = new ExpandingWallModel();
|
this.groundGrid[x + 1][y] = DisplayableElementModel.newExpandingWallModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,10 +1,8 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MagicWallModel
|
* MagicWallModel
|
||||||
@ -52,7 +50,7 @@ public class MagicWallModel extends DisplayableElementModel {
|
|||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*/
|
*/
|
||||||
public MagicWallModel() {
|
MagicWallModel() {
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.currentFrame = 0;
|
this.currentFrame = 0;
|
||||||
this.speed = 100;
|
this.speed = 100;
|
@ -1,10 +1,8 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RockfordModel
|
* RockfordModel
|
||||||
@ -72,10 +70,7 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
collideSound = null;
|
collideSound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
RockfordModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public RockfordModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
// Speed of the animation of the sprite
|
// Speed of the animation of the sprite
|
||||||
this.setSpeed(100);
|
this.setSpeed(100);
|
@ -1,6 +1,4 @@
|
|||||||
package fr.enssat.BoulderDash.models;
|
package fr.enssat.BoulderDash.models.displayableElement;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +34,7 @@ public class SteelWallModel extends DisplayableElementModel {
|
|||||||
collideSound = "touch";
|
collideSound = "touch";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
SteelWallModel() {
|
||||||
* Class constructor
|
|
||||||
*/
|
|
||||||
public SteelWallModel() {
|
|
||||||
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
super(isDestructible, canMove, spriteName, priority, impactExplosive, animate, falling, collideSound);
|
||||||
this.loadSprite(spriteName);
|
this.loadSprite(spriteName);
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package fr.enssat.BoulderDash.views;
|
package fr.enssat.BoulderDash.views;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.views.GroundView;
|
|
||||||
import fr.enssat.BoulderDash.controllers.GameController;
|
import fr.enssat.BoulderDash.controllers.GameController;
|
||||||
import fr.enssat.BoulderDash.controllers.GameKeyController;
|
import fr.enssat.BoulderDash.controllers.GameKeyController;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -7,9 +7,7 @@ import java.util.Observable;
|
|||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.controllers.GameController;
|
import fr.enssat.BoulderDash.controllers.GameController;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.GameGroundView;
|
|
||||||
import fr.enssat.BoulderDash.views.InformationPanel;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package fr.enssat.BoulderDash.views;
|
package fr.enssat.BoulderDash.views;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import java.util.Observer;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package fr.enssat.BoulderDash.views;
|
package fr.enssat.BoulderDash.views;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.views.GroundView;
|
|
||||||
import fr.enssat.BoulderDash.views.LevelEditorView;
|
|
||||||
import fr.enssat.BoulderDash.controllers.LevelEditorKeyController;
|
import fr.enssat.BoulderDash.controllers.LevelEditorKeyController;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,10 +8,7 @@ import java.util.Observer;
|
|||||||
import fr.enssat.BoulderDash.helpers.LevelSelectorHelper;
|
import fr.enssat.BoulderDash.helpers.LevelSelectorHelper;
|
||||||
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
import fr.enssat.BoulderDash.controllers.LevelEditorController;
|
||||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
||||||
import fr.enssat.BoulderDash.models.LevelModel;
|
import fr.enssat.BoulderDash.models.displayableElement.LevelModel;
|
||||||
import fr.enssat.BoulderDash.views.LevelEditorGroundView;
|
|
||||||
import fr.enssat.BoulderDash.views.AssetsLevelEditorComponent;
|
|
||||||
import fr.enssat.BoulderDash.views.MenuLevelSelector;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user