mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 20:34:29 +02:00
init for monopoly
This commit is contained in:
10
Projekte/monopoly/model/build.gradle
Normal file
10
Projekte/monopoly/model/build.gradle
Normal file
@@ -0,0 +1,10 @@
|
||||
plugins {
|
||||
id 'buildlogic.java-library-conventions'
|
||||
}
|
||||
|
||||
description = 'Monopoly common model'
|
||||
|
||||
dependencies {
|
||||
api project(":common")
|
||||
api libs.jme3.networking
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly;
|
||||
|
||||
import pp.util.config.Config;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
/**
|
||||
* Provides access to the configuration settings for the Monopoly game.
|
||||
* <p>
|
||||
* This class allows for loading configuration settings from a properties file,
|
||||
* including the server port, map dimensions
|
||||
* </p>
|
||||
* <p>
|
||||
* <b>Note:</b> Attributes of this class are not marked as {@code final} to allow
|
||||
* for proper initialization when reading from a properties file.
|
||||
* </p>
|
||||
*/
|
||||
public class MonopolyConfig extends Config {
|
||||
|
||||
/**
|
||||
* The default port number for the Monopoly server.
|
||||
*/
|
||||
@Property("port")
|
||||
private int port = 1234;
|
||||
|
||||
/**
|
||||
* The width of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.width")
|
||||
private int mapWidth = 10;
|
||||
|
||||
/**
|
||||
* The height of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.height")
|
||||
private int mapHeight = 10;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code MonopolyConfig} with default settings.
|
||||
*/
|
||||
public MonopolyConfig() {
|
||||
// Default constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port number configured for the Monopoly server.
|
||||
*
|
||||
* @return the port number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the game map. The width is guaranteed to be at least 2 units.
|
||||
*
|
||||
* @return the width of the game map
|
||||
*/
|
||||
public int getMapWidth() {
|
||||
return max(mapWidth, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the game map. The height is guaranteed to be at least 2 units.
|
||||
*
|
||||
* @return the height of the game map
|
||||
*/
|
||||
public int getMapHeight() {
|
||||
return max(mapHeight, 2);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Provides access to the resource bundle of the game.
|
||||
*
|
||||
* @see #BUNDLE
|
||||
*/
|
||||
public class Resources {
|
||||
/**
|
||||
* The resource bundle for the Monopoly game.
|
||||
*/
|
||||
public static final ResourceBundle BUNDLE = ResourceBundle.getBundle("monopoly"); //NON-NLS
|
||||
|
||||
/**
|
||||
* Gets a string for the given key from the resource bundle in {@linkplain #BUNDLE}.
|
||||
*
|
||||
* @param key the key for the desired string
|
||||
* @return the string for the given key
|
||||
* @throws NullPointerException if {@code key} is {@code null}
|
||||
* @throws java.util.MissingResourceException if no object for the given key can be found
|
||||
* @throws ClassCastException if the object found for the given key is not a string
|
||||
*/
|
||||
public static String lookup(String key) {
|
||||
return BUNDLE.getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor to prevent instantiation.
|
||||
*/
|
||||
private Resources() { /* do not instantiate */ }
|
||||
}
|
@@ -0,0 +1,171 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.ServerInterpreter;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.SoundEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
/**
|
||||
* Controls the client-side game logic for Monopoly.
|
||||
* Manages the player's placement, interactions with the map, and response to server messages.
|
||||
*/
|
||||
public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
static final Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||
private final ClientSender clientSender;
|
||||
private final List<GameEventListener> listeners = new ArrayList<>();
|
||||
private Board ownMap;
|
||||
private Board harbor;
|
||||
private Board opponentMap;
|
||||
private ClientState state = null;
|
||||
|
||||
/**
|
||||
* Constructs a ClientGameLogic with the specified sender object.
|
||||
*
|
||||
* @param clientSender the object used to send messages to the server
|
||||
*/
|
||||
public ClientGameLogic(ClientSender clientSender) {
|
||||
this.clientSender = clientSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current state of the game logic.
|
||||
*/
|
||||
ClientState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current state of the game logic.
|
||||
*
|
||||
* @param newState the new state to be set
|
||||
*/
|
||||
void setState(ClientState newState) {
|
||||
LOGGER.log(Level.DEBUG, "state transition {0} --> {1}", state.getName(), newState.getName()); //NON-NLS
|
||||
state = newState;
|
||||
notifyListeners(new ClientStateEvent());
|
||||
state.entry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player's own map.
|
||||
*
|
||||
* @return the player's own map
|
||||
*/
|
||||
public Board getMap() {
|
||||
return ownMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the preview figure to the specified position.
|
||||
*
|
||||
* @param pos the new position for the preview figure
|
||||
*/
|
||||
public void movePreview(IntPoint pos) {
|
||||
state.movePreview(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the informational text to be displayed to the player.
|
||||
*
|
||||
* @param key the key for the info text
|
||||
*/
|
||||
void setInfoText(String key) {
|
||||
notifyListeners(new InfoTextEvent(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an event to play the specified sound.
|
||||
*
|
||||
* @param sound the sound to be played.
|
||||
*/
|
||||
public void playSound(Sound sound) {
|
||||
notifyListeners(new SoundEvent(sound));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a map from the specified file.
|
||||
*
|
||||
* @param file the file to load the map from
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public void loadMap(File file) throws IOException {
|
||||
state.loadMap(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the server.
|
||||
*
|
||||
* @param msg the message to be sent
|
||||
*/
|
||||
void send(ClientMessage msg) {
|
||||
if (clientSender == null)
|
||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||
else
|
||||
clientSender.send(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener to receive game events.
|
||||
*
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public synchronized void addListener(GameEventListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a listener from receiving game events.
|
||||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public synchronized void removeListener(GameEventListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all listeners of a game event.
|
||||
*
|
||||
* @param event the game event to notify listeners of
|
||||
*/
|
||||
@Override
|
||||
public void notifyListeners(GameEvent event) {
|
||||
final List<GameEventListener> copy;
|
||||
synchronized (this) {
|
||||
copy = new ArrayList<>(listeners);
|
||||
}
|
||||
for (GameEventListener listener : copy)
|
||||
event.notifyListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once per frame by the update loop.
|
||||
*
|
||||
* @param delta time in seconds since the last update call
|
||||
*/
|
||||
public void update(float delta) {
|
||||
state.update(delta);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
|
||||
/**
|
||||
* Interface for sending messages to the server.
|
||||
*/
|
||||
public interface ClientSender {
|
||||
/**
|
||||
* Send the specified message to the server.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
void send(ClientMessage message);
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
/**
|
||||
* Defines the behavior and state transitions for the client-side game logic.
|
||||
* Different states of the game logic implement this interface to handle various game events and actions.
|
||||
*/
|
||||
abstract class ClientState {
|
||||
/**
|
||||
* The game logic object.
|
||||
*/
|
||||
final ClientGameLogic logic;
|
||||
|
||||
/**
|
||||
* Constructs a client state of the specified game logic.
|
||||
*
|
||||
* @param logic the game logic
|
||||
*/
|
||||
ClientState(ClientGameLogic logic) {
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to be overridden by subclasses for post-transition initialization.
|
||||
* By default, it does nothing, but it can be overridden in derived states.
|
||||
*/
|
||||
void entry() {
|
||||
// Default implementation does nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the current state.
|
||||
*
|
||||
* @return the name of the current state
|
||||
*/
|
||||
String getName() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the battle state should be shown.
|
||||
*
|
||||
* @return true if the battle state should be shown, false otherwise
|
||||
*/
|
||||
boolean showTurn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the preview figure to the specified position.
|
||||
*
|
||||
* @param pos the new position for the preview figure
|
||||
*/
|
||||
void movePreview(IntPoint pos) {
|
||||
ClientGameLogic.LOGGER.log(Level.DEBUG, "movePreview has no effect in {0}", getName()); //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a map from the specified file.
|
||||
*
|
||||
* @param file the file to load the map from
|
||||
* @throws IOException if the map cannot be loaded in the current state
|
||||
*/
|
||||
void loadMap(File file) throws IOException {
|
||||
throw new IOException("You are not allowed to load a map in this state of the game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once per frame by the update loop if this state is active.
|
||||
*
|
||||
* @param delta time in seconds since the last update call
|
||||
*/
|
||||
void update(float delta) { /* do nothing by default */ }
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
/**
|
||||
* Interface representing a Monopoly client.
|
||||
* Provides methods to access game logic, configuration, and to enqueue tasks.
|
||||
*/
|
||||
public interface MonopolyClient {
|
||||
|
||||
/**
|
||||
* Returns the game logic associated with this client.
|
||||
*
|
||||
* @return the ClientGameLogic instance
|
||||
*/
|
||||
ClientGameLogic getGameLogic();
|
||||
|
||||
/**
|
||||
* Returns the configuration associated with this client.
|
||||
*
|
||||
* @return the MonopolyConfig instance
|
||||
*/
|
||||
MonopolyClientConfig getConfig();
|
||||
|
||||
/**
|
||||
* Enqueues a task to be executed by the client.
|
||||
*
|
||||
* @param runnable the task to be executed
|
||||
*/
|
||||
void enqueue(Runnable runnable);
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class providing access to the Monopoly client configuration.
|
||||
* Extends {@link MonopolyConfig} to include additional properties specific to the client.
|
||||
* This class manages configuration settings related to the RobotClient's behavior
|
||||
* and the game maps used in single mode.
|
||||
* <p>
|
||||
* <b>Note:</b> Attributes of this class should not be marked as {@code final}
|
||||
* to ensure proper functionality when reading from a properties file.
|
||||
* </p>
|
||||
*/
|
||||
public class MonopolyClientConfig extends MonopolyConfig {
|
||||
|
||||
/**
|
||||
* Path to the file representing the map.
|
||||
*/
|
||||
@Property("map")
|
||||
private String map;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a default {@code MonopolyClientConfig} with predefined values.
|
||||
*/
|
||||
public MonopolyClientConfig() {
|
||||
// Default constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file representing the opponent's map.
|
||||
*
|
||||
* @return the opponent's map file, or {@code null} if not set.
|
||||
*/
|
||||
public File getMap() {
|
||||
return map == null ? null : new File(map);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
/**
|
||||
* Interface representing a connection to the server.
|
||||
* Extends ClientSender to allow sending messages to the server.
|
||||
*/
|
||||
public interface ServerConnection extends ClientSender {
|
||||
|
||||
/**
|
||||
* Checks if the client is currently connected to the server.
|
||||
*
|
||||
* @return true if connected, false otherwise.
|
||||
*/
|
||||
boolean isConnected();
|
||||
|
||||
/**
|
||||
* Establishes a connection to the server.
|
||||
*/
|
||||
void connect();
|
||||
|
||||
/**
|
||||
* Disconnects from the server.
|
||||
*/
|
||||
void disconnect();
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
/**
|
||||
* Class representing a player
|
||||
*/
|
||||
public class Player {
|
||||
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.message.client.ClientInterpreter;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Controls the server-side game logic for Monopoly.
|
||||
* Manages game states, player interactions, and message handling.
|
||||
*/
|
||||
public class ServerGameLogic implements ClientInterpreter {
|
||||
private static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName());
|
||||
|
||||
private final MonopolyConfig config;
|
||||
private final List<Player> players = new ArrayList<>(2);
|
||||
private final Set<Player> readyPlayers = new HashSet<>();
|
||||
private final ServerSender serverSender;
|
||||
private Player activePlayer;
|
||||
private ServerState state = ServerState.WAIT;
|
||||
|
||||
/**
|
||||
* Constructs a ServerGameLogic with the specified sender and configuration.
|
||||
*
|
||||
* @param serverSender the sender used to send messages to clients
|
||||
* @param config the game configuration
|
||||
*/
|
||||
public ServerGameLogic(ServerSender serverSender, MonopolyConfig config) {
|
||||
this.serverSender = serverSender;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state of the game.
|
||||
*/
|
||||
ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new state of the game and logs the state transition.
|
||||
*
|
||||
* @param newState the new state to set
|
||||
*/
|
||||
void setState(ServerState newState) {
|
||||
LOGGER.log(Level.DEBUG, "state transition {0} --> {1}", state, newState); //NON-NLS
|
||||
state = newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the opponent of the specified player.
|
||||
*
|
||||
* @param p the player
|
||||
* @return the opponent of the player
|
||||
*/
|
||||
Player getOpponent(Player p) {
|
||||
if (players.size() != 2)
|
||||
throw new RuntimeException("trying to find opponent without having 2 players");
|
||||
final int index = players.indexOf(p);
|
||||
if (index < 0)
|
||||
throw new RuntimeException("Nonexistent player " + p);
|
||||
return players.get(1 - index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player representing the client with the specified connection ID.
|
||||
*
|
||||
* @param id the ID of the client
|
||||
* @return the player associated with the client ID, or null if not found
|
||||
*/
|
||||
public Player getPlayerById(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the specified player.
|
||||
*
|
||||
* @param player the player to send the message to
|
||||
* @param msg the message to send
|
||||
*/
|
||||
void send(Player player, ServerMessage msg) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new player to the game if there are less than two players.
|
||||
* Transitions the state to SET_UP if two players are present.
|
||||
*
|
||||
* @param id the connection ID of the new player
|
||||
* @return the player added to the game, or null if the game is not in the right state
|
||||
*/
|
||||
public Player addPlayer(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method");
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the player as ready
|
||||
* Transitions the state to PLAY if both players are ready.
|
||||
*
|
||||
* @param player the player who is ready
|
||||
*/
|
||||
void playerReady(Player player) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
/**
|
||||
* Interface for sending messages to a client.
|
||||
*/
|
||||
public interface ServerSender {
|
||||
/**
|
||||
* Send the specified message to the client.
|
||||
*
|
||||
* @param id the id of the client that shall receive the message
|
||||
* @param message the message
|
||||
*/
|
||||
void send(int id, ServerMessage message);
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
/**
|
||||
* Represents the different states of the Monopoly server during the game lifecycle.
|
||||
*/
|
||||
enum ServerState {
|
||||
/**
|
||||
* The server is waiting for clients to connect.
|
||||
*/
|
||||
WAIT,
|
||||
|
||||
/**
|
||||
* The server is waiting for clients to set up their maps.
|
||||
*/
|
||||
SET_UP,
|
||||
|
||||
/**
|
||||
* The battle of the game where players take turns
|
||||
*/
|
||||
BATTLE,
|
||||
|
||||
/**
|
||||
* The game has ended because all the players went bankrott
|
||||
*/
|
||||
GAME_OVER
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
/**
|
||||
* Visitor interface for processing all client messages.
|
||||
*/
|
||||
public interface ClientInterpreter {
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import com.jme3.network.AbstractMessage;
|
||||
|
||||
/**
|
||||
* An abstract base class for client messages used in network transfer.
|
||||
* It extends the AbstractMessage class provided by the jme3-network library.
|
||||
*/
|
||||
public abstract class ClientMessage extends AbstractMessage {
|
||||
|
||||
/**
|
||||
* Constructs a new ClientMessage instance.
|
||||
*/
|
||||
protected ClientMessage() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor for processing this message.
|
||||
*
|
||||
* @param interpreter the visitor to be used for processing
|
||||
* @param from the connection ID of the sender
|
||||
*/
|
||||
public abstract void accept(ClientInterpreter interpreter, int from);
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
/**
|
||||
* An interface for processing server messages.
|
||||
* Implementations of this interface can be used to handle different types of server messages.
|
||||
*/
|
||||
public interface ServerInterpreter {
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.AbstractMessage;
|
||||
|
||||
/**
|
||||
* An abstract base class for server messages used in network transfer.
|
||||
* It extends the AbstractMessage class provided by the jme3-network library.
|
||||
*/
|
||||
public abstract class ServerMessage extends AbstractMessage {
|
||||
|
||||
/**
|
||||
* Constructs a new ServerMessage instance.
|
||||
*/
|
||||
protected ServerMessage() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor for processing this message.
|
||||
*
|
||||
* @param interpreter the visitor to be used for processing
|
||||
*/
|
||||
public abstract void accept(ServerInterpreter interpreter);
|
||||
|
||||
/**
|
||||
* Gets the bundle key of the informational text to be shown at the client.
|
||||
* This key is used to retrieve the appropriate localized text for display.
|
||||
*
|
||||
* @return the bundle key of the informational text
|
||||
*/
|
||||
public abstract String getInfoTextKey();
|
||||
}
|
@@ -0,0 +1,167 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.ItemAddedEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Represents a rectangular map that holds figures and registers houses, hotels
|
||||
* It also supports event notification for game state changes such as item addition or removal.
|
||||
* Valid positions on this map have x-coordinates in the range of 0 to width-1 and y-coordinates
|
||||
* in the range of 0 to height-1.
|
||||
*
|
||||
* @see #getWidth()
|
||||
* @see #getHeight()
|
||||
*/
|
||||
public class Board {
|
||||
/**
|
||||
* A list of items (figure, house, etc.) placed on the map.
|
||||
*/
|
||||
private final List<Item> items = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The broker responsible for notifying registered listeners of events
|
||||
* (such as when an item is added or removed from the map).
|
||||
* Can be null, in which case no notifications will be sent.
|
||||
*/
|
||||
private final GameEventBroker eventBroker;
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
/**
|
||||
* Constructs an empty map with the given dimensions. The specified event broker
|
||||
* will handle the notification of changes in the map state, such as adding or removing items.
|
||||
* Passing null as the event broker is allowed, but in that case, no notifications will occur.
|
||||
*
|
||||
* @param width the number of columns (width) of the map
|
||||
* @param height the number of rows (height) of the map
|
||||
* @param eventBroker the event broker used for notifying listeners, or null if event distribution is not needed
|
||||
*/
|
||||
public Board(int width, int height, GameEventBroker eventBroker) {
|
||||
if (width < 1 || height < 1)
|
||||
throw new IllegalArgumentException("Invalid map size");
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.eventBroker = eventBroker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item (e.g., a figure or a house) to the map and triggers the appropriate event.
|
||||
*
|
||||
* @param item the item to be added to the map
|
||||
*/
|
||||
private void addItem(Item item) {
|
||||
items.add(item);
|
||||
notifyListeners(new ItemAddedEvent(item, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item from the map and triggers an item removal event.
|
||||
*
|
||||
* @param item the item to be removed from the map
|
||||
*/
|
||||
public void remove(Item item) {
|
||||
items.remove(item);
|
||||
notifyListeners(new ItemAddedEvent(item, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all items from the map and triggers corresponding removal events for each.
|
||||
*/
|
||||
public void clear() {
|
||||
new ArrayList<>(items).forEach(this::remove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of items of a specified type (class).
|
||||
*
|
||||
* @param clazz the class type to filter items by
|
||||
* @param <T> the type of items to return
|
||||
* @return a stream of items matching the specified class type
|
||||
*/
|
||||
private <T extends Item> Stream<T> getItems(Class<T> clazz) {
|
||||
return items.stream().filter(clazz::isInstance).map(clazz::cast);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list of all items currently on the map.
|
||||
*
|
||||
* @return an unmodifiable list of all items
|
||||
*/
|
||||
public List<Item> getItems() {
|
||||
return Collections.unmodifiableList(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width (number of columns) of the map.
|
||||
*
|
||||
* @return the width of the map
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height (number of rows) of the map.
|
||||
*
|
||||
* @return the height of the map
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether the specified position is within the map boundaries.
|
||||
*
|
||||
* @param pos the position to validate
|
||||
* @return true if the position is within the map, false otherwise
|
||||
*/
|
||||
public boolean isValid(IntPosition pos) {
|
||||
return isValid(pos.getX(), pos.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified coordinates are within the map boundaries.
|
||||
*
|
||||
* @param x the x-coordinate to validate
|
||||
* @param y the y-coordinate to validate
|
||||
* @return true if the coordinates are valid, false otherwise
|
||||
*/
|
||||
public boolean isValid(int x, int y) {
|
||||
return x >= 0 && x < width &&
|
||||
y >= 0 && y < height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the map.
|
||||
*
|
||||
* @return a string representation of the map
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Board:{" + items + '}'; //NON-NLS
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all registered listeners about a game event if the event broker is available.
|
||||
*
|
||||
* @param event the event to be distributed to listeners
|
||||
*/
|
||||
private void notifyListeners(GameEvent event) {
|
||||
if (eventBroker != null)
|
||||
eventBroker.notifyListeners(event);
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a point in the two-dimensional plane with integer coordinates.
|
||||
*/
|
||||
@Serializable
|
||||
public final class IntPoint implements IntPosition {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private IntPoint() { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Constructs a new IntPoint with the specified coordinates.
|
||||
*
|
||||
* @param x the x-coordinate of the point
|
||||
* @param y the y-coordinate of the point
|
||||
*/
|
||||
public IntPoint(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x-coordinate of the point.
|
||||
*
|
||||
* @return the x-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y-coordinate of the point.
|
||||
*
|
||||
* @return the y-coordinate
|
||||
*/
|
||||
@Override
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether some other object is "equal to" this one.
|
||||
*
|
||||
* @param obj the reference object with which to compare
|
||||
* @return true if this object is the same as the obj argument; false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || obj.getClass() != this.getClass()) return false;
|
||||
var that = (IntPoint) obj;
|
||||
return this.x == that.x &&
|
||||
this.y == that.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code value for the IntPoint.
|
||||
*
|
||||
* @return a hash code value for this object
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the IntPoint.
|
||||
*
|
||||
* @return a string representation of the object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IntPoint[" + //NON-NLS
|
||||
"x=" + x + ", " + //NON-NLS
|
||||
"y=" + y + ']'; //NON-NLS
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
/**
|
||||
* Interface representing a position with X and Y coordinates.
|
||||
*/
|
||||
public interface IntPosition {
|
||||
|
||||
/**
|
||||
* Returns the X coordinate of this position.
|
||||
*
|
||||
* @return the X coordinate.
|
||||
*/
|
||||
int getX();
|
||||
|
||||
/**
|
||||
* Returns the Y coordinate of this position.
|
||||
*
|
||||
* @return the Y coordinate.
|
||||
*/
|
||||
int getY();
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
/**
|
||||
* An interface representing any item on a board
|
||||
* It extends the IntPosition interface to provide position information.
|
||||
*/
|
||||
public interface Item {
|
||||
|
||||
/**
|
||||
* Accepts a visitor to perform operations on the item.
|
||||
*
|
||||
* @param visitor the visitor performing operations on the item
|
||||
* @param <T> the type of result returned by the visitor
|
||||
* @return the result of the visitor's operation on the item
|
||||
*/
|
||||
<T> T accept(Visitor<T> visitor);
|
||||
|
||||
/**
|
||||
* Accepts a visitor to perform operations on the item without returning a result.
|
||||
*
|
||||
* @param visitor the visitor performing operations on the item
|
||||
*/
|
||||
void accept(VoidVisitor visitor);
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Represents the rotation of a Item and provides functionality related to rotation.
|
||||
*/
|
||||
public enum Rotation implements Serializable {
|
||||
/**
|
||||
* Represents the item facing upwards.
|
||||
*/
|
||||
UP,
|
||||
/**
|
||||
* Represents the item facing rightwards.
|
||||
*/
|
||||
RIGHT,
|
||||
/**
|
||||
* Represents the item facing downwards.
|
||||
*/
|
||||
DOWN,
|
||||
/**
|
||||
* Represents the item facing leftwards.
|
||||
*/
|
||||
LEFT;
|
||||
|
||||
/**
|
||||
* Gets the change in x-coordinate corresponding to this rotation.
|
||||
*
|
||||
* @return the change in x-coordinate
|
||||
*/
|
||||
public int dx() {
|
||||
return switch (this) {
|
||||
case UP, DOWN -> 0;
|
||||
case RIGHT -> 1;
|
||||
case LEFT -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the change in y-coordinate corresponding to this rotation.
|
||||
*
|
||||
* @return the change in y-coordinate
|
||||
*/
|
||||
public int dy() {
|
||||
return switch (this) {
|
||||
case UP -> 1;
|
||||
case LEFT, RIGHT -> 0;
|
||||
case DOWN -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the orientation clockwise and returns the next rotation.
|
||||
*
|
||||
* @return the next rotation after rotating clockwise
|
||||
*/
|
||||
public Rotation rotate() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
/**
|
||||
* An interface for implementing the Visitor pattern for different types of elements in the Monopoly model.
|
||||
*
|
||||
* @param <T> the type of result returned by the visit methods
|
||||
*/
|
||||
public interface Visitor<T> {
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.model;
|
||||
|
||||
/**
|
||||
* An interface for implementing the Visitor pattern for different types of elements in the Monopoly model
|
||||
* without returning any result.
|
||||
*/
|
||||
public interface VoidVisitor {
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Event when an item is added to a map.
|
||||
*/
|
||||
public record ClientStateEvent() implements GameEvent {
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* An interface used for all game events.
|
||||
*/
|
||||
public interface GameEvent {
|
||||
/**
|
||||
* Notifies the game event listener of the event.
|
||||
*
|
||||
* @param listener the game event listener to be notified
|
||||
*/
|
||||
void notifyListener(GameEventListener listener);
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Defines a broker for distributing game events to registered listeners.
|
||||
*/
|
||||
public interface GameEventBroker {
|
||||
/**
|
||||
* Notifies all registered listeners about the specified game event.
|
||||
*
|
||||
* @param event the game event to be broadcast to listeners
|
||||
*/
|
||||
void notifyListeners(GameEvent event);
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Listener interface for all events implemented by subclasses of {@linkplain pp.monopoly.notification.GameEvent}.
|
||||
*/
|
||||
public interface GameEventListener {
|
||||
/**
|
||||
* Indicates that an item has been destroyed
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(ItemRemovedEvent event) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Indicates that an item has been added to a map.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(ItemAddedEvent event) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Indicates that an info text shall be shown.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(InfoTextEvent event) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Indicates that a sound shall be played.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(SoundEvent event) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Indicates that the client's state has changed.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Event when an item is added to a map.
|
||||
*
|
||||
* @param key the bundle key for the message
|
||||
*/
|
||||
public record InfoTextEvent(String key) implements GameEvent {
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.model.Board;
|
||||
|
||||
/**
|
||||
* Event when an item is added to a map.
|
||||
*
|
||||
* @param item the added item
|
||||
* @param map the map that got the additional item
|
||||
*/
|
||||
public record ItemAddedEvent(Item item, Board map) implements GameEvent {
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.model.Board;
|
||||
|
||||
/**
|
||||
* Event when an item gets removed.
|
||||
*
|
||||
* @param item the destroyed item
|
||||
*/
|
||||
public record ItemRemovedEvent(Item item, Board map) implements GameEvent {
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Enumeration representing different types of sounds used in the game.
|
||||
*/
|
||||
public enum Sound {
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.notification;
|
||||
|
||||
/**
|
||||
* Event when an item is added to a map.
|
||||
*
|
||||
* @param sound the sound to be played
|
||||
*/
|
||||
public record SoundEvent(Sound sound) implements GameEvent {
|
||||
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
########################################
|
||||
## Programming project code
|
||||
## UniBw M, 2022, 2023, 2024
|
||||
## www.unibw.de/inf2
|
||||
## (c) Mark Minas (mark.minas@unibw.de)
|
||||
########################################
|
||||
#
|
||||
battleship.name=Battleship
|
||||
button.ready=Ready
|
@@ -0,0 +1,9 @@
|
||||
########################################
|
||||
## Programming project code
|
||||
## UniBw M, 2022, 2023, 2024
|
||||
## www.unibw.de/inf2
|
||||
## (c) Mark Minas (mark.minas@unibw.de)
|
||||
########################################
|
||||
#
|
||||
monopoly.name=Monopoly
|
||||
button.ready=Bereit
|
@@ -0,0 +1,7 @@
|
||||
package pp.monopoly.client;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClientLogicTest {
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.game.client;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ClientGameLogicTest {
|
||||
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class ServerGameLogicTest {
|
||||
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package pp.monopoly.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class RandomPositionIteratorTest {
|
||||
|
||||
}
|
Reference in New Issue
Block a user