Merge pull request 'Kronjuwild' (#6) from Kronjuwild into main

Reviewed-on: #6
Reviewed-by: ole <git@peer-ole.de>
This commit is contained in:
ole 2024-11-14 16:23:21 +00:00
commit 22937ab45d
15 changed files with 382 additions and 4 deletions

View File

@ -2,6 +2,7 @@
<library name="jlayer-1.0.3"> <library name="jlayer-1.0.3">
<CLASSES> <CLASSES>
<root url="jar://$USER_HOME$/Downloads/jlayer-master/jlayer-master/target/jlayer-1.0.3.jar!/" /> <root url="jar://$USER_HOME$/Downloads/jlayer-master/jlayer-master/target/jlayer-1.0.3.jar!/" />
<root url="jar://$USER_HOME$/Downloads/jlayer-1.0.3.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
Grafik/sound button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B

BIN
graphics/aiPlayer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

BIN
graphics/backButton.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
graphics/humanplayer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

View File

@ -1,10 +1,14 @@
public class HalloSchiffeVersenken { public class HalloSchiffeVersenken {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
/*Luccas Methoden
MainMenuModel model = new MainMenuModel();
MainMenuView view = new MainMenuView();
MainMenuController controller = new MainMenuController(model, view);
*/
System.out.println("HelloSchiffeVersenekn"); System.out.println("HelloSchiffeVersenekn");
/*
System.out.println("sound"); System.out.println("sound");
SoundHandler.playSound("hit"); SoundHandler.playSound("hit");
@ -13,7 +17,7 @@ public class HalloSchiffeVersenken {
SoundHandler.setSoundOn(false); SoundHandler.setSoundOn(false);
System.out.println("sound off"); System.out.println("sound off");
SoundHandler.playSound("hit"); SoundHandler.playSound("hit");
*/
startLocalGame huso = new startLocalGame();
} }
} }

View File

@ -0,0 +1,31 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class MainMenuController implements ActionListener {
private MainMenuView view;
private MainMenuModel model;
public MainMenuController(MainMenuModel model, MainMenuView view) {
this.view = view;
this.model = model;
this.view.getLocalButton().addActionListener(this);
this.view.getMultiButton().addActionListener(this);
this.view.getSoundButton().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == view.getMultiButton()) {
view.closeWindOw();
MultiMenuModel model = new MultiMenuModel();
MultiMenuView view = new MultiMenuView();
MultiMenuController controller2 = new MultiMenuController(model, view);
} else if (e.getSource() == view.getMultiButton()) {
model.setGameMode("Multiplayer");
JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected.");
}else if (e.getSource() == view.getSoundButton()) {
view.toggleMute();
}
}
}

11
src/MainMenuModel.java Normal file
View File

@ -0,0 +1,11 @@
public class MainMenuModel {
private String gameMode;
public void setGameMode(String mode) {
this.gameMode = mode;
}
public String getGameMode() {
return gameMode;
}
}

73
src/MainMenuView.java Normal file
View File

@ -0,0 +1,73 @@
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.*;
public class MainMenuView {
ImageIcon SoundIcon = new ImageIcon("Grafik/sound button.png");
private JFrame frame = new JFrame();
private JLabel titelLabel = new JLabel("Studium versenken");
private JButton lokalButton = new JButton("Lokal");
private JButton multiButton= new JButton("Multiplayer");
private JButton soundButton = new JButton(SoundIcon);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public MainMenuView() {
buildFrame();
buildComponents();
}
public void buildComponents(){
lokalButton.setBounds(200,200,500,500);
multiButton.setBounds(800,200,500,500);
titelLabel.setBounds(550,10,700,100);
soundButton.setBounds(20,20,128,128);
titelLabel.setFont(robotoFont);
lokalButton.setFont(robotoFont.deriveFont(50f));
multiButton.setFont(robotoFont.deriveFont(50f));
}
public void buildFrame() {
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500,1000);
frame.setVisible(true);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
JLabel backgroundLabel = new JLabel(new ImageIcon("Grafik/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(titelLabel);
frame.add(lokalButton);
frame.add(multiButton);
frame.add(soundButton);
frame.setLocationRelativeTo(null);
}
public void toggleMute(){
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(soundButton.getIcon()==SoundIcon) {
soundButton.setIcon(MuteIcon);
}else{
soundButton.setIcon(SoundIcon);
}
}
public void closeWindOw(){
frame.dispose();
}
public JFrame getFrame() {
return frame;
}
public JButton getLocalButton() {
return lokalButton;
}
public JButton getMultiButton() {
return multiButton;
}
public JButton getSoundButton() {
return soundButton;
}
}

View File

@ -0,0 +1,21 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class MultiMenuController implements ActionListener {
private MultiMenuView view;
private MultiMenuModel model;
public MultiMenuController(MultiMenuModel model, MultiMenuView view) {
this.view = view;
this.model = model;
this.view.getSoundButton().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == view.getSoundButton()) {
view.toggleMute();
}
}
}

11
src/MultiMenuModel.java Normal file
View File

@ -0,0 +1,11 @@
public class MultiMenuModel {
private String gameMode;
public void setGameMode(String mode) {
this.gameMode = mode;
}
public String getGameMode() {
return gameMode;
}
}

53
src/MultiMenuView.java Normal file
View File

