You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.5 KiB
111 lines
3.5 KiB
import java.util.ArrayList;
|
|
|
|
public class Game {
|
|
|
|
Gameboard gb;
|
|
ArrayList<Player> players;
|
|
|
|
public static void main(String[] args) {
|
|
Game g = new Game();
|
|
while(true){
|
|
for (Player p : g.players) {
|
|
int c = 0;
|
|
int dice;
|
|
|
|
do {
|
|
dice = p.rollDice();
|
|
|
|
/*
|
|
= Done rolldice()
|
|
--> dice(1-6)
|
|
= List<Integer> getUsableFigures (dice, g, p)
|
|
--> {0,1,2,3}
|
|
int choose(List<Integer> figs, p)
|
|
--> 1
|
|
setFigure (p.figures.get(1), dice, g, p)
|
|
--> nächster Spieler
|
|
*/
|
|
|
|
|
|
c++;
|
|
//g.checkFieldClear(p.startPos, p, g)
|
|
if(p.checkFigureInBase(p.figures) > 0 && dice == 6) {
|
|
int figId = p.choose() - 1;
|
|
//checkIfKicked
|
|
|
|
p.figures.get(figId).setPosition(p.startPos);
|
|
} else {
|
|
int figId = p.choose() - 1;
|
|
//moveToDice
|
|
}
|
|
} while (g.checkDice(dice, p, c));
|
|
|
|
p.checkGameWin(p.figures);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Game() {
|
|
this.gb = new Gameboard();
|
|
gb.initGameboard();
|
|
players = new ArrayList<>();
|
|
players.add(new Player("Rot",0, 40, 39));
|
|
players.add(new Player("Blau",10, 44, 9));
|
|
players.add(new Player("Gelb",20, 48, 19));
|
|
players.add(new Player("Grün",30, 52, 29));
|
|
}
|
|
|
|
public boolean checkDice(int dice, Player p, int countRolls) {
|
|
int figuresInBase = p.checkFigureInBase(p.figures);
|
|
if(figuresInBase == 4) {
|
|
return countRolls <= 3;
|
|
} else return dice == 6;
|
|
}
|
|
|
|
public int checkFieldClear(int posToCheck, Player p, Game g) {
|
|
int mode;
|
|
for (Player currentPlayer : g.players) {
|
|
if (currentPlayer.name.equals(p.name)) {
|
|
mode = 2;
|
|
} else {
|
|
mode = 1;
|
|
}
|
|
for (Figure f : currentPlayer.figures) {
|
|
if (posToCheck == f.getPosition()) {
|
|
return mode;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public ArrayList<Integer> getUsableFigures(int dice, Player p, Game g) {
|
|
ArrayList<Integer> result = new ArrayList<>();
|
|
for(int i = 0; i < p.figures.size(); i++) {
|
|
if(figureIsUsable(dice, i, p, g)) {
|
|
result.add(i);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public boolean figureIsUsable(int dice, int figId, Player p, Game g) {
|
|
Figure f = p.figures.get(figId);
|
|
|
|
if(p.checkFigureInBase(p.figures) > 0 && dice == 6){
|
|
if(g.checkFieldClear(p.startPos, p, g) == 2) {
|
|
return f.getPosition() == p.startPos; //TODO Wenn Figur auf Startpos von anderer Figur blockiert ist
|
|
}
|
|
return f.getPosition() == -1;
|
|
} else if (f.getPosition() <= p.jumpToHome && (f.getPosition() + dice) > p.jumpToHome) {
|
|
if((f.getPosition() + dice) <= p.jumpToHome + 4) {
|
|
return g.checkFieldClear(f.getPosition() + dice - p.jumpToHome + p.startHome - 1, p, g) != 2;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else if(f.getPosition() != -1) {
|
|
return g.checkFieldClear((f.getPosition() + dice) % 40, p, g) != 2;
|
|
}
|
|
return false;
|
|
}
|
|
}
|