mv levelModel field up to superclass

This commit is contained in:
Daniel Langbein 2024-11-07 15:30:55 +01:00
parent 99db8d4956
commit f896028199
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
8 changed files with 643 additions and 640 deletions

View File

@ -0,0 +1,11 @@
package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.LevelModel;
public abstract class AbstractLevelController {
protected LevelModel levelModel;
public AbstractLevelController(LevelModel levelModel) {
this.levelModel = levelModel;
}
}

View File

@ -7,7 +7,7 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
/** /**
* ElementPositionUpdateHelper * ElementPositionUpdateHelper
* * <p>
* Updates position of all elements displayed on the map, according to their * Updates position of all elements displayed on the map, according to their
* next potential position. Each object has a weight, which is used to compare * next potential position. Each object has a weight, which is used to compare
* their power to destroy in the food chain. Sorry for that Darwinism. * their power to destroy in the food chain. Sorry for that Darwinism.
@ -15,8 +15,7 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class BoulderAndDiamondController implements Runnable { public class BoulderAndDiamondController extends AbstractLevelController implements Runnable {
private LevelModel levelModel;
private AudioLoadHelper audioLoadHelper; private AudioLoadHelper audioLoadHelper;
private Thread elementMovingThread; private Thread elementMovingThread;
@ -26,7 +25,7 @@ public class BoulderAndDiamondController implements Runnable {
* @param levelModel Level model * @param levelModel Level model
*/ */
public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { public BoulderAndDiamondController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) {
this.levelModel = levelModel; super(levelModel);
this.audioLoadHelper = audioLoadHelper; this.audioLoadHelper = audioLoadHelper;
// Start thread // Start thread

View File

@ -2,7 +2,6 @@ package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.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;
@ -12,15 +11,14 @@ import java.awt.event.ActionListener;
/** /**
* GameController * GameController
* * <p>
* This system creates the view. * This system creates the view.
* The game loop is also handled there. * The game loop is also handled there.
* *
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class GameController implements ActionListener { public class GameController extends AbstractLevelController implements ActionListener {
private LevelModel levelModel;
private AudioLoadHelper audioLoadHelper; private AudioLoadHelper audioLoadHelper;
private boolean firstClickOnPause; private boolean firstClickOnPause;
private MenuView menuView; private MenuView menuView;
@ -34,11 +32,12 @@ public class GameController implements ActionListener {
* @param navigationBetweenViewController * @param navigationBetweenViewController
*/ */
public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) { public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) {
super(levelModel);
this.firstClickOnPause = true; this.firstClickOnPause = true;
this.navigationBetweenViewController = navigationBetweenViewController; this.navigationBetweenViewController = navigationBetweenViewController;
this.levelModel = levelModel;
this.audioLoadHelper = audioLoadHelper; this.audioLoadHelper = audioLoadHelper;
this.gameView = new GameView(this, levelModel); this.gameView = new GameView(this, levelModel);
this.menuView = navigationBetweenViewController.getMenuView(); this.menuView = navigationBetweenViewController.getMenuView();
@ -103,6 +102,7 @@ public class GameController implements ActionListener {
/** /**
* Return the game view * Return the game view
*
* @return gameView * @return gameView
*/ */
public GameView getGameView() { public GameView getGameView() {
@ -111,6 +111,7 @@ public class GameController implements ActionListener {
/** /**
* Set the gameView * Set the gameView
*
* @param gameView * @param gameView
*/ */
public void setGameView(GameView gameView) { public void setGameView(GameView gameView) {

View File

@ -2,8 +2,6 @@ package fr.enssat.BoulderDash.controllers;
import fr.enssat.BoulderDash.models.DisplayableElementModel; import fr.enssat.BoulderDash.models.DisplayableElementModel;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.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;
@ -12,22 +10,22 @@ import java.awt.event.KeyListener;
/** /**
* GameKeyController * GameKeyController
* * <p>
* Manages the key events controller. * Manages the key events controller.
* *
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class GameKeyController implements KeyListener { public class GameKeyController extends AbstractLevelController implements KeyListener {
private LevelModel levelModel;
private RockfordUpdateController updatePosRockford; private RockfordUpdateController updatePosRockford;
/** /**
* Class constructor * Class constructor
* *
* @param levelModel Level model * @param levelModel Level model
*/ */
public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) { public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) {
this.levelModel = levelModel; super(levelModel);
new BoulderAndDiamondController(levelModel, audioLoadHelper); new BoulderAndDiamondController(levelModel, audioLoadHelper);
this.updatePosRockford = new RockfordUpdateController(levelModel); this.updatePosRockford = new RockfordUpdateController(levelModel);
} }

View File

@ -9,20 +9,18 @@ import fr.enssat.BoulderDash.helpers.LevelSaveHelper;
import fr.enssat.BoulderDash.models.LevelModel; import fr.enssat.BoulderDash.models.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.*;
/** /**
* LevelEditorController * LevelEditorController
* * <p>
* Manages the level editor controller. * Manages the level editor controller.
* *
* @author Valerian Saliou <valerian@valeriansaliou.name> * @author Valerian Saliou <valerian@valeriansaliou.name>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class LevelEditorController implements ActionListener { public class LevelEditorController extends AbstractLevelController implements ActionListener {
private LevelModel levelModel;
private LevelEditorView levelEditorView; private LevelEditorView levelEditorView;
private NavigationBetweenViewController nav; private NavigationBetweenViewController nav;
@ -32,7 +30,7 @@ public class LevelEditorController implements ActionListener {
* @param levelModel Level model * @param levelModel Level model
*/ */
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) { public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
this.levelModel = levelModel; super(levelModel);
this.levelModel.setShowCursor(true); this.levelModel.setShowCursor(true);
this.nav = nav; this.nav = nav;

View File

@ -9,14 +9,13 @@ import java.awt.event.KeyListener;
/** /**
* LevelEditorKeyController * LevelEditorKeyController
* * <p>
* Manages the key events controller. * Manages the key events controller.
* *
* @author Valerian Saliou <valerian@valeriansaliou.name> * @author Valerian Saliou <valerian@valeriansaliou.name>
* @since 2015-06-21 * @since 2015-06-21
*/ */
public class LevelEditorKeyController implements KeyListener { public class LevelEditorKeyController extends AbstractLevelController implements KeyListener {
private LevelModel levelModel;
private LevelEditorView levelEditorView; private LevelEditorView levelEditorView;
private boolean capLocks; private boolean capLocks;
@ -27,7 +26,7 @@ public class LevelEditorKeyController implements KeyListener {
* @param levelEditorView Level editor view * @param levelEditorView Level editor view
*/ */
public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) { public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) {
this.levelModel = levelModel; super(levelModel);
this.capLocks = false; this.capLocks = false;
this.levelEditorView = levelEditorView; this.levelEditorView = levelEditorView;
} }

View File

@ -13,13 +13,11 @@ import fr.enssat.BoulderDash.controllers.GameController;
* Controller to navigate between the different views * Controller to navigate between the different views
* *
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
*
*/ */
public class NavigationBetweenViewController implements ActionListener { public class NavigationBetweenViewController implements ActionListener {
private LevelEditorController levelEditorController; private LevelEditorController levelEditorController;
private MenuView menuView; private MenuView menuView;
private AudioLoadHelper audioLoadHelper; private AudioLoadHelper audioLoadHelper;
private LevelModel levelModelForGame, levelModelForEditor;
private GameController gameController; private GameController gameController;
private String pickedLevelIdentifier; private String pickedLevelIdentifier;
@ -50,8 +48,8 @@ public class NavigationBetweenViewController implements ActionListener {
case "editor": case "editor":
// New blank model for editor // New blank model for editor
this.levelModelForEditor = new LevelModel(audioLoadHelper); LevelModel levelModelForEditor = new LevelModel(audioLoadHelper);
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this); this.levelEditorController = new LevelEditorController(levelModelForEditor, this);
this.levelEditorController.getLevelEditorView().setVisible(true); this.levelEditorController.getLevelEditorView().setVisible(true);
this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus(); this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus();
@ -66,7 +64,7 @@ public class NavigationBetweenViewController implements ActionListener {
// Reinit the levelModelForGame... // Reinit the levelModelForGame...
pickedLevelIdentifier = this.menuView.getLevelIdentifier(); pickedLevelIdentifier = this.menuView.getLevelIdentifier();
this.levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper); LevelModel levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper);
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this); this.gameController = new GameController(levelModelForGame, audioLoadHelper, this);
if (levelEditorController != null) { if (levelEditorController != null) {

View File

@ -4,7 +4,7 @@ import fr.enssat.BoulderDash.models.LevelModel;
/** /**
* ElementPositionUpdateHelper * ElementPositionUpdateHelper
* * <p>
* Updates position of all elements displayed on the map, according to their * Updates position of all elements displayed on the map, according to their
* next potential position. Each object has a weight, which is used to compare * next potential position. Each object has a weight, which is used to compare
* their power to destroy in the food chain. Sorry for that Darwinism. * their power to destroy in the food chain. Sorry for that Darwinism.
@ -12,8 +12,7 @@ import fr.enssat.BoulderDash.models.LevelModel;
* @author Colin Leverger <me@colinleverger.fr> * @author Colin Leverger <me@colinleverger.fr>
* @since 2015-06-19 * @since 2015-06-19
*/ */
public class RockfordUpdateController implements Runnable { public class RockfordUpdateController extends AbstractLevelController implements Runnable {
private LevelModel levelModel;
private Thread elementMovingThread; private Thread elementMovingThread;
private int rockfordPositionX; private int rockfordPositionX;
private int rockfordPositionY; private int rockfordPositionY;
@ -25,7 +24,7 @@ public class RockfordUpdateController implements Runnable {
* @param levelModel Level model * @param levelModel Level model
*/ */
public RockfordUpdateController(LevelModel levelModel) { public RockfordUpdateController(LevelModel levelModel) {
this.levelModel = levelModel; super(levelModel);
this.elementMovingThread = new Thread(this); this.elementMovingThread = new Thread(this);
this.elementMovingThread.start(); this.elementMovingThread.start();
this.rockfordHasMoved = false; this.rockfordHasMoved = false;