@ -0,0 +1,53 @@
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.*;
public class MultiMenuView {
ImageIcon SoundIcon = new ImageIcon("Grafik/sound button.png");
private JFrame frame = new JFrame();
private JButton soundButton = new JButton(SoundIcon);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public MultiMenuView() {
buildFrame();
buildComponents();
}
public void buildComponents(){
soundButton.setBounds(20,20,128,128);
}
public void buildFrame() {
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500,1000);
frame.setVisible(true);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
JLabel backgroundLabel = new JLabel(new ImageIcon("Grafik/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(soundButton);
frame.setLocationRelativeTo(null);
}
public void toggleMute(){
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(soundButton.getIcon()==SoundIcon) {
soundButton.setIcon(MuteIcon);
}else{
soundButton.setIcon(SoundIcon);
}
}
public void closeWindOw(){
frame.dispose();
}
public JFrame getFrame() {
return frame;
}
public JButton getSoundButton() {
return soundButton;
}
}

173
src/startLocalGame.java Normal file
View File

@ -0,0 +1,173 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class startLocalGame {
// Funktionshilfen
int semesterCounter = 1; // Semester Counter Label
// Grafiken
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
// Frame
JFrame frame = new JFrame("Lokales Spiel");
// Labels
JLabel frameTitle = new JLabel("Lokales Spiel");
JLabel semesterlable = new JLabel("Semester");
JLabel leftPlayerName = new JLabel("Name");
JLabel rightPlayerName = new JLabel("KI-Level");
JLabel leftPlayerIcon = new JLabel(humanPlayerIcon);
JLabel rightPlayerIcon = new JLabel(aiPlayerIcon);
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
// Buttons
JButton backButton = new JButton(backButtonIcon);
JButton leftPlayerLeftButton = new JButton("<-");
JButton leftPlayerRightButton = new JButton("->");
JButton semesterUpButton = new JButton("^");
JButton semesterDownButton = new JButton("v");
JButton rightPlayerLeftButton = new JButton("<-");
JButton rightPlayerRightButton = new JButton("->");
JButton startButton = new JButton("Start!");
// Textfelder
JTextField leftPlayerTextField = new JTextField(20);
JTextField rightPlayerTextField = new JTextField(20);
startLocalGame() {
// Erstelle Frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500, 1000);
// Layout Manager (absolute ositionierung)
frame.setLayout(null);
// Erstelle Label
frameTitle.setBounds(20, 20, 200, 30);
frame.add(frameTitle);
semesterlable.setBounds(700, 300, 200, 30);
frame.add(semesterlable);
leftPlayerName.setBounds(50, 625, 200, 30);
frame.add(leftPlayerName);
rightPlayerName.setBounds(1200, 625, 200, 30);
frame.add(rightPlayerName);
leftPlayerIcon.setBounds(75, 400, 200, 128);
frame.add(leftPlayerIcon);
rightPlayerIcon.setBounds(1225, 400, 200, 128);
frame.add(rightPlayerIcon);
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
frame.add(semesterCounterLabel);
// Erstellt Buttons
backButton.setBounds(1380, 20, 80, 80);
frame.add(backButton);
leftPlayerLeftButton.setBounds(50, 450, 50, 50);
frame.add(leftPlayerLeftButton);
leftPlayerRightButton.setBounds(250, 450, 50, 50);
frame.add(leftPlayerRightButton);
semesterUpButton.setBounds(725, 400, 50, 50);
frame.add(semesterUpButton);
semesterDownButton.setBounds(725, 550, 50, 50);
frame.add(semesterDownButton);
rightPlayerLeftButton.setBounds(1200, 450, 50, 50);
frame.add(rightPlayerLeftButton);
rightPlayerRightButton.setBounds(1400, 450, 50, 50);
frame.add(rightPlayerRightButton);
startButton.setBounds(700, 750, 100, 50);
frame.add(startButton);
// Erstellt Textfelder
leftPlayerTextField.setBounds(50, 650, 250, 50);
frame.add(leftPlayerTextField);
rightPlayerTextField.setBounds(1200, 650, 250, 50);
frame.add(rightPlayerTextField);
// ActionListener für die Buttons
semesterUpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (semesterCounter < 6) {
semesterCounter++;
semesterCounterLabel.setText(String.valueOf(semesterCounter));
}
}
});
semesterDownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (semesterCounter > 1) { // Verhindert, dass der Wert unter 1 fällt
semesterCounter--;
semesterCounterLabel.setText(String.valueOf(semesterCounter));
}
}
});
leftPlayerLeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(leftPlayerIcon.getIcon()==humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerIcon);
}else{
leftPlayerIcon.setIcon(humanPlayerIcon);
}
}
});
leftPlayerRightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(leftPlayerIcon.getIcon()==humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerIcon);
}else{
leftPlayerIcon.setIcon(humanPlayerIcon);
}
}
});
rightPlayerLeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(rightPlayerIcon.getIcon()==humanPlayerIcon) {
rightPlayerIcon.setIcon(aiPlayerIcon);
}else{
rightPlayerIcon.setIcon(humanPlayerIcon);
}
}
});
rightPlayerRightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(rightPlayerIcon.getIcon()==humanPlayerIcon) {
rightPlayerIcon.setIcon(aiPlayerIcon);
}else{
rightPlayerIcon.setIcon(humanPlayerIcon);
}
}
});
frame.setVisible(true);
}
}