First_Push_Jackaroo_Game

MAIN
wafialwakil 2024-02-24 18:57:29 +01:00
parent abc6f77664
commit 55d81bf929
12 changed files with 760 additions and 4 deletions

11
.project 100644
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JACKAROO_PROJECT</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Jackaroo/.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Jackaroo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,7 @@
package Infrastructur;
public enum Cards {
ZWEI, DREI, VIER, FÜNF, SECHS, SIEBEN, ACHT, NEUN, ZEHN, BUBE, DAME, KÖNIG, ACE
}

View File

@ -0,0 +1,7 @@
package Infrastructur;
public enum Figure {
Blue, Red, Green, Yellow
}

View File

@ -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<BOARDSIZE; i++) {
for(int j=0; j<BOARDSIZE; j++) {
board[i][j] = 'O';
}
}
//--------------------------------------------------------------------
// Fill the UPPER LEFT corner with empty spaces
for(int i=0; i<6; i++) {
for(int j=0; j<10; j++) {
board[i][j] = ' ';
}
}
for(int i=6; i<7; i++) {
for(int j=0; j<9; j++) {
board[i][j] = ' ';
}
}
for(int i=7; i<8; i++) {
for(int j=0; j<8; j++) {
board[i][j] = ' ';
}
}
for(int i=8; i<9; i++) {
for(int j=0; j<7; j++) {
board[i][j] = ' ';
}
}
for(int i=9; i<10; i++) {
for(int j=0; j<6; j++) {
board[i][j] = ' ';
}
}
//----------------------------------------------------------------
// Fill the UNDER LEFT corner with empty space
for(int i=15; i<BOARDSIZE; i++) {
for(int j=0; j<6; j++) {
board[i][j] = ' ';
}
}
for(int i=16; i<17; i++) {
for(int j=6; j<7; j++) {
board[i][j] = ' ';
}
}
for(int i=17; i<18; i++) {
for(int j=6; j<8; j++) {
board[i][j] = ' ';
}
}
for(int i=18; i<19; i++) {
for(int j=6; j<9; j++) {
board[i][j] = ' ';
}
}
for(int i=19; i<20; i++) {
for(int j=6; j<10; j++) {
board[i][j] = ' ';
}
}
for(int i=20; i<BOARDSIZE; i++) {
for(int j=6; j<10; j++) {
board[i][j] = ' ';
}
}
//----------------------------------------------------------------
// Fill the UPPER RIGHT corner with empty space
for(int i=0; i<6; i++) {
for(int j=15; j<BOARDSIZE; j++) {
board[i][j] = ' ';
}
}
for(int i=0; i<7; i++) {
for(int j=16; j<BOARDSIZE; j++) {
board[i][j] = ' ';
}
}
for(int i=0; i<8; i++) {
for(int j=17; j<BOARDSIZE; j++) {
board[i][j] = ' ';
}
}
for(int i=0; i<9; i++) {
for(int j=18; j<BOARDSIZE; j++) {
board[i][j] = ' ';
}
}for(int i=0; i<10; i++) {
for(int j=19; j<BOARDSIZE; j++) {
board[i][j] = ' ';
}
}
//---------------------------------------------------------------------
// Fill the UNDER RIGHT corner with empty space
for(int i= 19; i< BOARDSIZE; i++) {
for(int j= 15; j< BOARDSIZE; j++) {
board[i][j] = ' ';
}
}
for(int i=15; i<BOARDSIZE; i++) {
for(int j=19; j<BOARDSIZE; j++) {
board[i][j] = ' ';
}
}
for(int i=16; i< BOARDSIZE; i++) {
for(int j=18; j<19; j++) {
board[i][j] = ' ';
}
}
for(int i=17; i< BOARDSIZE; i++) {
for(int j=17; j<18; j++) {
board[i][j] = ' ';
}
}
for(int i=18; i< BOARDSIZE; i++) {
for(int j=16; j<17; j++) {
board[i][j] = ' ';
}
}
//---------------------------------------------------------------------
// Fill the not-needed places in the middle with empty spaces
for(int i=1; i<BOARDSIZE-1; i++) {
for(int j=11; j< 14; j++) {
board[i][j] = ' ';
}
}
for(int i=11; i<14; i++) {
for(int j=1; j<BOARDSIZE-1; j++) {
board[i][j] = ' ';
}
}
for(int i=6; i<11; i++) {
for(int j=10; j<11; j++) {
board[i][j] = ' ';
}
}
for(int i=7; i<11; i++) {
for(int j=9; j<10; j++) {
board[i][j] = ' ';
}
}
for(int i=8; i<11; i++) {
for(int j=8; j<9; j++) {
board[i][j] = ' ';
}
}
for(int i=9; i<11; i++) {
for(int j=7; j<8; j++) {
board[i][j] = ' ';
}
}
for(int i=10; i<11; i++) {
for(int j=6; j<7; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<15; i++) {
for(int j=6; j<7; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<16; i++) {
for(int j=7; j<8; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<17; i++) {
for(int j=8; j<9; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<18; i++) {
for(int j=9; j<10; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<19; i++) {
for(int j=10; j<11; j++) {
board[i][j] = ' ';
}
}
for(int i=6; i<11; i++) {
for(int j=14; j<15; j++) {
board[i][j] = ' ';
}
}
for(int i=7; i<11; i++) {
for(int j=15; j<16; j++) {
board[i][j] = ' ';
}
}
for(int i=8; i<11; i++) {
for(int j=16; j<17; j++) {
board[i][j] = ' ';
}
}
for(int i=9; i<11; i++) {
for(int j=17; j<18; j++) {
board[i][j] = ' ';
}
}
for(int i=10; i<11; i++) {
for(int j=18; j<19; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<19; i++) {
for(int j=14; j<15; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<18; i++) {
for(int j=15; j<16; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<17; i++) {
for(int j=16; j<17; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<16; i++) {
for(int j=17; j<18; j++) {
board[i][j] = ' ';
}
}
for(int i=14; i<15; i++) {
for(int j=18; j<19; j++) {
board[i][j] = ' ';
}
}
//------------------------------------------------------------
// Fill the safe place for the FIRST Player
for(int i=1; i<5; i++) {
for(int j=12; j<13; j++) {
board[i][j] = 'X';
}
}
// Fill the safe place for the SECOND Player
for(int i=12; i<13; i++) {
for(int j=1; j<5; j++) {
board[i][j] = 'X';
}
}
// Fill the safe place for the THIRD Player
for(int i=20; i<24; i++) {
for(int j=12; j<13; j++) {
board[i][j] = 'X';
}
}
// Fill the safe place for the FORTH Player
for(int i=12; i<13; i++) {
for(int j=20; j<24; j++) {
board[i][j] = 'X';
}
}
//-----------------------------------------------------------------
// The FIRST Player Home
if(numberOfPlayers >= 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<BOARDSIZE; i++) {
for(int j=0; j<BOARDSIZE; j++) {
System.out.print(board[i][j] + " ");
}
System.out.println();
}
}
}

View File

@ -0,0 +1,18 @@
package MAIN;
import GameFunctionality.GameboardGUI;
import Infrastructur.Gameboard;
public class Main {
public static void main(String[] args) {
int numberOfPlayers = 4;
int numberOfPiecesPerPlayer = 4;
Gameboard gameboard = new Gameboard(numberOfPlayers, numberOfPiecesPerPlayer);
new GameboardGUI(gameboard);
}
}

View File

@ -0,0 +1,5 @@
package UI;
public class ui {
}

View File

@ -1 +0,0 @@
In addition, as a special exception, <<var;name=licensor;original=XXXX;match=.+>> 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.

View File

@ -1,3 +0,0 @@
# JACKAROO_PROJECT
Jackaroo Board-Game by Wafi Al Wakil