Refactored Game following the footprints of Socc

such Singleton, very software techniques, much patterns
This commit is contained in:
Bokros Bálint 2016-05-13 13:56:16 +02:00
parent ccff798960
commit 3cd196df78
5 changed files with 19 additions and 29 deletions

View File

@ -9,8 +9,6 @@ import java.io.File;
public class ApplicationFrame implements Runnable public class ApplicationFrame implements Runnable
{ {
private Game game;
private JFrame jframe; private JFrame jframe;
private JPanel mapselectorpanel; private JPanel mapselectorpanel;
@ -18,11 +16,6 @@ public class ApplicationFrame implements Runnable
private JList<File> filelist; private JList<File> filelist;
public ApplicationFrame(Game game){
this.game = game;
}
private class ListMouseHandler extends MouseAdapter{ private class ListMouseHandler extends MouseAdapter{
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {

View File

@ -5,8 +5,6 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class Control { public class Control {
private Game game;
public class KeyHandler extends KeyAdapter{ public class KeyHandler extends KeyAdapter{
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
@ -14,49 +12,49 @@ public class Control {
c = Character.toUpperCase(c); c = Character.toUpperCase(c);
switch(c) { switch(c) {
case 'W' : case 'W' :
game.moveONeill(Direction.NORTH); Game.instance.moveONeill(Direction.NORTH);
break; break;
case 'A' : case 'A' :
game.moveONeill(Direction.WEST); Game.instance.moveONeill(Direction.WEST);
break; break;
case 'S' : case 'S' :
game.moveONeill(Direction.SOUTH); Game.instance.moveONeill(Direction.SOUTH);
break; break;
case 'D' : case 'D' :
game.moveONeill(Direction.EAST); Game.instance.moveONeill(Direction.EAST);
break; break;
case 'I' : case 'I' :
game.moveJaffa(Direction.NORTH); Game.instance.moveJaffa(Direction.NORTH);
break; break;
case 'J' : case 'J' :
game.moveJaffa(Direction.WEST); Game.instance.moveJaffa(Direction.WEST);
break; break;
case 'K' : case 'K' :
game.moveJaffa(Direction.SOUTH); Game.instance.moveJaffa(Direction.SOUTH);
break; break;
case 'L' : case 'L' :
game.moveJaffa(Direction.EAST); Game.instance.moveJaffa(Direction.EAST);
break; break;
case 'Q' : case 'Q' :
game.boxONeill(); Game.instance.boxONeill();
break; break;
case 'U' : case 'U' :
game.boxJaffa(); Game.instance.boxJaffa();
break; break;
case 'E' : case 'E' :
game.shootStargate(Color.YELLOW); Game.instance.shootStargate(Color.YELLOW);
break; break;
case 'R' : case 'R' :
game.shootStargate(Color.BLUE); Game.instance.shootStargate(Color.BLUE);
break; break;
case 'O' : case 'O' :
game.shootStargate(Color.RED); Game.instance.shootStargate(Color.RED);
break; break;
case 'P' : case 'P' :
game.shootStargate(Color.GREEN); Game.instance.shootStargate(Color.GREEN);
break; break;
} }
game.updateDisplay(); Game.instance.updateDisplay();
} }
} }

View File

@ -6,14 +6,12 @@ import java.util.TimerTask;
public class FlowOfTime extends Timer { public class FlowOfTime extends Timer {
private TimerTask timeup; private TimerTask timeup;
private long gametime; private long gametime;
private Game game;
private class GameOver extends TimerTask { private class GameOver extends TimerTask {
@Override @Override
public void run() { public void run() {
game.stopGame(GameoverCause.TIMEOUT); Game.instance.stopGame(GameoverCause.TIMEOUT);
} }
} }

View File

@ -17,8 +17,10 @@ public class Game {
private FlowOfTime flowoftime; private FlowOfTime flowoftime;
private Display display; private Display display;
public static Game instance = new Game();
public Game() { private Game() {
dungeon = new Dungeon(); dungeon = new Dungeon();
random = new Random(); random = new Random();
flowoftime = new FlowOfTime(); flowoftime = new FlowOfTime();

View File

@ -1,7 +1,6 @@
package cicaprojekt; package cicaprojekt;
public class PlayerBase implements Destroyable { public class PlayerBase implements Destroyable {
protected Game game;
protected Tile currentTile; protected Tile currentTile;
protected Direction facingDirection; protected Direction facingDirection;
protected String name; protected String name;