Add some endOfTurn handling to RoundControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@155 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
0b66e7d763
commit
38f6f0dc24
6 changed files with 254 additions and 219 deletions
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class MockGameState implements IGameState {
|
public class MockGameState implements IGameState {
|
||||||
public MockTable table;
|
public MockTable table;
|
||||||
|
public ITable setTable;
|
||||||
public List<MockPlayer> players;
|
public List<MockPlayer> players;
|
||||||
public int activePlayer;
|
public int activePlayer;
|
||||||
public StoneHeap gameHeap;
|
public StoneHeap gameHeap;
|
||||||
|
@ -56,4 +57,9 @@ public class MockGameState implements IGameState {
|
||||||
public IPlayer getNthNextPlayer(int i) {
|
public IPlayer getNthNextPlayer(int i) {
|
||||||
return players.get((activePlayer + i) % players.size());
|
return players.get((activePlayer + i) % players.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTable(ITable table) {
|
||||||
|
setTable = table;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class RoundControl {
|
||||||
endOfTurn();
|
endOfTurn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
turnControl.startTurn();
|
turnControl.startTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +75,27 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOfTurn() {
|
private void endOfTurn() {
|
||||||
|
Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable);
|
||||||
|
|
||||||
|
if (!tableDiff.isEmpty()) { // Player has made a move
|
||||||
|
if (clonedTable.isValid()) {
|
||||||
|
gameState.setTable(clonedTable);
|
||||||
|
|
||||||
|
// TODO Win check
|
||||||
|
} else {
|
||||||
|
gameState.getGameHeap().putBack(tableDiff);
|
||||||
|
dealPenalty(tableDiff.size());
|
||||||
|
}
|
||||||
|
} else { // Player hasn't made a move
|
||||||
|
if (clonedTable.isValid()) {
|
||||||
|
gameState.setTable(clonedTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
dealStone();
|
||||||
|
}
|
||||||
|
|
||||||
|
gameState.nextPlayer();
|
||||||
|
prepareTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Set<Stone> tableDifference(ITable oldTable, ITable newTable) {
|
static Set<Stone> tableDifference(ITable oldTable, ITable newTable) {
|
||||||
|
@ -94,15 +115,12 @@ public class RoundControl {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetTable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void preparePlayerTurn() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dealStone() {
|
private void dealStone() {
|
||||||
|
// gameState.getActivePlayer().getHand().drop(object, position)
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dealPenalty(int count) {
|
||||||
|
for (int i = 0; i < count + 3; ++i)
|
||||||
|
dealStone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,11 @@ public class GameState implements IGameState {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTable(ITable table) {
|
||||||
|
this.table = table;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerCount() {
|
public int getPlayerCount() {
|
||||||
return players.size();
|
return players.size();
|
||||||
|
|
|
@ -3,6 +3,7 @@ package jrummikub.model;
|
||||||
public interface IGameState {
|
public interface IGameState {
|
||||||
|
|
||||||
public ITable getTable();
|
public ITable getTable();
|
||||||
|
public void setTable(ITable table);
|
||||||
|
|
||||||
public int getPlayerCount();
|
public int getPlayerCount();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -56,4 +57,8 @@ public class StoneHeap {
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return heap.size();
|
return heap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void putBack(Collection<Stone> stones) {
|
||||||
|
heap.addAll(stones);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue