Refactored Game following the footprints of Socc
such Singleton, very software techniques, much patterns
This commit is contained in:
		@@ -9,8 +9,6 @@ import java.io.File;
 | 
			
		||||
 | 
			
		||||
public class ApplicationFrame implements Runnable
 | 
			
		||||
{
 | 
			
		||||
    private Game game;
 | 
			
		||||
 | 
			
		||||
    private JFrame jframe;
 | 
			
		||||
 | 
			
		||||
    private JPanel mapselectorpanel;
 | 
			
		||||
@@ -18,11 +16,6 @@ public class ApplicationFrame implements Runnable
 | 
			
		||||
 | 
			
		||||
    private JList<File> filelist;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public ApplicationFrame(Game game){
 | 
			
		||||
        this.game = game;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private class ListMouseHandler extends MouseAdapter{
 | 
			
		||||
        @Override
 | 
			
		||||
        public void mouseClicked(MouseEvent e) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,6 @@ import java.awt.event.KeyAdapter;
 | 
			
		||||
import java.awt.event.KeyEvent;
 | 
			
		||||
 | 
			
		||||
public class Control {
 | 
			
		||||
    private Game game;
 | 
			
		||||
 | 
			
		||||
    public class KeyHandler extends KeyAdapter{
 | 
			
		||||
        @Override
 | 
			
		||||
        public void keyTyped(KeyEvent e) {
 | 
			
		||||
@@ -14,49 +12,49 @@ public class Control {
 | 
			
		||||
            c = Character.toUpperCase(c);
 | 
			
		||||
            switch(c) {
 | 
			
		||||
                case 'W' :
 | 
			
		||||
                    game.moveONeill(Direction.NORTH);
 | 
			
		||||
                    Game.instance.moveONeill(Direction.NORTH);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'A' :
 | 
			
		||||
                    game.moveONeill(Direction.WEST);
 | 
			
		||||
                    Game.instance.moveONeill(Direction.WEST);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'S' :
 | 
			
		||||
                    game.moveONeill(Direction.SOUTH);
 | 
			
		||||
                    Game.instance.moveONeill(Direction.SOUTH);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'D' :
 | 
			
		||||
                    game.moveONeill(Direction.EAST);
 | 
			
		||||
                    Game.instance.moveONeill(Direction.EAST);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'I' :
 | 
			
		||||
                    game.moveJaffa(Direction.NORTH);
 | 
			
		||||
                    Game.instance.moveJaffa(Direction.NORTH);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'J' :
 | 
			
		||||
                    game.moveJaffa(Direction.WEST);
 | 
			
		||||
                    Game.instance.moveJaffa(Direction.WEST);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'K' :
 | 
			
		||||
                    game.moveJaffa(Direction.SOUTH);
 | 
			
		||||
                    Game.instance.moveJaffa(Direction.SOUTH);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'L' :
 | 
			
		||||
                    game.moveJaffa(Direction.EAST);
 | 
			
		||||
                    Game.instance.moveJaffa(Direction.EAST);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'Q' :
 | 
			
		||||
                    game.boxONeill();
 | 
			
		||||
                    Game.instance.boxONeill();
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'U' :
 | 
			
		||||
                    game.boxJaffa();
 | 
			
		||||
                    Game.instance.boxJaffa();
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'E' :
 | 
			
		||||
                    game.shootStargate(Color.YELLOW);
 | 
			
		||||
                    Game.instance.shootStargate(Color.YELLOW);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'R' :
 | 
			
		||||
                    game.shootStargate(Color.BLUE);
 | 
			
		||||
                    Game.instance.shootStargate(Color.BLUE);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'O' :
 | 
			
		||||
                    game.shootStargate(Color.RED);
 | 
			
		||||
                    Game.instance.shootStargate(Color.RED);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'P' :
 | 
			
		||||
                    game.shootStargate(Color.GREEN);
 | 
			
		||||
                    Game.instance.shootStargate(Color.GREEN);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
            game.updateDisplay();
 | 
			
		||||
            Game.instance.updateDisplay();
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,14 +6,12 @@ import java.util.TimerTask;
 | 
			
		||||
public class FlowOfTime extends Timer {
 | 
			
		||||
    private TimerTask timeup;
 | 
			
		||||
    private long gametime;
 | 
			
		||||
    private Game game;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private class GameOver extends TimerTask {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void run() {
 | 
			
		||||
            game.stopGame(GameoverCause.TIMEOUT);
 | 
			
		||||
            Game.instance.stopGame(GameoverCause.TIMEOUT);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,10 @@ public class Game {
 | 
			
		||||
    private FlowOfTime flowoftime;
 | 
			
		||||
 | 
			
		||||
    private Display display;
 | 
			
		||||
 | 
			
		||||
    public static Game instance = new Game();
 | 
			
		||||
    
 | 
			
		||||
    public Game() {
 | 
			
		||||
    private Game() {
 | 
			
		||||
        dungeon = new Dungeon();
 | 
			
		||||
        random = new Random();
 | 
			
		||||
        flowoftime = new FlowOfTime();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
package cicaprojekt;
 | 
			
		||||
 | 
			
		||||
public class PlayerBase implements Destroyable {
 | 
			
		||||
    protected Game game;
 | 
			
		||||
    protected Tile currentTile;
 | 
			
		||||
    protected Direction facingDirection;
 | 
			
		||||
    protected String name;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user