|
@ -12,15 +12,18 @@ import javax.swing.JLabel; |
|
|
import javax.swing.JPanel; |
|
|
import javax.swing.JPanel; |
|
|
import javax.swing.border.MatteBorder; |
|
|
import javax.swing.border.MatteBorder; |
|
|
|
|
|
|
|
|
|
|
|
import de.tims.fleetstorm.ai.Logic; |
|
|
import de.tims.fleetstorm.matchfield.Matchfield; |
|
|
import de.tims.fleetstorm.matchfield.Matchfield; |
|
|
|
|
|
|
|
|
public class Logic extends JPanel { |
|
|
|
|
|
|
|
|
public class GameLogic extends JPanel { |
|
|
|
|
|
|
|
|
// GameManager stuff |
|
|
// GameManager stuff |
|
|
private int gameState; |
|
|
private int gameState; |
|
|
private Matchfield matchfield; |
|
|
private Matchfield matchfield; |
|
|
|
|
|
private Matchfield enemyMatchfield; |
|
|
private int matchfieldSize = 10; |
|
|
private int matchfieldSize = 10; |
|
|
private boolean playerMove = true; |
|
|
private boolean playerMove = true; |
|
|
|
|
|
private Logic aiLogic; |
|
|
|
|
|
|
|
|
public static final int PREPARATION = 1; |
|
|
public static final int PREPARATION = 1; |
|
|
public static final int RUNNING = 2; |
|
|
public static final int RUNNING = 2; |
|
@ -39,7 +42,7 @@ public class Logic extends JPanel { |
|
|
private JLabel enemy4Ship; |
|
|
private JLabel enemy4Ship; |
|
|
private JLabel enemy5Ship; |
|
|
private JLabel enemy5Ship; |
|
|
|
|
|
|
|
|
public Logic(int gapToFrameBorder, int fieldWidth, int spaceBetween) { |
|
|
|
|
|
|
|
|
public GameLogic(int gapToFrameBorder, int fieldWidth, int spaceBetween) { |
|
|
this.fields = new ArrayList<>(); |
|
|
this.fields = new ArrayList<>(); |
|
|
setSize(640, 480); |
|
|
setSize(640, 480); |
|
|
|
|
|
|
|
@ -248,7 +251,7 @@ public class Logic extends JPanel { |
|
|
*/ |
|
|
*/ |
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
JFrame frame = new JFrame("Test GUI"); |
|
|
JFrame frame = new JFrame("Test GUI"); |
|
|
Logic gui = new Logic(15, 28, 1); |
|
|
|
|
|
|
|
|
GameLogic gui = new GameLogic(15, 28, 1); |
|
|
frame.setContentPane(gui); |
|
|
frame.setContentPane(gui); |
|
|
frame.setSize(640, 480); |
|
|
frame.setSize(640, 480); |
|
|
frame.setResizable(true); |
|
|
frame.setResizable(true); |
|
@ -256,9 +259,15 @@ public class Logic extends JPanel { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void start() { |
|
|
public void start() { |
|
|
this.gameState = Logic.PREPARATION; |
|
|
|
|
|
|
|
|
this.gameState = GameLogic.PREPARATION; |
|
|
|
|
|
|
|
|
|
|
|
// create player matchfield |
|
|
this.matchfield = new Matchfield(matchfieldSize); |
|
|
this.matchfield = new Matchfield(matchfieldSize); |
|
|
|
|
|
|
|
|
|
|
|
// create enemy matchfield and initialize AI (with player's matchfield) |
|
|
|
|
|
this.enemyMatchfield = new Matchfield(matchfieldSize); |
|
|
|
|
|
this.aiLogic = new Logic(); |
|
|
|
|
|
this.aiLogic.setMatchfield(this.matchfield); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void nextMove() { |
|
|
public void nextMove() { |