Complete overhaul of Application & ApplicationFrame so that game can end

This commit is contained in:
Kjistóf 2016-05-13 20:04:20 +02:00
parent 5585028819
commit 3be072e282
3 changed files with 44 additions and 11 deletions

View File

@ -2,10 +2,11 @@ package cicaprojekt;
public class Application
{
public static final ApplicationFrame frameInstance = new ApplicationFrame();
public static void main(String[] args)
{
ApplicationFrame af = new ApplicationFrame();
af.init();
af.run();
frameInstance.init();
frameInstance.run();
}
}

View File

@ -40,6 +40,24 @@ public class ApplicationFrame implements Runnable
jframe.setMinimumSize(new Dimension(600, 400));
jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
initMapselector();
jframe.add(mapselectorpanel);
}
public void backToMapSelection() {
jframe.remove(gamepanel);
initMapselector();
jframe.add(mapselectorpanel);
jframe.revalidate();
}
@Override
public void run() {
jframe.setVisible(true);
}
private void initMapselector() {
mapselectorpanel = new JPanel();
DefaultListModel<File> dungeonslist = new DefaultListModel<>();
@ -58,14 +76,6 @@ public class ApplicationFrame implements Runnable
filelist.addMouseListener(new ListMouseHandler());
mapselectorpanel.add(filelist);
jframe.add(mapselectorpanel);
}
@Override
public void run() {
jframe.setVisible(true);
}
private void setGameParams(File dungeonFile) throws IOException {

View File

@ -58,6 +58,28 @@ public class Game {
}
public void stopGame(GameoverCause cause) {
switch (cause){
case TIMEOUT:
JOptionPane.showMessageDialog(null, "Time is up! Anubis has enslaved the world by now.",
"Game over",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("Anubis.png"));
Application.frameInstance.backToMapSelection();
break;
case ONEILLWON:
JOptionPane.showMessageDialog(null, "Colonel O'Neill won!", "Game over",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("Deal_with_iit.png"));
Application.frameInstance.backToMapSelection();
break;
case JAFFAWON:
JOptionPane.showMessageDialog(null, "Jaffa won!", "Game over",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("Deal_with_iit.png"));
Application.frameInstance.backToMapSelection();
break;
}
}
public void moveONeill(Direction direction) {