Implementierung eines grundlegenden Startmenüs

This commit is contained in:
Luca Puderbach
2024-11-15 00:39:47 +01:00
parent caa45097c3
commit 853b52b52d
19 changed files with 485 additions and 835 deletions

View File

@@ -7,15 +7,16 @@
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;
import pp.monopoly.notification.GameEvent;
import pp.monopoly.notification.GameEventBroker;
import pp.monopoly.notification.ItemAddedEvent;
import pp.monopoly.notification.ItemRemovedEvent;
/**
* 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.
@@ -65,7 +66,7 @@ public class Board {
*/
private void addItem(Item item) {
items.add(item);
notifyListeners(new ItemAddedEvent(item, this));
notifyListeners((GameEvent) new ItemAddedEvent(item, null));
}
/**
@@ -75,7 +76,7 @@ public class Board {
*/
public void remove(Item item) {
items.remove(item);
notifyListeners(new ItemAddedEvent(item, this));
notifyListeners((GameEvent) new ItemRemovedEvent(item, null)); // Falls es ein entsprechendes ItemRemovedEvent gibt
}
/**

View File

@@ -1,29 +1,41 @@
////////////////////////////////////////
// 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;
import pp.monopoly.model.Item;
/**
* Event when an item is added to a map.
*
* @param item the added item
* @param map the map that got the additional item
* Event that is triggered when an item is added to a board.
*/
public record ItemAddedEvent(Item item, Board map) implements GameEvent {
public class ItemAddedEvent {
private final Item item;
private final Board board;
/**
* Notifies the game event listener of this event.
* Constructs a new ItemAddedEvent.
*
* @param listener the game event listener
* @param item the item that was added
* @param board the board to which the item was added
*/
@Override
public void notifyListener(GameEventListener listener) {
listener.receivedEvent(this);
public ItemAddedEvent(Item item, Board board) {
this.item = item;
this.board = board;
}
/**
* Gets the item that was added.
*
* @return the added item
*/
public Item getItem() {
return item;
}
/**
* Gets the board to which the item was added.
*
* @return the board
*/
public Board getBoard() {
return board;
}
}

View File

@@ -7,22 +7,30 @@
package pp.monopoly.notification;
import pp.monopoly.model.Item;
import pp.monopoly.model.Board;
import pp.monopoly.model.Item;
/**
* 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);
public class ItemRemovedEvent {
private final Item item;
private final Board board;
public ItemRemovedEvent(Item item, Board board) {
this.item = item;
this.board = board;
}
public Item getItem() {
return item;
}
public Board getBoard() {
return board;
}
}

View File

@@ -4,5 +4,17 @@ package pp.monopoly.notification;
* Enumeration representing different types of sounds used in the game.
*/
public enum Sound {
CLICK("click_sound.wav"),
WIN("win_sound.wav"),
LOSE("lose_sound.wav");
}
private final String fileName;
Sound(String fileName) {
this.fileName = fileName;
}
public String getFileName() {
return fileName;
}
}

View File

@@ -1,26 +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.
* Event when a sound needs to be played.
*
* @param sound the sound to be played
* @param soundFileName the sound file to be played
*/
public record SoundEvent(Sound sound) implements GameEvent {
public class SoundEvent implements GameEvent {
private final String soundFileName;
public SoundEvent(Sound sound) {
this.soundFileName = sound.getFileName(); // Angenommen, Sound hat eine Methode getFileName()
}
public String getSoundFileName() {
return soundFileName;
}
/**
* Notifies the game event listener of this event.
*
* @param listener the game event listener
*/
@Override
public void notifyListener(GameEventListener listener) {
listener.receivedEvent(this);
}
}