Compare commits
17 Commits
main
...
ueb03_Chih
Author | SHA1 | Date | |
---|---|---|---|
![]() |
96457af2d3 | ||
![]() |
32647ef118 | ||
![]() |
65f226a951 | ||
![]() |
a8dc0b20c7 | ||
f8cb868e55 | |||
d350b1eb1c | |||
59a7ecff2e | |||
2247c7f43d | |||
f40b8b4492 | |||
f896028199 | |||
![]() |
9fa8eeaed9 | ||
![]() |
1b54c07d3c | ||
![]() |
2751521dd5 | ||
99db8d4956 | |||
![]() |
db30b572ff | ||
fd3dfb35ca | |||
![]() |
5f6312555d |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
.DS_Store
|
||||
/classes
|
||||
/bin/
|
||||
/out/
|
||||
/classes/
|
||||
.DS_Store
|
0
boulder-dash/.idea/.name → .idea/.name
generated
0
boulder-dash/.idea/.name → .idea/.name
generated
16
.idea/checkstyle-idea.xml
generated
Normal file
16
.idea/checkstyle-idea.xml
generated
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CheckStyle-IDEA" serialisationVersion="2">
|
||||
<checkstyleVersion>10.18.2</checkstyleVersion>
|
||||
<scanScope>JavaOnly</scanScope>
|
||||
<option name="thirdPartyClasspath" />
|
||||
<option name="activeLocationIds" />
|
||||
<option name="locations">
|
||||
<list>
|
||||
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
|
||||
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
|
||||
<ConfigurationLocation id="5232a701-ef57-4b8f-b1df-ed9fcf2cc548" type="LOCAL_FILE" scope="All" description="Ueb 01 Checkstyle">$PROJECT_DIR$/ueb01_checkstyle_config.xml</ConfigurationLocation>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
7
.idea/misc.xml
generated
7
.idea/misc.xml
generated
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
<component name="PDMPlugin">
|
||||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
</project>
|
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/sq_2024.iml" filepath="$PROJECT_DIR$/.idea/sq_2024.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Boulder Dash.iml" filepath="$PROJECT_DIR$/Boulder Dash.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
.idea/sq_2024.iml
generated
11
.idea/sq_2024.iml
generated
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/classes" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
2
boulder-dash/.gitignore
vendored
2
boulder-dash/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/bin/
|
||||
/out/
|
8
boulder-dash/.idea/.gitignore
generated
vendored
8
boulder-dash/.idea/.gitignore
generated
vendored
@ -1,8 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
boulder-dash/.idea/misc.xml
generated
6
boulder-dash/.idea/misc.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
</project>
|
8
boulder-dash/.idea/modules.xml
generated
8
boulder-dash/.idea/modules.xml
generated
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Boulder Dash.iml" filepath="$PROJECT_DIR$/Boulder Dash.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
boulder-dash/.idea/vcs.xml
generated
6
boulder-dash/.idea/vcs.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,119 +0,0 @@
|
||||
package fr.enssat.BoulderDash.controllers;
|
||||
|
||||
import fr.enssat.BoulderDash.models.LevelModel;
|
||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
||||
import fr.enssat.BoulderDash.views.MenuView;
|
||||
import fr.enssat.BoulderDash.views.GameView;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
||||
/**
|
||||
* GameController
|
||||
*
|
||||
* This system creates the view.
|
||||
* The game loop is also handled there.
|
||||
*
|
||||
* @author Colin Leverger <me@colinleverger.fr>
|
||||
* @since 2015-06-19
|
||||
*/
|
||||
public class GameController implements ActionListener {
|
||||
private LevelModel levelModel;
|
||||
private AudioLoadHelper audioLoadHelper;
|
||||
private boolean firstClickOnPause;
|
||||
private MenuView menuView;
|
||||
private GameView gameView;
|
||||
private NavigationBetweenViewController navigationBetweenViewController;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param levelModel Level model
|
||||
* @param navigationBetweenViewController
|
||||
*/
|
||||
public GameController(LevelModel levelModel, AudioLoadHelper audioLoadHelper, NavigationBetweenViewController navigationBetweenViewController) {
|
||||
this.firstClickOnPause = true;
|
||||
|
||||
this.navigationBetweenViewController = navigationBetweenViewController;
|
||||
|
||||
this.levelModel = levelModel;
|
||||
this.audioLoadHelper = audioLoadHelper;
|
||||
this.gameView = new GameView(this, levelModel);
|
||||
this.menuView = navigationBetweenViewController.getMenuView();
|
||||
|
||||
this.getAudioLoadHelper().stopMusic();
|
||||
this.getAudioLoadHelper().playSound("new");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'action performed' event
|
||||
*
|
||||
* @param event Action event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
switch(event.getActionCommand()) {
|
||||
case "pause":
|
||||
if(this.firstClickOnPause) {
|
||||
this.levelModel.setGamePaused(true);
|
||||
} else if(!this.firstClickOnPause) {
|
||||
this.levelModel.setGamePaused(false);
|
||||
}
|
||||
|
||||
this.firstClickOnPause = !this.firstClickOnPause;
|
||||
this.gameView.getGameFieldView().grabFocus();
|
||||
break;
|
||||
|
||||
case "restart":
|
||||
this.resetGame("restart");
|
||||
this.getAudioLoadHelper().playSound("new");
|
||||
this.gameView.getGameFieldView().grabFocus();
|
||||
break;
|
||||
|
||||
case "menu":
|
||||
this.menuView.setVisible(true);
|
||||
this.getAudioLoadHelper().startMusic("game");
|
||||
this.resetGame("menu");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to reset the game
|
||||
*/
|
||||
private void resetGame(String source) {
|
||||
this.gameView.dispose();
|
||||
|
||||
if(source.equals("restart")){
|
||||
this.levelModel = new LevelModel(this.navigationBetweenViewController.getPickedLevelIdentifier(), audioLoadHelper);
|
||||
this.gameView = new GameView(this, levelModel);
|
||||
this.gameView.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the audio load helper instance
|
||||
*
|
||||
* @return Audio load helper instance
|
||||
*/
|
||||
public AudioLoadHelper getAudioLoadHelper() {
|
||||
return this.audioLoadHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the game view
|
||||
* @return gameView
|
||||
*/
|
||||
public GameView getGameView() {
|
||||
return gameView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the gameView
|
||||
* @param gameView
|
||||
*/
|
||||
public void setGameView(GameView gameView) {
|
||||
this.gameView = gameView;
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package fr.enssat.BoulderDash.controllers;
|
||||
|
||||
import fr.enssat.BoulderDash.models.DisplayableElementModel;
|
||||
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 java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
|
||||
/**
|
||||
* GameKeyController
|
||||
*
|
||||
* Manages the key events controller.
|
||||
*
|
||||
* @author Colin Leverger <me@colinleverger.fr>
|
||||
* @since 2015-06-19
|
||||
*/
|
||||
public class GameKeyController implements KeyListener {
|
||||
private LevelModel levelModel;
|
||||
private RockfordUpdateController updatePosRockford;
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param levelModel Level model
|
||||
*/
|
||||
public GameKeyController(LevelModel levelModel, AudioLoadHelper audioLoadHelper) {
|
||||
this.levelModel = levelModel;
|
||||
new BoulderAndDiamondController(levelModel, audioLoadHelper);
|
||||
this.updatePosRockford = new RockfordUpdateController(levelModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'key pressed' event
|
||||
*
|
||||
* @param e Key event
|
||||
*/
|
||||
public void keyPressed(KeyEvent e) {
|
||||
int keyCode = e.getKeyCode();
|
||||
|
||||
switch (keyCode) {
|
||||
// Direction: UP
|
||||
case KeyEvent.VK_UP:
|
||||
DisplayableElementModel upElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() - 1];
|
||||
|
||||
if (upElement.getPriority() < levelModel.getRockford().getPriority()) {
|
||||
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() - 1);
|
||||
this.levelModel.getRockford().startRunningUp();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Direction: DOWN
|
||||
case KeyEvent.VK_DOWN:
|
||||
DisplayableElementModel downElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX()][levelModel.getRockfordPositionY() + 1];
|
||||
|
||||
if (downElement.getPriority() < levelModel.getRockford().getPriority()) {
|
||||
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX(), levelModel.getRockfordPositionY() + 1);
|
||||
this.levelModel.getRockford().startRunningDown();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Direction: LEFT
|
||||
case KeyEvent.VK_LEFT:
|
||||
DisplayableElementModel leftElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() - 1][levelModel.getRockfordPositionY()];
|
||||
|
||||
if (leftElement.getPriority() < levelModel.getRockford().getPriority()) {
|
||||
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() - 1, levelModel.getRockfordPositionY());
|
||||
this.levelModel.getRockford().startRunningLeft();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Direction: RIGHT
|
||||
case KeyEvent.VK_RIGHT:
|
||||
DisplayableElementModel rightElement = levelModel.getGroundLevelModel()[levelModel.getRockfordPositionX() + 1][levelModel.getRockfordPositionY()];
|
||||
|
||||
if (rightElement.getPriority() < levelModel.getRockford().getPriority()) {
|
||||
this.updatePosRockford.moveRockford(levelModel.getRockfordPositionX() + 1, levelModel.getRockfordPositionY());
|
||||
this.levelModel.getRockford().startRunningRight();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'key released' event
|
||||
*
|
||||
* @param e Key event
|
||||
*/
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
this.levelModel.getRockford().startStaying();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'key typed' event
|
||||
*
|
||||
* @param e Key event
|
||||
*/
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
package fr.enssat.BoulderDash.controllers;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import fr.enssat.BoulderDash.exceptions.LevelConstraintNotRespectedException;
|
||||
import fr.enssat.BoulderDash.helpers.LevelRemoveHelper;
|
||||
import fr.enssat.BoulderDash.helpers.LevelSaveHelper;
|
||||
import fr.enssat.BoulderDash.models.LevelModel;
|
||||
import fr.enssat.BoulderDash.views.HelpView;
|
||||
import fr.enssat.BoulderDash.views.LevelEditorView;
|
||||
import fr.enssat.BoulderDash.controllers.NavigationBetweenViewController;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* LevelEditorController
|
||||
*
|
||||
* Manages the level editor controller.
|
||||
*
|
||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||
* @since 2015-06-19
|
||||
*/
|
||||
public class LevelEditorController implements ActionListener {
|
||||
private LevelModel levelModel;
|
||||
private LevelEditorView levelEditorView;
|
||||
private NavigationBetweenViewController nav;
|
||||
|
||||
/**
|
||||
* Class constructor'
|
||||
*
|
||||
* @param levelModel Level model
|
||||
*/
|
||||
public LevelEditorController(LevelModel levelModel, NavigationBetweenViewController nav) {
|
||||
this.levelModel = levelModel;
|
||||
this.levelModel.setShowCursor(true);
|
||||
|
||||
this.nav = nav;
|
||||
this.nav.getAudioLoadHelper().stopMusic();
|
||||
|
||||
this.levelEditorView = new LevelEditorView(this, levelModel, nav);
|
||||
|
||||
// Pre-bind event watcher (hack to fix a Java issue)
|
||||
this.levelModel.decrementCursorXPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'action performed' event
|
||||
*
|
||||
* @param event Action event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
switch(event.getActionCommand()) {
|
||||
case "menu":
|
||||
this.levelEditorView.setVisible(false);
|
||||
this.nav.setMenuView();
|
||||
this.nav.getAudioLoadHelper().startMusic("game");
|
||||
|
||||
break;
|
||||
|
||||
case "save":
|
||||
// Check constraints
|
||||
try {
|
||||
this.levelModel.checkConstraints();
|
||||
|
||||
// Save action (direct save)
|
||||
String levelId = this.levelEditorView.getSelectedLevel();
|
||||
LevelSaveHelper levelSave;
|
||||
|
||||
if(levelId == null || levelId.isEmpty()) {
|
||||
// Create a new level
|
||||
levelSave = new LevelSaveHelper(levelModel.getGroundLevelModel());
|
||||
} else {
|
||||
// Overwrite existing level
|
||||
levelSave = new LevelSaveHelper(levelId, levelModel.getGroundLevelModel());
|
||||
}
|
||||
|
||||
JFrame frameDialog = new JFrame("Info");
|
||||
JOptionPane.showMessageDialog(frameDialog, "Level saved");
|
||||
|
||||
this.levelEditorView.openedLevelChange(levelSave.getLevelId());
|
||||
} catch(LevelConstraintNotRespectedException e) {
|
||||
JFrame frameDialog = new JFrame("Error");
|
||||
JOptionPane.showMessageDialog(frameDialog, e.getMessage());
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
String levelId = this.levelEditorView.getSelectedLevel();
|
||||
JFrame frameDialog = new JFrame("Info");
|
||||
|
||||
if(levelId == null || levelId.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(frameDialog, "Level not yet saved, no need to delete it!");
|
||||
} else {
|
||||
new LevelRemoveHelper(levelId);
|
||||
JOptionPane.showMessageDialog(frameDialog, "Level deleted!");
|
||||
|
||||
this.levelEditorView.openedLevelChange(null);
|
||||
}
|
||||
break;
|
||||
|
||||
case "help":
|
||||
new HelpView();
|
||||
break;
|
||||
|
||||
case "new":
|
||||
this.levelEditorView.openedLevelChange(null);
|
||||
break;
|
||||
}
|
||||
|
||||
this.getLevelEditorView().getLevelEditorGroundView().grabFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level editor view
|
||||
*
|
||||
* @return Level editor view
|
||||
*/
|
||||
public LevelEditorView getLevelEditorView() {
|
||||
return levelEditorView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets level model
|
||||
*
|
||||
* @return Level model
|
||||
*/
|
||||
public LevelModel getLevelModel() {
|
||||
return this.levelModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the level editor view
|
||||
*
|
||||
* @param levelEditorView Level editor view
|
||||
*/
|
||||
public void setLevelEditorView(LevelEditorView levelEditorView) {
|
||||
this.levelEditorView = levelEditorView;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package fr.enssat.BoulderDash.controllers;
|
||||
|
||||
import fr.enssat.BoulderDash.models.LevelModel;
|
||||
import fr.enssat.BoulderDash.views.LevelEditorView;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
|
||||
/**
|
||||
* LevelEditorKeyController
|
||||
*
|
||||
* Manages the key events controller.
|
||||
*
|
||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||
* @since 2015-06-21
|
||||
*/
|
||||
public class LevelEditorKeyController implements KeyListener {
|
||||
private LevelModel levelModel;
|
||||
private LevelEditorView levelEditorView;
|
||||
private boolean capLocks;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param levelModel Level model
|
||||
* @param levelEditorView Level editor view
|
||||
*/
|
||||
public LevelEditorKeyController(LevelModel levelModel, LevelEditorView levelEditorView) {
|
||||
this.levelModel = levelModel;
|
||||
this.capLocks = false;
|
||||
this.levelEditorView = levelEditorView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'key pressed' event
|
||||
*
|
||||
* @param e Key event
|
||||
*/
|
||||
public void keyPressed(KeyEvent e) {
|
||||
int keyCode = e.getKeyCode();
|
||||
|
||||
switch (keyCode) {
|
||||
// Direction: UP
|
||||
case KeyEvent.VK_UP:
|
||||
this.levelModel.decrementCursorYPosition();
|
||||
break;
|
||||
|
||||
// Direction: DOWN
|
||||
case KeyEvent.VK_DOWN:
|
||||
this.levelModel.incrementCursorYPosition();
|
||||
break;
|
||||
|
||||
// Direction: LEFT
|
||||
case KeyEvent.VK_LEFT:
|
||||
this.levelModel.decrementCursorXPosition();
|
||||
break;
|
||||
|
||||
// Direction: RIGHT
|
||||
case KeyEvent.VK_RIGHT:
|
||||
this.levelModel.incrementCursorXPosition();
|
||||
break;
|
||||
|
||||
// Key: SPACE
|
||||
case KeyEvent.VK_SPACE:
|
||||
this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
|
||||
break;
|
||||
|
||||
case 16:
|
||||
this.capLocks = !capLocks;
|
||||
break;
|
||||
}
|
||||
|
||||
// Hold block change (quick edit)
|
||||
if(capLocks) {
|
||||
this.levelModel.triggerBlockChange(this.levelEditorView.getPickedBlockValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'key released' event
|
||||
*
|
||||
* @param e Key event
|
||||
*/
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'key typed' event
|
||||
*
|
||||
* @param e Key event
|
||||
*/
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
package fr.enssat.BoulderDash.controllers;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
||||
import fr.enssat.BoulderDash.models.LevelModel;
|
||||
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
|
||||
*
|
||||
* @author Colin Leverger <me@colinleverger.fr>
|
||||
*
|
||||
*/
|
||||
public class NavigationBetweenViewController implements ActionListener {
|
||||
private LevelEditorController levelEditorController;
|
||||
private MenuView menuView;
|
||||
private AudioLoadHelper audioLoadHelper;
|
||||
private LevelModel levelModelForGame, levelModelForEditor;
|
||||
private GameController gameController;
|
||||
private String pickedLevelIdentifier;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public NavigationBetweenViewController() {
|
||||
this.audioLoadHelper = new AudioLoadHelper();
|
||||
|
||||
// Play game music
|
||||
this.getAudioLoadHelper().startMusic("game");
|
||||
|
||||
// Creation of the first view
|
||||
this.menuView = new MenuView(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action performed event handler
|
||||
*
|
||||
* @param event Action event
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
switch (event.getActionCommand()) {
|
||||
case "quit":
|
||||
System.exit(0);
|
||||
break;
|
||||
|
||||
case "editor":
|
||||
// New blank model for editor
|
||||
this.levelModelForEditor = new LevelModel(audioLoadHelper);
|
||||
this.levelEditorController = new LevelEditorController(this.levelModelForEditor, this);
|
||||
|
||||
this.levelEditorController.getLevelEditorView().setVisible(true);
|
||||
this.levelEditorController.getLevelEditorView().getLevelEditorGroundView().grabFocus();
|
||||
|
||||
if (gameController != null) {
|
||||
this.gameController.getGameView().setVisible(false);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "game":
|
||||
// Reinit the levelModelForGame...
|
||||
pickedLevelIdentifier = this.menuView.getLevelIdentifier();
|
||||
|
||||
this.levelModelForGame = new LevelModel(pickedLevelIdentifier, audioLoadHelper);
|
||||
this.gameController = new GameController(levelModelForGame, audioLoadHelper, this);
|
||||
|
||||
if (levelEditorController != null) {
|
||||
this.levelEditorController.getLevelEditorView().setVisible(false);
|
||||
}
|
||||
|
||||
this.gameController.getGameView().setVisible(true);
|
||||
this.gameController.getGameView().getGameFieldView().grabFocus();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
this.menuView.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the audio load helper
|
||||
*
|
||||
* @return Audio load helper
|
||||
*/
|
||||
public AudioLoadHelper getAudioLoadHelper() {
|
||||
return this.audioLoadHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first view
|
||||
*
|
||||
* @return First view
|
||||
*/
|
||||
public MenuView getMenuView() {
|
||||
return this.menuView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the first view
|
||||
*
|
||||
* @param menuView
|
||||
*/
|
||||
public MenuView setMenuView() {
|
||||
this.menuView = new MenuView(this);
|
||||
return menuView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pickedLevel
|
||||
*
|
||||
* @return pickedLevelIdentifier Picked level identifier
|
||||
*/
|
||||
public String getPickedLevelIdentifier() {
|
||||
return pickedLevelIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pickedLevelIdentifier
|
||||
*
|
||||
* @param pickedLevelIdentifier Picked level identifier
|
||||
*/
|
||||
public void setPickedLevelIdentifier(String pickedLevelIdentifier) {
|
||||
this.pickedLevelIdentifier = pickedLevelIdentifier;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package fr.enssat.BoulderDash.controllers;
|
||||
|
||||
import fr.enssat.BoulderDash.models.LevelModel;
|
||||
|
||||
/**
|
||||
* ElementPositionUpdateHelper
|
||||
*
|
||||
* 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
|
||||
* their power to destroy in the food chain. Sorry for that Darwinism.
|
||||
*
|
||||
* @author Colin Leverger <me@colinleverger.fr>
|
||||
* @since 2015-06-19
|
||||
*/
|
||||
public class RockfordUpdateController implements Runnable {
|
||||
private LevelModel levelModel;
|
||||
private Thread elementMovingThread;
|
||||
private int rockfordPositionX;
|
||||
private int rockfordPositionY;
|
||||
private boolean rockfordHasMoved;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param levelModel Level model
|
||||
*/
|
||||
public RockfordUpdateController(LevelModel levelModel) {
|
||||
this.levelModel = levelModel;
|
||||
this.elementMovingThread = new Thread(this);
|
||||
this.elementMovingThread.start();
|
||||
this.rockfordHasMoved = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Watches for elements to be moved
|
||||
*/
|
||||
public void run() {
|
||||
while (this.levelModel.isGameRunning()) {
|
||||
if(!this.levelModel.getGamePaused()){
|
||||
if (this.rockfordHasMoved) {
|
||||
this.levelModel.setPositionOfRockford(rockfordPositionX, rockfordPositionY);
|
||||
this.rockfordHasMoved = false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves Rockford
|
||||
*
|
||||
* @param rockfordPositionX Next horizontal position on the grid
|
||||
* @param rockfordPositionY Next vertical position on the grid
|
||||
*/
|
||||
public void moveRockford(int rockfordPositionX, int rockfordPositionY) {
|
||||
this.rockfordPositionX = rockfordPositionX;
|
||||
this.rockfordPositionY = rockfordPositionY;
|
||||
this.rockfordHasMoved = true;
|
||||
}
|
||||
}
|
4
dicegame/.gitignore
vendored
4
dicegame/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
.gradle/
|
||||
.idea/
|
||||
src/build/
|
||||
target/
|
@ -1,4 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path: .
|
||||
Main-Class: WuerfelspielGUI
|
||||
|
@ -1,5 +0,0 @@
|
||||
package dicegame.logic;
|
||||
|
||||
public interface DiceInteraction {
|
||||
public int changeDiceState(int diceIndex) throws SelectionException;
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
package dicegame.logic;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Logic implements DiceInteraction {
|
||||
public static final int DICE_NUMBER = 6;
|
||||
public static final int DEFAULT_PLAYER_NUMBER = 2;
|
||||
public static final int DEFAULT_ROUNDS = 10;
|
||||
private static final int DIE_UNFIXED = 0;
|
||||
private static final int DIE_TEMP_FIXED = 1;
|
||||
private static final int DIE_FIXED = 2;
|
||||
private boolean gameIsRunning;
|
||||
private boolean playerCanThrowDice;
|
||||
private int currentPlayer;
|
||||
private int roundNumber;
|
||||
private int roundPoints;
|
||||
private int maxRounds = DEFAULT_ROUNDS;
|
||||
private int[] points = new int[2];
|
||||
private String[] names = new String[2];
|
||||
private int[] dicePips = new int[6];
|
||||
private int[] diceFixed = new int[6];
|
||||
private Random random;
|
||||
|
||||
public Logic(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
this.resetGame();
|
||||
this.gameIsRunning = true;
|
||||
this.playerCanThrowDice = true;
|
||||
this.roundNumber = 1;
|
||||
this.currentPlayer = 0;
|
||||
}
|
||||
|
||||
public String rollDice() {
|
||||
if (!this.gameIsRunning) {
|
||||
return "Das Spiel läuft aktuell nicht!";
|
||||
} else {
|
||||
if (this.isAllDiceFixed()) {
|
||||
this.resetDice();
|
||||
}
|
||||
|
||||
for(int i = 0; i < DICE_NUMBER; ++i) {
|
||||
if (this.diceFixed[i] == DIE_TEMP_FIXED) {
|
||||
this.diceFixed[i] = DIE_FIXED;
|
||||
} else if (this.diceFixed[i] == DIE_UNFIXED) {
|
||||
this.dicePips[i] = this.random.nextInt(6) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isScoringPipsAvailable()) {
|
||||
this.playerCanThrowDice = true;
|
||||
} else {
|
||||
this.playerCanThrowDice = false;
|
||||
this.roundPoints = 0;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isScoringPipsAvailable() {
|
||||
for(int i = 0; i < DICE_NUMBER; ++i) {
|
||||
if (this.diceFixed[i] != DIE_FIXED && (this.dicePips[i] == 5 || this.dicePips[i] == 1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isAllDiceFixed() {
|
||||
for(int i = 0; i < DICE_NUMBER; ++i) {
|
||||
if (this.diceFixed[i] == DIE_UNFIXED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String checkIfGameCanStart() {
|
||||
if (this.gameIsRunning) {
|
||||
return "Das Spiel läuft bereits!";
|
||||
} else {
|
||||
for(int i = 0; i < DEFAULT_PLAYER_NUMBER; ++i) {
|
||||
if (this.names[i] == null || this.names[i].trim().length() < 2) {
|
||||
return "Spieler " + (i + 1) + " hat noch keinen Namen!";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void resetGame() {
|
||||
this.roundNumber = 0;
|
||||
this.roundPoints = 0;
|
||||
this.resetDice();
|
||||
this.resetPoints();
|
||||
}
|
||||
|
||||
public void finishRound() {
|
||||
this.resetDice();
|
||||
int[] var10000 = this.points;
|
||||
int var10001 = this.currentPlayer;
|
||||
var10000[var10001] += this.roundPoints;
|
||||
this.roundPoints = 0;
|
||||
this.currentPlayer = ++this.currentPlayer % DEFAULT_PLAYER_NUMBER;
|
||||
if (this.currentPlayer == 0) {
|
||||
if (this.roundNumber == this.maxRounds) {
|
||||
this.gameIsRunning = false;
|
||||
} else {
|
||||
++this.roundNumber;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void resetDice() {
|
||||
for(int i = 0; i < DICE_NUMBER; ++i) {
|
||||
this.diceFixed[i] = DIE_UNFIXED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void resetPoints() {
|
||||
for(int i = 0; i < DEFAULT_PLAYER_NUMBER; ++i) {
|
||||
this.points[i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getRoundNumber() {
|
||||
return this.roundNumber;
|
||||
}
|
||||
|
||||
public int getRoundPoints() {
|
||||
return this.roundPoints;
|
||||
}
|
||||
|
||||
public boolean isDieFixed(int dieIndex) {
|
||||
return this.diceFixed[dieIndex] != DIE_UNFIXED;
|
||||
}
|
||||
|
||||
public boolean isAtLeastOneDieFixedInCurrentThrow() {
|
||||
for(int i = 0; i < DICE_NUMBER; ++i) {
|
||||
if (this.diceFixed[i] == DIE_TEMP_FIXED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int countTempFixedByPips(int pips) {
|
||||
int count = 0;
|
||||
|
||||
for(int i = 0; i < DICE_NUMBER; ++i) {
|
||||
if (this.diceFixed[i] == DIE_TEMP_FIXED && this.dicePips[i] == pips) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getDiePips(int dieIndex) {
|
||||
return this.dicePips[dieIndex];
|
||||
}
|
||||
|
||||
public int getMaxRounds() {
|
||||
return this.maxRounds;
|
||||
}
|
||||
|
||||
public String setMaxRounds(int maxRounds) {
|
||||
if (this.gameIsRunning) {
|
||||
return "Rundenzahl kann nicht während eines Spiels verändert werden!";
|
||||
} else {
|
||||
this.maxRounds = maxRounds;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPoints(int playerIndex) {
|
||||
return this.points[playerIndex];
|
||||
}
|
||||
|
||||
public String getName(int playerIndex) {
|
||||
return this.names[playerIndex];
|
||||
}
|
||||
|
||||
public String setName(int playerIndex, String name) {
|
||||
if (this.gameIsRunning) {
|
||||
return "Ein Spielername kann nicht während eines Spiels verändert werden!";
|
||||
} else {
|
||||
this.names[playerIndex] = name;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlayerCanThrowDice() {
|
||||
return this.playerCanThrowDice;
|
||||
}
|
||||
|
||||
public boolean isGameIsRunning() {
|
||||
return this.gameIsRunning;
|
||||
}
|
||||
|
||||
public int getCurrentPlayer() {
|
||||
return this.currentPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int changeDiceState(int diceIndex) throws SelectionException {
|
||||
if (this.diceFixed[diceIndex] == DIE_UNFIXED) {
|
||||
setDieFixed(diceIndex);
|
||||
} else {
|
||||
setDieUnfixed(diceIndex);
|
||||
}
|
||||
return roundPoints;
|
||||
}
|
||||
|
||||
private void setDieFixed(int dieIndex) throws SelectionException {
|
||||
int c;
|
||||
if (this.dicePips[dieIndex] == 1) {
|
||||
c = this.countTempFixedByPips(1);
|
||||
if (c != 2 && c != 5) {
|
||||
this.roundPoints += 100;
|
||||
} else {
|
||||
this.roundPoints -= 200;
|
||||
this.roundPoints += 1000;
|
||||
}
|
||||
|
||||
this.diceFixed[dieIndex] = DIE_TEMP_FIXED;
|
||||
} else if (this.dicePips[dieIndex] == 5) {
|
||||
c = this.countTempFixedByPips(5);
|
||||
if (c != 2 && c != 5) {
|
||||
this.roundPoints += 50;
|
||||
} else {
|
||||
this.roundPoints -= 100;
|
||||
this.roundPoints += 500;
|
||||
}
|
||||
|
||||
this.diceFixed[dieIndex] = DIE_TEMP_FIXED;
|
||||
} else {
|
||||
throw new SelectionException("Es können nur 1'en und 5'en fixiert werden!");
|
||||
}
|
||||
}
|
||||
|
||||
private void setDieUnfixed(int dieIndex) throws SelectionException {
|
||||
int c;
|
||||
if (this.dicePips[dieIndex] == 1) {
|
||||
c = this.countTempFixedByPips(1);
|
||||
if (c != 3 && c != 6) {
|
||||
this.roundPoints -= 100;
|
||||
} else {
|
||||
this.roundPoints -= 1000;
|
||||
this.roundPoints += 200;
|
||||
}
|
||||
|
||||
this.diceFixed[dieIndex] = DIE_UNFIXED;
|
||||
} else if (this.dicePips[dieIndex] == 5) {
|
||||
c = this.countTempFixedByPips(5);
|
||||
if (c != 3 && c != 6) {
|
||||
this.roundPoints -= 50;
|
||||
} else {
|
||||
this.roundPoints -= 500;
|
||||
this.roundPoints += 100;
|
||||
}
|
||||
|
||||
this.diceFixed[dieIndex] = DIE_UNFIXED;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package dicegame.logic;
|
||||
|
||||
public class SelectionException extends Exception {
|
||||
SelectionException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -1,608 +0,0 @@
|
||||
package dicegame.view;
|
||||
|
||||
import dicegame.logic.SelectionException;
|
||||
import dicegame.logic.Logic;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Random;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public final class GUI extends JFrame implements ActionListener {
|
||||
private final Logic logic;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel jContentPane = null;
|
||||
private JPanel panelHead = null;
|
||||
private JPanel panelMain = null;
|
||||
private JTextField textfieldS1Name = null;
|
||||
private JLabel labelS1Name = null;
|
||||
private JLabel labelS2Name = null;
|
||||
private JTextField textfieldS2Name = null;
|
||||
private JPanel panelSpieler1 = null;
|
||||
private JPanel panelSpieler2 = null;
|
||||
private JLabel labelS1Points = null;
|
||||
private JLabel labelS1PointsValue = null;
|
||||
private JLabel labelS2Points = null;
|
||||
private JLabel labelS2PointsValue = null;
|
||||
private JPanel panelGoButton = null;
|
||||
private JButton buttonGo = null;
|
||||
private JPanel panelRound = null;
|
||||
private JLabel labelRound = null;
|
||||
private JLabel labelRoundValue = null;
|
||||
private JPanel panelDice = null;
|
||||
private JToggleButton toggleDie1 = null;
|
||||
private JToggleButton toggleDie2 = null;
|
||||
private JToggleButton toggleDie3 = null;
|
||||
private JToggleButton toggleDie4 = null;
|
||||
private JToggleButton toggleDie5 = null;
|
||||
private JToggleButton toggleDie6 = null;
|
||||
private JPanel panelActions = null;
|
||||
private JPanel panelRoundPoints = null;
|
||||
private JLabel labelRoundPoints = null;
|
||||
private JLabel labelRoundPointsValue = null;
|
||||
private JPanel panelActionsButtons = null;
|
||||
private JButton buttonRoll = null;
|
||||
private JButton buttonReady = null;
|
||||
private JPanel panelDiceActions = null;
|
||||
private JPanel panelStatus = null;
|
||||
private JLabel labelStatus = null;
|
||||
|
||||
private JPanel getPanelHead() {
|
||||
if (this.panelHead == null) {
|
||||
BorderLayout borderLayout3 = new BorderLayout();
|
||||
borderLayout3.setHgap(3);
|
||||
borderLayout3.setVgap(3);
|
||||
this.labelS2Name = new JLabel();
|
||||
this.labelS2Name.setText("Spieler 2 :");
|
||||
this.labelS2Name.setFont(new Font("Dialog", 0, 12));
|
||||
this.labelS2Name.setToolTipText("");
|
||||
this.labelS1Name = new JLabel();
|
||||
this.labelS1Name.setText("Spieler 1 :");
|
||||
this.labelS1Name.setFont(new Font("Dialog", 0, 12));
|
||||
this.panelHead = new JPanel();
|
||||
this.panelHead.setLayout(borderLayout3);
|
||||
this.panelHead.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
||||
this.panelHead.add(this.getPanelSpieler1(), "West");
|
||||
this.panelHead.add(this.getPanelSpieler2(), "East");
|
||||
this.panelHead.add(this.getPanelGoButton(), "South");
|
||||
}
|
||||
|
||||
return this.panelHead;
|
||||
}
|
||||
|
||||
private JPanel getPanelMain() {
|
||||
if (this.panelMain == null) {
|
||||
BorderLayout borderLayout1 = new BorderLayout();
|
||||
borderLayout1.setVgap(5);
|
||||
GridLayout gridLayout3 = new GridLayout();
|
||||
gridLayout3.setRows(3);
|
||||
gridLayout3.setColumns(1);
|
||||
this.panelMain = new JPanel();
|
||||
this.panelMain.setEnabled(true);
|
||||
this.panelMain.setBorder(BorderFactory.createEtchedBorder(0));
|
||||
this.panelMain.setLayout(borderLayout1);
|
||||
this.panelMain.add(this.getPanelRound(), "North");
|
||||
this.panelMain.add(this.getPanelDiceActions(), "Center");
|
||||
}
|
||||
|
||||
return this.panelMain;
|
||||
}
|
||||
|
||||
private JTextField getTextfieldS1Name() {
|
||||
if (this.textfieldS1Name == null) {
|
||||
this.textfieldS1Name = new JTextField();
|
||||
this.textfieldS1Name.setColumns(10);
|
||||
this.textfieldS1Name.setName("");
|
||||
this.textfieldS1Name.setToolTipText("Name des ersten Spielers, bestehend aus mindestens 2 Zeichen");
|
||||
this.textfieldS1Name.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
GUI.this.textfieldS2Name.grabFocus();
|
||||
}
|
||||
});
|
||||
this.textfieldS1Name.addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
GUI.this.logic.setName(0, GUI.this.textfieldS1Name.getText());
|
||||
String s = GUI.this.logic.checkIfGameCanStart();
|
||||
if (s != null) {
|
||||
GUI.this.labelStatus.setText(s);
|
||||
GUI.this.buttonGo.setEnabled(false);
|
||||
} else {
|
||||
GUI.this.buttonGo.setEnabled(true);
|
||||
GUI.this.labelStatus.setText(" ");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this.textfieldS1Name;
|
||||
}
|
||||
|
||||
private JTextField getTextfieldS2Name() {
|
||||
if (this.textfieldS2Name == null) {
|
||||
this.textfieldS2Name = new JTextField();
|
||||
this.textfieldS2Name.setColumns(10);
|
||||
this.textfieldS2Name.setName("");
|
||||
this.textfieldS2Name.setToolTipText("Name des zweiten Spielers, bestehend aus mindestens 2 Zeichen");
|
||||
this.textfieldS2Name.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
GUI.this.buttonGo.grabFocus();
|
||||
}
|
||||
});
|
||||
this.textfieldS2Name.addKeyListener(new KeyAdapter() {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
GUI.this.logic.setName(1, GUI.this.textfieldS2Name.getText());
|
||||
String s = GUI.this.logic.checkIfGameCanStart();
|
||||
if (s != null) {
|
||||
GUI.this.labelStatus.setText(s);
|
||||
GUI.this.buttonGo.setEnabled(false);
|
||||
} else {
|
||||
GUI.this.buttonGo.setEnabled(true);
|
||||
GUI.this.labelStatus.setText(" ");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this.textfieldS2Name;
|
||||
}
|
||||
|
||||
private JPanel getPanelSpieler1() {
|
||||
if (this.panelSpieler1 == null) {
|
||||
GridLayout gridLayout21 = new GridLayout();
|
||||
gridLayout21.setRows(2);
|
||||
this.labelS1PointsValue = new JLabel();
|
||||
this.labelS1PointsValue.setText("0");
|
||||
this.labelS1PointsValue.setFont(new Font("Dialog", 1, 14));
|
||||
GridLayout gridLayout1 = new GridLayout();
|
||||
gridLayout1.setRows(2);
|
||||
gridLayout1.setColumns(2);
|
||||
this.labelS1Points = new JLabel();
|
||||
this.labelS1Points.setText("Punkte :");
|
||||
this.labelS1Points.setFont(new Font("Dialog", 0, 12));
|
||||
GridLayout gridLayout = new GridLayout();
|
||||
gridLayout.setRows(2);
|
||||
gridLayout.setColumns(2);
|
||||
this.panelSpieler1 = new JPanel();
|
||||
this.panelSpieler1.setLayout(gridLayout21);
|
||||
this.panelSpieler1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
||||
this.panelSpieler1.add(this.labelS1Name, (Object)null);
|
||||
this.panelSpieler1.add(this.getTextfieldS1Name(), (Object)null);
|
||||
this.panelSpieler1.add(this.labelS1Points, (Object)null);
|
||||
this.panelSpieler1.add(this.labelS1PointsValue, (Object)null);
|
||||
}
|
||||
|
||||
return this.panelSpieler1;
|
||||
}
|
||||
|
||||
private JPanel getPanelSpieler2() {
|
||||
if (this.panelSpieler2 == null) {
|
||||
this.labelS2PointsValue = new JLabel();
|
||||
this.labelS2PointsValue.setText("0");
|
||||
this.labelS2PointsValue.setFont(new Font("Dialog", 1, 14));
|
||||
this.labelS2Points = new JLabel();
|
||||
this.labelS2Points.setText("Punkte :");
|
||||
this.labelS2Points.setFont(new Font("Dialog", 0, 12));
|
||||
GridLayout gridLayout2 = new GridLayout();
|
||||
gridLayout2.setRows(2);
|
||||
gridLayout2.setColumns(2);
|
||||
this.panelSpieler2 = new JPanel();
|
||||
this.panelSpieler2.setLayout(gridLayout2);
|
||||
this.panelSpieler2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
||||
this.panelSpieler2.add(this.labelS2Name, (Object)null);
|
||||
this.panelSpieler2.add(this.getTextfieldS2Name(), (Object)null);
|
||||
this.panelSpieler2.add(this.labelS2Points, (Object)null);
|
||||
this.panelSpieler2.add(this.labelS2PointsValue, (Object)null);
|
||||
}
|
||||
|
||||
return this.panelSpieler2;
|
||||
}
|
||||
|
||||
private JPanel getPanelGoButton() {
|
||||
if (this.panelGoButton == null) {
|
||||
this.panelGoButton = new JPanel();
|
||||
this.panelGoButton.setLayout(new GridBagLayout());
|
||||
this.panelGoButton.setEnabled(true);
|
||||
this.panelGoButton.add(this.getButtonGo(), new GridBagConstraints());
|
||||
}
|
||||
|
||||
return this.panelGoButton;
|
||||
}
|
||||
|
||||
private JButton getButtonGo() {
|
||||
if (this.buttonGo == null) {
|
||||
this.buttonGo = new JButton();
|
||||
this.buttonGo.setName("");
|
||||
this.buttonGo.setEnabled(false);
|
||||
this.buttonGo.setText(" Spiel starten ");
|
||||
this.buttonGo.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.buttonGo;
|
||||
}
|
||||
|
||||
private JPanel getPanelRound() {
|
||||
if (this.panelRound == null) {
|
||||
this.labelRoundValue = new JLabel();
|
||||
this.labelRoundValue.setText("0");
|
||||
this.labelRoundValue.setFont(new Font("Dialog", 0, 12));
|
||||
this.labelRound = new JLabel();
|
||||
this.labelRound.setText("Runde ");
|
||||
this.labelRound.setFont(new Font("Dialog", 0, 12));
|
||||
this.panelRound = new JPanel();
|
||||
this.panelRound.setLayout(new FlowLayout());
|
||||
this.panelRound.add(this.labelRound, (Object)null);
|
||||
this.panelRound.add(this.labelRoundValue, (Object)null);
|
||||
}
|
||||
|
||||
return this.panelRound;
|
||||
}
|
||||
|
||||
private JPanel getPanelDice() {
|
||||
if (this.panelDice == null) {
|
||||
GridLayout gridLayout5 = new GridLayout();
|
||||
gridLayout5.setRows(1);
|
||||
gridLayout5.setHgap(20);
|
||||
gridLayout5.setVgap(1);
|
||||
gridLayout5.setColumns(6);
|
||||
this.panelDice = new JPanel();
|
||||
this.panelDice.setPreferredSize(new Dimension(346, 26));
|
||||
this.panelDice.setBorder(BorderFactory.createEmptyBorder(5, 3, 5, 0));
|
||||
this.panelDice.setLayout(gridLayout5);
|
||||
this.panelDice.add(this.getToggleDie1(), (Object)null);
|
||||
this.panelDice.add(this.getToggleDie2(), (Object)null);
|
||||
this.panelDice.add(this.getToggleDie3(), (Object)null);
|
||||
this.panelDice.add(this.getToggleDie4(), (Object)null);
|
||||
this.panelDice.add(this.getToggleDie5(), (Object)null);
|
||||
this.panelDice.add(this.getToggleDie6(), (Object)null);
|
||||
}
|
||||
|
||||
return this.panelDice;
|
||||
}
|
||||
|
||||
private JToggleButton getToggleDie1() {
|
||||
if (this.toggleDie1 == null) {
|
||||
this.toggleDie1 = new JToggleButton();
|
||||
this.toggleDie1.setText("1");
|
||||
this.toggleDie1.setEnabled(false);
|
||||
this.toggleDie1.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.toggleDie1;
|
||||
}
|
||||
|
||||
private JToggleButton getToggleDie2() {
|
||||
if (this.toggleDie2 == null) {
|
||||
this.toggleDie2 = new JToggleButton();
|
||||
this.toggleDie2.setText("2");
|
||||
this.toggleDie2.setEnabled(false);
|
||||
this.toggleDie2.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.toggleDie2;
|
||||
}
|
||||
|
||||
private JToggleButton getToggleDie3() {
|
||||
if (this.toggleDie3 == null) {
|
||||
this.toggleDie3 = new JToggleButton();
|
||||
this.toggleDie3.setText("3");
|
||||
this.toggleDie3.setEnabled(false);
|
||||
this.toggleDie3.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.toggleDie3;
|
||||
}
|
||||
|
||||
private JToggleButton getToggleDie4() {
|
||||
if (this.toggleDie4 == null) {
|
||||
this.toggleDie4 = new JToggleButton();
|
||||
this.toggleDie4.setText("4");
|
||||
this.toggleDie4.setEnabled(false);
|
||||
this.toggleDie4.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.toggleDie4;
|
||||
}
|
||||
|
||||
private JToggleButton getToggleDie5() {
|
||||
if (this.toggleDie5 == null) {
|
||||
this.toggleDie5 = new JToggleButton();
|
||||
this.toggleDie5.setText("5");
|
||||
this.toggleDie5.setEnabled(false);
|
||||
this.toggleDie5.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.toggleDie5;
|
||||
}
|
||||
|
||||
private JToggleButton getToggleDie6() {
|
||||
if (this.toggleDie6 == null) {
|
||||
this.toggleDie6 = new JToggleButton();
|
||||
this.toggleDie6.setText("6");
|
||||
this.toggleDie6.setEnabled(false);
|
||||
this.toggleDie6.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.toggleDie6;
|
||||
}
|
||||
|
||||
private JPanel getPanelActions() {
|
||||
if (this.panelActions == null) {
|
||||
BorderLayout borderLayout2 = new BorderLayout();
|
||||
borderLayout2.setVgap(0);
|
||||
borderLayout2.setHgap(0);
|
||||
this.panelActions = new JPanel();
|
||||
this.panelActions.setLayout(borderLayout2);
|
||||
this.panelActions.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
this.panelActions.add(this.getPanelRoundPoints(), "West");
|
||||
this.panelActions.add(this.getPanelActionsButtons(), "East");
|
||||
}
|
||||
|
||||
return this.panelActions;
|
||||
}
|
||||
|
||||
private JPanel getPanelRoundPoints() {
|
||||
if (this.panelRoundPoints == null) {
|
||||
this.labelRoundPointsValue = new JLabel();
|
||||
this.labelRoundPointsValue.setText("0");
|
||||
this.labelRoundPoints = new JLabel();
|
||||
this.labelRoundPoints.setText("Punkte des aktuellen Zuges : ");
|
||||
this.labelRoundPoints.setFont(new Font("Dialog", 0, 12));
|
||||
this.panelRoundPoints = new JPanel();
|
||||
this.panelRoundPoints.setLayout(new GridBagLayout());
|
||||
this.panelRoundPoints.add(this.labelRoundPoints, new GridBagConstraints());
|
||||
this.panelRoundPoints.add(this.labelRoundPointsValue, new GridBagConstraints());
|
||||
}
|
||||
|
||||
return this.panelRoundPoints;
|
||||
}
|
||||
|
||||
private JPanel getPanelActionsButtons() {
|
||||
if (this.panelActionsButtons == null) {
|
||||
GridLayout gridLayout6 = new GridLayout();
|
||||
gridLayout6.setRows(2);
|
||||
gridLayout6.setHgap(0);
|
||||
gridLayout6.setVgap(6);
|
||||
gridLayout6.setColumns(1);
|
||||
this.panelActionsButtons = new JPanel();
|
||||
this.panelActionsButtons.setLayout(gridLayout6);
|
||||
this.panelActionsButtons.add(this.getButtonRoll(), (Object)null);
|
||||
this.panelActionsButtons.add(this.getButtonReady(), (Object)null);
|
||||
}
|
||||
|
||||
return this.panelActionsButtons;
|
||||
}
|
||||
|
||||
private JButton getButtonRoll() {
|
||||
if (this.buttonRoll == null) {
|
||||
this.buttonRoll = new JButton();
|
||||
this.buttonRoll.setText("Würfeln");
|
||||
this.buttonRoll.setEnabled(false);
|
||||
this.buttonRoll.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.buttonRoll;
|
||||
}
|
||||
|
||||
private JButton getButtonReady() {
|
||||
if (this.buttonReady == null) {
|
||||
this.buttonReady = new JButton();
|
||||
this.buttonReady.setText("Zug beenden");
|
||||
this.buttonReady.setEnabled(false);
|
||||
this.buttonReady.addActionListener(this);
|
||||
}
|
||||
|
||||
return this.buttonReady;
|
||||
}
|
||||
|
||||
private JPanel getPanelDiceActions() {
|
||||
if (this.panelDiceActions == null) {
|
||||
BorderLayout borderLayout = new BorderLayout();
|
||||
borderLayout.setHgap(5);
|
||||
borderLayout.setVgap(5);
|
||||
this.panelDiceActions = new JPanel();
|
||||
this.panelDiceActions.setLayout(borderLayout);
|
||||
this.panelDiceActions.add(this.getPanelDice(), "Center");
|
||||
this.panelDiceActions.add(this.getPanelActions(), "South");
|
||||
}
|
||||
|
||||
return this.panelDiceActions;
|
||||
}
|
||||
|
||||
private JPanel getPanelStatus() {
|
||||
if (this.panelStatus == null) {
|
||||
this.labelStatus = new JLabel();
|
||||
this.labelStatus.setText(" ");
|
||||
this.labelStatus.setToolTipText("");
|
||||
this.labelStatus.setFont(new Font("Arial", 0, 12));
|
||||
this.panelStatus = new JPanel();
|
||||
this.panelStatus.setLayout(new BorderLayout());
|
||||
this.panelStatus.setBorder(BorderFactory.createBevelBorder(1));
|
||||
this.panelStatus.add(this.labelStatus, "North");
|
||||
}
|
||||
|
||||
return this.panelStatus;
|
||||
}
|
||||
|
||||
public GUI() {
|
||||
this.initialize();
|
||||
this.logic = new Logic(new Random());
|
||||
this.logic.resetGame();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
this.setSize(478, 311);
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(3);
|
||||
this.setName("mainFrame");
|
||||
this.setContentPane(this.getJContentPane());
|
||||
this.setTitle("Dings");
|
||||
}
|
||||
|
||||
private JPanel getJContentPane() {
|
||||
if (this.jContentPane == null) {
|
||||
BorderLayout borderLayout4 = new BorderLayout();
|
||||
borderLayout4.setHgap(3);
|
||||
borderLayout4.setVgap(2);
|
||||
this.jContentPane = new JPanel();
|
||||
this.jContentPane.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
|
||||
this.jContentPane.setLayout(borderLayout4);
|
||||
this.jContentPane.add(this.getPanelHead(), "North");
|
||||
this.jContentPane.add(this.getPanelMain(), "Center");
|
||||
this.jContentPane.add(this.getPanelStatus(), "South");
|
||||
}
|
||||
|
||||
return this.jContentPane;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object source = e.getSource();
|
||||
if (source != this.textfieldS1Name && source != this.textfieldS2Name) {
|
||||
if (source == this.buttonGo) {
|
||||
this.logic.startGame();
|
||||
this.labelStatus.setText(" ");
|
||||
this.buttonGo.setEnabled(false);
|
||||
this.textfieldS1Name.setEditable(false);
|
||||
this.textfieldS2Name.setEditable(false);
|
||||
this.buttonReady.setEnabled(true);
|
||||
this.labelS2PointsValue.setText(String.valueOf(this.logic.getPoints(1)));
|
||||
this.labelS1PointsValue.setText(String.valueOf(this.logic.getPoints(0)));
|
||||
this.syncRoundInfoToGui();
|
||||
this.logic.rollDice();
|
||||
this.syncLogicDiceToGui();
|
||||
this.toggleDie1.setEnabled(true);
|
||||
this.toggleDie2.setEnabled(true);
|
||||
this.toggleDie3.setEnabled(true);
|
||||
this.toggleDie4.setEnabled(true);
|
||||
this.toggleDie5.setEnabled(true);
|
||||
this.toggleDie6.setEnabled(true);
|
||||
} else if (source == this.buttonReady) {
|
||||
this.logic.finishRound();
|
||||
this.syncRoundInfoToGui();
|
||||
if (this.logic.isGameIsRunning()) {
|
||||
this.logic.rollDice();
|
||||
this.syncLogicDiceToGui();
|
||||
}
|
||||
} else if (source == this.buttonRoll) {
|
||||
if (!this.logic.isAtLeastOneDieFixedInCurrentThrow()) {
|
||||
this.labelStatus.setText("Wenigstens ein Würfel muss fixiert sein.");
|
||||
} else {
|
||||
String s = this.logic.rollDice();
|
||||
if (s != null) {
|
||||
this.labelStatus.setText(s);
|
||||
} else {
|
||||
this.syncLogicDiceToGui();
|
||||
}
|
||||
}
|
||||
} else if (source == this.toggleDie1) {
|
||||
this.toggleDie(this.toggleDie1, 0);
|
||||
} else if (source == this.toggleDie2) {
|
||||
this.toggleDie(this.toggleDie2, 1);
|
||||
} else if (source == this.toggleDie3) {
|
||||
this.toggleDie(this.toggleDie3, 2);
|
||||
} else if (source == this.toggleDie4) {
|
||||
this.toggleDie(this.toggleDie4, 3);
|
||||
} else if (source == this.toggleDie5) {
|
||||
this.toggleDie(this.toggleDie5, 4);
|
||||
} else if (source == this.toggleDie6) {
|
||||
this.toggleDie(this.toggleDie6, 5);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void toggleDie(JToggleButton die, int dieIndex) {
|
||||
String result = null;
|
||||
this.labelStatus.setText(" ");
|
||||
try {
|
||||
int resultingPoints = this.logic.changeDiceState(dieIndex);
|
||||
this.labelRoundPointsValue.setText(String.valueOf(resultingPoints));
|
||||
} catch (SelectionException e) {
|
||||
die.setSelected(!die.isSelected());
|
||||
this.labelStatus.setText(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void syncRoundInfoToGui() {
|
||||
if (this.logic.isGameIsRunning()) {
|
||||
this.labelRoundValue.setText(String.valueOf(this.logic.getRoundNumber()));
|
||||
this.labelRoundPointsValue.setText(String.valueOf(this.logic.getRoundPoints()));
|
||||
if (this.logic.getCurrentPlayer() == 0) {
|
||||
this.labelS1Name.setForeground(Color.GREEN);
|
||||
this.labelS2Name.setForeground(Color.BLACK);
|
||||
this.labelS2PointsValue.setText(String.valueOf(this.logic.getPoints(1)));
|
||||
} else {
|
||||
this.labelS2Name.setForeground(Color.GREEN);
|
||||
this.labelS1Name.setForeground(Color.BLACK);
|
||||
this.labelS1PointsValue.setText(String.valueOf(this.logic.getPoints(0)));
|
||||
}
|
||||
} else {
|
||||
this.labelS2Name.setForeground(Color.BLACK);
|
||||
this.labelS1Name.setForeground(Color.BLACK);
|
||||
this.textfieldS1Name.setEditable(true);
|
||||
this.textfieldS2Name.setEditable(true);
|
||||
this.labelStatus.setText("Das Spiel ist beendet!");
|
||||
this.buttonReady.setEnabled(false);
|
||||
this.buttonRoll.setEnabled(false);
|
||||
this.buttonGo.setEnabled(true);
|
||||
this.toggleDie1.setEnabled(false);
|
||||
this.toggleDie2.setEnabled(false);
|
||||
this.toggleDie3.setEnabled(false);
|
||||
this.toggleDie4.setEnabled(false);
|
||||
this.toggleDie5.setEnabled(false);
|
||||
this.toggleDie6.setEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void syncLogicDiceToGui() {
|
||||
this.syncLogicDieToGui(this.toggleDie1, 0);
|
||||
this.syncLogicDieToGui(this.toggleDie2, 1);
|
||||
this.syncLogicDieToGui(this.toggleDie3, 2);
|
||||
this.syncLogicDieToGui(this.toggleDie4, 3);
|
||||
this.syncLogicDieToGui(this.toggleDie5, 4);
|
||||
this.syncLogicDieToGui(this.toggleDie6, 5);
|
||||
this.buttonRoll.setEnabled(this.logic.isPlayerCanThrowDice());
|
||||
this.labelRoundPointsValue.setText(String.valueOf(this.logic.getRoundPoints()));
|
||||
}
|
||||
|
||||
private void syncLogicDieToGui(JToggleButton die, int dieIndex) {
|
||||
die.setText(String.valueOf(this.logic.getDiePips(dieIndex)));
|
||||
if (this.logic.isDieFixed(dieIndex)) {
|
||||
die.setForeground(Color.BLUE);
|
||||
die.setSelected(true);
|
||||
} else {
|
||||
die.setForeground(Color.BLACK);
|
||||
die.setSelected(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
GUI thisClass = new GUI();
|
||||
thisClass.setDefaultCloseOperation(3);
|
||||
thisClass.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user