Browse Source

United AI with GameLogic

fleetstorm
Lorenz Hohmann 3 years ago
parent
commit
871f5fb860
  1. 17
      src/main/java/de/tims/fleetstorm/gui/GameLogic.java
  2. 6
      src/test/java/de/tims/fleetstorm/gui/LogicTest.java

17
src/main/java/de/tims/fleetstorm/gui/Logic.java → src/main/java/de/tims/fleetstorm/gui/GameLogic.java

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

6
src/test/java/de/tims/fleetstorm/gui/LogicTest.java

@ -7,11 +7,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import de.tims.fleetstorm.gui.Logic;
import de.tims.fleetstorm.gui.GameLogic;
class LogicTest {
Logic guiLogic = new Logic(0, 0, 0);
GameLogic guiLogic = new GameLogic(0, 0, 0);
@BeforeEach
void setup() {
@ -20,7 +20,7 @@ class LogicTest {
@Test
void testIfGameStateIsPreparationAfterStart() {
int expectedState = Logic.PREPARATION;
int expectedState = GameLogic.PREPARATION;
int calculatedState = guiLogic.getGameState();

Loading…
Cancel
Save