WinPanel funktioniert und ist getestet und überhaupt ist alles ganz toll
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@211 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
b14a707d4f
commit
a64492dc4b
4 changed files with 93 additions and 22 deletions
|
@ -2,8 +2,7 @@ package jrummikub;
|
|||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import jrummikub.control.RoundControl;
|
||||
import jrummikub.model.GameState;
|
||||
import jrummikub.control.GameControl;
|
||||
import jrummikub.view.impl.View;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +14,7 @@ public class JRummikub {
|
|||
* The main method
|
||||
*
|
||||
* @param args
|
||||
* command line arguments
|
||||
* command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
String nativeLF = UIManager.getSystemLookAndFeelClassName();
|
||||
|
@ -25,11 +24,10 @@ public class JRummikub {
|
|||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
GameState gameState = new GameState();
|
||||
View view = new View();
|
||||
|
||||
RoundControl roundControl = new RoundControl(gameState, view);
|
||||
roundControl.startRound();
|
||||
GameControl gameControl = new GameControl(view);
|
||||
gameControl.startGame();
|
||||
|
||||
}
|
||||
|
||||
|
|
59
src/jrummikub/control/GameControl.java
Normal file
59
src/jrummikub/control/GameControl.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package jrummikub.control;
|
||||
|
||||
import jrummikub.model.GameState;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
public class GameControl {
|
||||
final static int HAND_HEIGHT = 2;
|
||||
final static int HAND_WIDTH = 14;
|
||||
private IView view;
|
||||
private RoundControl roundControl;
|
||||
|
||||
public GameControl(IView view) {
|
||||
this.view = view;
|
||||
view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
|
||||
view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
|
||||
|
||||
view.getNewGameEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
startRound();
|
||||
}
|
||||
});
|
||||
view.getQuitEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
quitProgram();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
startRound();
|
||||
}
|
||||
|
||||
private void startRound() {
|
||||
if (roundControl != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameState gameState = new GameState();
|
||||
|
||||
roundControl = new RoundControl(gameState, view);
|
||||
roundControl.getEndRoundEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
roundControl = null;
|
||||
}
|
||||
});
|
||||
|
||||
roundControl.startRound();
|
||||
}
|
||||
|
||||
private void quitProgram() {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package jrummikub.control;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import jrummikub.model.IGameState;
|
||||
|
@ -9,35 +11,39 @@ import jrummikub.model.ITable;
|
|||
import jrummikub.model.Position;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneSet;
|
||||
import jrummikub.util.Connection;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.Pair;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
public class RoundControl {
|
||||
// TODO move to game control once existent
|
||||
final static int HAND_HEIGHT = 2;
|
||||
final static int HAND_WIDTH = 14;
|
||||
private IGameState gameState;
|
||||
private IView view;
|
||||
private ITable clonedTable;
|
||||
private Event endRoundEvent = new Event();
|
||||
private List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
public RoundControl(IGameState gameState, IView view) {
|
||||
this.gameState = gameState;
|
||||
this.view = view;
|
||||
view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
|
||||
view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
|
||||
}
|
||||
|
||||
public IEvent getEndRoundEvent() {
|
||||
return endRoundEvent;
|
||||
}
|
||||
|
||||
public void startRound() {
|
||||
deal();
|
||||
|
||||
view.getStartTurnEvent().add(new IListener() {
|
||||
connections.add(view.getStartTurnEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
startTurn();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
prepareTurn();
|
||||
}
|
||||
|
@ -58,13 +64,13 @@ public class RoundControl {
|
|||
private void startTurn() {
|
||||
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
|
||||
.getHand(), clonedTable, view);
|
||||
turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||
connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
turnControl.startTurn();
|
||||
}
|
||||
|
@ -73,14 +79,17 @@ public class RoundControl {
|
|||
for (int i = 0; i < gameState.getPlayerCount(); i++) {
|
||||
IHand hand = gameState.getNthNextPlayer(i).getHand();
|
||||
for (int j = 0; j < 7; j++) {
|
||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
|
||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
|
||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
||||
0));
|
||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
||||
1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void endOfTurn() {
|
||||
Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(gameState.getTable(),
|
||||
clonedTable);
|
||||
|
||||
if (!tableDiff.isEmpty()) { // Player has made a move
|
||||
if (clonedTable.isValid()) {
|
||||
|
@ -128,7 +137,8 @@ public class RoundControl {
|
|||
.getActivePlayer()
|
||||
.getHand()
|
||||
.drop(gameState.getGameHeap().drawStone(),
|
||||
new Position(HAND_WIDTH - 1, HAND_HEIGHT - 1));
|
||||
new Position(GameControl.HAND_WIDTH - 1,
|
||||
GameControl.HAND_HEIGHT - 1));
|
||||
}
|
||||
|
||||
private void dealPenalty(int count) {
|
||||
|
@ -137,6 +147,10 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
private void win() {
|
||||
for (Connection c : connections) {
|
||||
c.remove();
|
||||
}
|
||||
endRoundEvent.emit();
|
||||
view.enableWinPanel(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class TurnControl {
|
|||
private List<Stone> selectedStones = new ArrayList<Stone>();
|
||||
|
||||
private Event endOfTurnEvent = new Event();
|
||||
List<Connection> connections = new ArrayList<Connection>();
|
||||
private List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
public TurnControl(IHand hand, ITable table, IView view) {
|
||||
this.hand = hand;
|
||||
|
@ -203,11 +203,11 @@ public class TurnControl {
|
|||
for (Stone stone : stones) {
|
||||
hand.drop(stone, new Position(x, y));
|
||||
x++;
|
||||
if (x >= RoundControl.HAND_WIDTH) {
|
||||
if (x >= GameControl.HAND_WIDTH) {
|
||||
x = 0;
|
||||
y++;
|
||||
|
||||
if (y >= RoundControl.HAND_HEIGHT) {
|
||||
if (y >= GameControl.HAND_HEIGHT) {
|
||||
throw new ArrayIndexOutOfBoundsException(); // TODO We can't
|
||||
// handle
|
||||
// this yet...
|
||||
|
|
Reference in a new issue