From 55d81bf929f0f9dcbe67ce90860207b807e810dd Mon Sep 17 00:00:00 2001 From: wafialwakil Date: Sat, 24 Feb 2024 18:57:29 +0100 Subject: [PATCH] First_Push_Jackaroo_Game --- .project | 11 + Jackaroo/.classpath | 10 + Jackaroo/.project | 17 + .../src/GameFunctionality/GameboardGUI.java | 82 ++++ .../src/GameFunctionality/Gamesystem.java | 195 +++++++++ Jackaroo/src/Infrastructur/Cards.java | 7 + Jackaroo/src/Infrastructur/Figure.java | 7 + Jackaroo/src/Infrastructur/Gameboard.java | 408 ++++++++++++++++++ Jackaroo/src/MAIN/Main.java | 18 + Jackaroo/src/UI/ui.java | 5 + LICENSE | 1 - README.md | 3 - 12 files changed, 760 insertions(+), 4 deletions(-) create mode 100644 .project create mode 100644 Jackaroo/.classpath create mode 100644 Jackaroo/.project create mode 100644 Jackaroo/src/GameFunctionality/GameboardGUI.java create mode 100644 Jackaroo/src/GameFunctionality/Gamesystem.java create mode 100644 Jackaroo/src/Infrastructur/Cards.java create mode 100644 Jackaroo/src/Infrastructur/Figure.java create mode 100644 Jackaroo/src/Infrastructur/Gameboard.java create mode 100644 Jackaroo/src/MAIN/Main.java create mode 100644 Jackaroo/src/UI/ui.java delete mode 100644 LICENSE delete mode 100644 README.md diff --git a/.project b/.project new file mode 100644 index 0000000..9e46ab2 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + JACKAROO_PROJECT + + + + + + + + diff --git a/Jackaroo/.classpath b/Jackaroo/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/Jackaroo/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Jackaroo/.project b/Jackaroo/.project new file mode 100644 index 0000000..62e7e52 --- /dev/null +++ b/Jackaroo/.project @@ -0,0 +1,17 @@ + + + Jackaroo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Jackaroo/src/GameFunctionality/GameboardGUI.java b/Jackaroo/src/GameFunctionality/GameboardGUI.java new file mode 100644 index 0000000..52b6cf5 --- /dev/null +++ b/Jackaroo/src/GameFunctionality/GameboardGUI.java @@ -0,0 +1,82 @@ +package GameFunctionality; + +import Infrastructur.Gameboard; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +public class GameboardGUI extends JFrame { + + private Gameboard gameboard; + + public GameboardGUI(Gameboard gameboard) { + this.gameboard = gameboard; + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setTitle("Jackaroo (Wafi Al Wakil)"); + this.setResizable(true); + this.add(new GameboardPanel()); + this.pack(); + this.setLocationRelativeTo(null); + this.setVisible(true); + } + + private class GameboardPanel extends JPanel { + + @Override + protected void paintComponent(Graphics g) { + + super.paintComponent(g); + + int feldSize = 33; // Größe eines Feldes + + char[][] board = gameboard.getBoard(); + + for (int i = 0; i < gameboard.getBoardLength(); i++) { + for (int j = 0; j < gameboard.getBoardWidth(); j++) { + if (board[i][j] == 'O') { + g.setColor(Color.DARK_GRAY); // Hintergrundfarbe + } else if (board[i][j] == ' ') { + g.setColor(Color.WHITE); // Leere Felder + } else if (board[i][j] == 'X') { + g.setColor(Color.LIGHT_GRAY); // Sichere Zone + } else if (board[i][j] == 'R' || board[i][j] == 'B' || board[i][j] == 'G' || board[i][j] == 'Y') { + // Spielerfarben + switch (board[i][j]) { + case 'R': + g.setColor(Color.RED); + break; + case 'B': + g.setColor(Color.BLUE); + break; + case 'G': + g.setColor(Color.GREEN); + break; + case 'Y': + g.setColor(Color.YELLOW); + break; + } + } + g.fillRect(j * feldSize, i * feldSize, feldSize, feldSize); + g.setColor(Color.GRAY); + g.drawRect(j * feldSize, i * feldSize, feldSize, feldSize); + } + } + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(gameboard.getBoardWidth() * 33, gameboard.getBoardLength() * 33); // Größe des Fensters basierend auf der Brettgröße + } + } + + // Methode in Gameboard Klasse hinzufügen, um das Board zu erhalten + public char[][] getBoard() { + return this.getBoard(); + } + + +} diff --git a/Jackaroo/src/GameFunctionality/Gamesystem.java b/Jackaroo/src/GameFunctionality/Gamesystem.java new file mode 100644 index 0000000..80982be --- /dev/null +++ b/Jackaroo/src/GameFunctionality/Gamesystem.java @@ -0,0 +1,195 @@ +package GameFunctionality; + +import Infrastructur.Cards; +import Infrastructur.Figure; +import Infrastructur.Gameboard; + +public class Gamesystem { + + private Gameboard gameboard; + private int currentPlayer; + private boolean isGameOver; + + public Gamesystem(int numberOfPlayers, int numberOfPiecesPerPlayer) { + this.gameboard = new Gameboard(numberOfPlayers, numberOfPiecesPerPlayer); + this.currentPlayer = 1; // Start mit Spieler 1 + this.isGameOver = false; + } + + private boolean checkMove (int i, int j) { + + boolean isAllowedMove = false; + char[][] board = gameboard.getBoard(); + + if (board[i][j] == 'O' || board[i][j] == 'X') { + isAllowedMove = true; + } + + + return isAllowedMove; + } + + private Cards[] deckErstellen() { + + // create Deck Cards + Cards[] deck = new Cards[52]; + + for(int i=0; i<4; i++) { + deck[i]=Cards.ZWEI; + } + for(int i=4; i<8; i++) { + deck[i]=Cards.DREI; + } + for(int i=8; i<12; i++) { + deck[i]=Cards.VIER; + } + for(int i=12; i<16; i++) { + deck[i]=Cards.FÜNF; + } + for(int i=16; i<20; i++) { + deck[i]=Cards.SECHS; + } + for(int i=20; i<24; i++) { + deck[i]=Cards.SIEBEN; + } + for(int i=24; i<28; i++) { + deck[i]=Cards.ACHT; + } + for(int i=28; i<32; i++) { + deck[i]=Cards.NEUN; + } + for(int i=32; i<36; i++) { + deck[i]=Cards.ZEHN; + } + for(int i=36; i<40; i++) { + deck[i]=Cards.BUBE; + } + for(int i=40; i<44; i++) { + deck[i]=Cards.DAME; + } + for(int i=44; i<48; i++) { + deck[i]=Cards.KÖNIG; + } + for(int i=48; i<52; i++) { + deck[i]=Cards.ACE; + } + + // shuffle Deck Cards + // Array mischen mit dem Fisher-Yates-Algorithmus + for (int i = deck.length - 1; i > 0; i--) { + int index = (int) (Math.random() * (i + 1)); + Cards card = deck[index]; + deck[index] = deck[i]; + deck[i] = card; + } + + return deck; + } + + private void deckFunctinality(Cards card, Figure figure) { + + // move 2 steps forward (Clockwise) on the Game-Board 'O' with your own Figure + if(card == Cards.ZWEI) { + + } + + // move 3 steps forwardon (Clockwise) the Game-Board 'O' with your own Figure + if(card == Cards.DREI) { + + } + + // move 4 steps backward (Counterclockwise) on the Game-Board 'O' with your own Figure + if(card == Cards.VIER) { + + } + + // move 5 steps forward (Clockwise) on the Game-Board 'O' with any Figure on the Field + if(card == Cards.FÜNF) { + + } + + // move 6 steps forward (Clockwise) on the Game-Board 'O' with your own Figure + if(card == Cards.SECHS) { + + } + + // move in sum of 7 steps forward (Clockwise) on the Game-Board 'O' with two of your own Figures + if(card == Cards.SIEBEN) { + + } + // move 8 steps forward (Clockwise) on the Game-Board 'O' with your own Figure + if(card == Cards.ACHT) { + + } + // move 9 steps forward (Clockwise) on the Game-Board 'O' with your own Figure + if(card == Cards.NEUN) { + + } + // move 10 steps forward (Clockwise) on the Game-Board 'O' with your own Figure + // OR skip the turn of the next Player + if(card == Cards.ZEHN) { + + } + // exchange places of one of your pieces with one of another player pieces + if(card == Cards.BUBE) { + + } + // move 12 steps forward (Clockwise) on the Game-Board 'O' with your own Figure + if(card == Cards.DAME) { + + } + // move 13 steps forward (Clockwise) with your own Figure and destroy every Piece on the Way + // OR take one Figure or Piece out from your Home to your Base + if(card == Cards.KÖNIG) { + + } + // move 1 or 11 steps forward (Clockwise) with your own Figure + // OR take one Figure or Piece out from your Home to your Base + if(card == Cards.ACE) { + + } + + } + + public void startGame() { + // Initialisierung und Startlogik + System.out.println("Spiel gestartet mit " + gameboard.getNumberOfPlayers() + " Spielern."); + } + + public void makeMove(int player, int x, int y) { + // Prüfung, ob der Zug gültig ist und Aktualisierung des Spielbretts + if (isGameOver) { + System.out.println("Spiel ist bereits zu Ende."); + return; + } + if (player != currentPlayer) { + System.out.println("Es ist nicht die Reihe von Spieler " + player); + return; + } + // Hier könnte die Logik implementiert werden, um einen Zug zu machen + // Beispiel: gameboard.setPiece(x, y, player); + + // Prüfung auf Gewinn oder Niederlage nach jedem Zug + checkForWin(); + + // Spielerwechsel + currentPlayer = (currentPlayer % gameboard.getNumberOfPlayers()) + 1; + } + + private void checkForWin() { + // Implementierung der Logik zur Überprüfung des Gewinnzustands + // Wenn ein Gewinnzustand erkannt wird, isGameOver auf true setzen + } + + public boolean isGameOver() { + return isGameOver; + } + + public int getCurrentPlayer() { + return currentPlayer; + } + + + + +} \ No newline at end of file diff --git a/Jackaroo/src/Infrastructur/Cards.java b/Jackaroo/src/Infrastructur/Cards.java new file mode 100644 index 0000000..dece9be --- /dev/null +++ b/Jackaroo/src/Infrastructur/Cards.java @@ -0,0 +1,7 @@ +package Infrastructur; + +public enum Cards { + + ZWEI, DREI, VIER, FÜNF, SECHS, SIEBEN, ACHT, NEUN, ZEHN, BUBE, DAME, KÖNIG, ACE + +} diff --git a/Jackaroo/src/Infrastructur/Figure.java b/Jackaroo/src/Infrastructur/Figure.java new file mode 100644 index 0000000..6d5bfe6 --- /dev/null +++ b/Jackaroo/src/Infrastructur/Figure.java @@ -0,0 +1,7 @@ +package Infrastructur; + +public enum Figure { + + Blue, Red, Green, Yellow + +} diff --git a/Jackaroo/src/Infrastructur/Gameboard.java b/Jackaroo/src/Infrastructur/Gameboard.java new file mode 100644 index 0000000..c770b37 --- /dev/null +++ b/Jackaroo/src/Infrastructur/Gameboard.java @@ -0,0 +1,408 @@ +package Infrastructur; + +public class Gameboard { + + + + private static final int BOARD_LENGHT = 25; + private static final int BOARD_WIDTH = 25; + private static final int BOARDSIZE = 25; + + + + private char [][] board; + private int numberOfPlayers; + private int numberOfPiecesPerPlayer; + + + + + public Gameboard (int numberOfPlayers,int numberOfPiecesPerPlayer) { + if(numberOfPlayers < 2 || numberOfPlayers > 4) { + throw new IllegalArgumentException(); + } + if(numberOfPiecesPerPlayer < 1 || numberOfPiecesPerPlayer > 4) { + throw new IllegalArgumentException(); + } + this.numberOfPlayers = numberOfPlayers; + this.numberOfPiecesPerPlayer = numberOfPiecesPerPlayer; + this.board = new char [BOARD_LENGHT][BOARD_WIDTH]; + initializeBoard(); + } + + + + + + + public char[][] getBoard(){ + return board; + } + + public int getBoardLength() { + return BOARD_LENGHT; + } + + public int getBoardWidth() { + return BOARD_WIDTH; + } + + public int getNumberOfPlayers() { + return numberOfPlayers; + } + + + + + + + private char[][] initializeBoard() { + + int saveTheNumberOfPiecesPerPlayers = numberOfPiecesPerPlayer; + +//------------------------------------------------------------------- + // Fill ALL of the Game Board with O + for(int i=0; i= 1) { + for(int i=7; i<9; i++) { + for(int j=1; j<3; j++) { + while(numberOfPiecesPerPlayer>0) { + board[i][j] = 'R'; + numberOfPiecesPerPlayer--; + break; + } + } + } + numberOfPiecesPerPlayer = saveTheNumberOfPiecesPerPlayers; + } + + // The SECOND Player Home + if(numberOfPlayers >= 2) { + for(int i=16; i<18; i++) { + for(int j=22; j<24; j++) { + while(numberOfPiecesPerPlayer>0) { + board[i][j] = 'B'; + numberOfPiecesPerPlayer--; + break; + } + } + } + numberOfPiecesPerPlayer = saveTheNumberOfPiecesPerPlayers; + } + + // The THIRD Player Home + if(numberOfPlayers >= 3) { + for(int i=1; i<3; i++) { + for(int j=16; j<18; j++) { + while(numberOfPiecesPerPlayer>0) { + board[i][j] = 'G'; + numberOfPiecesPerPlayer--; + break; + } + } + } + numberOfPiecesPerPlayer = saveTheNumberOfPiecesPerPlayers; + } + + + // The FORTH Player Home + if(numberOfPlayers == 4) { + for(int i=22; i<24; i++) { + for(int j=7; j<9; j++) { + while(numberOfPiecesPerPlayer>0) { + board[i][j] = 'Y'; + numberOfPiecesPerPlayer--; + break; + } + } + } + numberOfPiecesPerPlayer = saveTheNumberOfPiecesPerPlayers; + } + + + return board; + + + } + + + + + + + + public void printBoard() { + for(int i=0; i> gives permission to link the code of this program with the proprietary Java implementation provided by Sun (or other vendors as well), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than the proprietary Java implementation. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. diff --git a/README.md b/README.md deleted file mode 100644 index 3b784b1..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# JACKAROO_PROJECT - -Jackaroo Board-Game by Wafi Al Wakil \ No newline at end of file