mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
finish: multiplayer layer
This commit is contained in:
@@ -1,21 +0,0 @@
|
|||||||
package org.toop.app;
|
|
||||||
|
|
||||||
public enum GameType {
|
|
||||||
TICTACTOE, OTHELLO;
|
|
||||||
|
|
||||||
public static String toName(GameType type) {
|
|
||||||
return switch (type) {
|
|
||||||
case TICTACTOE -> "Tic Tac Toe";
|
|
||||||
case OTHELLO -> "Othello";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameType toType(String name) {
|
|
||||||
return switch (name) {
|
|
||||||
case "Tic Tac Toe" -> TICTACTOE;
|
|
||||||
case "Reversi" -> OTHELLO;
|
|
||||||
|
|
||||||
default -> TICTACTOE;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package org.toop.app.layer.layers;
|
package org.toop.app.layer.layers;
|
||||||
|
|
||||||
import org.toop.app.App;
|
import org.toop.app.App;
|
||||||
import org.toop.app.GameType;
|
|
||||||
import org.toop.app.layer.Container;
|
import org.toop.app.layer.Container;
|
||||||
import org.toop.app.layer.Layer;
|
import org.toop.app.layer.Layer;
|
||||||
import org.toop.app.layer.containers.VerticalContainer;
|
import org.toop.app.layer.containers.VerticalContainer;
|
||||||
|
import org.toop.game.othello.Othello;
|
||||||
|
import org.toop.game.tictactoe.TicTacToe;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
|
||||||
@@ -21,11 +22,11 @@ public final class MainLayer extends Layer {
|
|||||||
final Container gamesContainer = new VerticalContainer(5);
|
final Container gamesContainer = new VerticalContainer(5);
|
||||||
|
|
||||||
gamesContainer.addButton("Tic Tac Toe", () -> {
|
gamesContainer.addButton("Tic Tac Toe", () -> {
|
||||||
App.activate(new MultiplayerLayer(GameType.TICTACTOE));
|
App.activate(new MultiplayerLayer<TicTacToe>());
|
||||||
});
|
});
|
||||||
|
|
||||||
gamesContainer.addButton("Othello", () -> {
|
gamesContainer.addButton("Othello", () -> {
|
||||||
App.activate(new MultiplayerLayer(GameType.OTHELLO));
|
App.activate(new MultiplayerLayer<Othello>());
|
||||||
});
|
});
|
||||||
|
|
||||||
final Container controlContainer = new VerticalContainer(5);
|
final Container controlContainer = new VerticalContainer(5);
|
||||||
|
|||||||
@@ -1,21 +1,29 @@
|
|||||||
package org.toop.app.layer.layers;
|
package org.toop.app.layer.layers;
|
||||||
|
|
||||||
import org.toop.app.App;
|
import org.toop.app.App;
|
||||||
import org.toop.app.GameType;
|
|
||||||
import org.toop.app.layer.Container;
|
import org.toop.app.layer.Container;
|
||||||
import org.toop.app.layer.Layer;
|
import org.toop.app.layer.Layer;
|
||||||
import org.toop.app.layer.containers.HorizontalContainer;
|
import org.toop.app.layer.containers.HorizontalContainer;
|
||||||
import org.toop.app.layer.containers.VerticalContainer;
|
import org.toop.app.layer.containers.VerticalContainer;
|
||||||
|
import org.toop.game.TurnBasedGame;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
|
||||||
public class MultiplayerLayer extends Layer {
|
public final class MultiplayerLayer<T extends TurnBasedGame> extends Layer {
|
||||||
boolean isConnectionLocal = true;
|
private boolean isConnectionLocal = true;
|
||||||
|
|
||||||
boolean isPlayer1Human = true;
|
private boolean isPlayer1Human = true;
|
||||||
boolean isPlayer2Human = true;
|
private String player1Name = "";
|
||||||
|
private int computer1Difficulty = 0;
|
||||||
|
|
||||||
protected MultiplayerLayer(GameType type) {
|
private boolean isPlayer2Human = true;
|
||||||
|
private String player2Name = "";
|
||||||
|
private int computer2Difficulty = 0;
|
||||||
|
|
||||||
|
private String serverIP = "";
|
||||||
|
private String serverPort = "";
|
||||||
|
|
||||||
|
public MultiplayerLayer() {
|
||||||
super("multiplayer.css");
|
super("multiplayer.css");
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
@@ -49,8 +57,7 @@ public class MultiplayerLayer extends Layer {
|
|||||||
mainContainer.addButton("Start", () -> {
|
mainContainer.addButton("Start", () -> {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
mainContainer.addButton("Connnect", () -> {
|
mainContainer.addButton("Connect", () -> {
|
||||||
App.activate(new GameLayer());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,11 +67,14 @@ public class MultiplayerLayer extends Layer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isPlayer1Human) {
|
if (isPlayer1Human) {
|
||||||
player1Container.addText("player is human", true);
|
player1Container.addText("Player name", true);
|
||||||
player1Container.addText("input player name here: ...", true);
|
player1Container.addInput(player1Name, (name) -> {
|
||||||
|
player1Name = name;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
player1Container.addText("Computer depth", true);
|
player1Container.addText("Computer difficulty", true);
|
||||||
player1Container.addSlider(9, 2, (depth) -> {
|
player1Container.addSlider(5, computer1Difficulty, (difficulty) -> {
|
||||||
|
computer1Difficulty = difficulty;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,22 +85,27 @@ public class MultiplayerLayer extends Layer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isPlayer2Human) {
|
if (isPlayer2Human) {
|
||||||
player2Container.addText("player is human", true);
|
player2Container.addText("Player name", true);
|
||||||
player2Container.addText("input player name here: ...", true);
|
player2Container.addInput(player2Name, (name) -> {
|
||||||
|
player2Name = name;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
player2Container.addText("Computer depth", true);
|
player2Container.addText("Computer difficulty", true);
|
||||||
player2Container.addSlider(9, 2, (depth) -> {
|
player2Container.addSlider(5, computer2Difficulty, (difficulty) -> {
|
||||||
|
computer2Difficulty = difficulty;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player2Container.addText("Server IP", true);
|
player2Container.addText("Server IP", true);
|
||||||
player2Container.addInput("", (input) -> {
|
player2Container.addInput(serverIP, (ip) -> {
|
||||||
|
serverIP = ip;
|
||||||
});
|
});
|
||||||
|
|
||||||
player2Container.addSeparator(true);
|
player2Container.addSeparator(true);
|
||||||
|
|
||||||
player2Container.addText("Server Port", true);
|
player2Container.addText("Server Port", true);
|
||||||
player2Container.addInput("", (input) -> {
|
player2Container.addInput(serverPort, (port) -> {
|
||||||
|
serverPort = port;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19
game/src/main/java/org/toop/game/othello/Othello.java
Normal file
19
game/src/main/java/org/toop/game/othello/Othello.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package org.toop.game.othello;
|
||||||
|
|
||||||
|
import org.toop.game.TurnBasedGame;
|
||||||
|
|
||||||
|
public final class Othello extends TurnBasedGame {
|
||||||
|
Othello() {
|
||||||
|
super(8, 8, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Move[] getLegalMoves() {
|
||||||
|
return new Move[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public State play(Move move) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
game/src/main/java/org/toop/game/othello/OthelloAI.java
Normal file
11
game/src/main/java/org/toop/game/othello/OthelloAI.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package org.toop.game.othello;
|
||||||
|
|
||||||
|
import org.toop.game.AI;
|
||||||
|
import org.toop.game.Game;
|
||||||
|
|
||||||
|
public final class OthelloAI extends AI<Othello> {
|
||||||
|
@Override
|
||||||
|
public Game.Move findBestMove(Othello game, int depth) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user