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:
Ida Massow 2011-05-10 03:13:11 +02:00
parent b14a707d4f
commit a64492dc4b
4 changed files with 93 additions and 22 deletions

View file

@ -2,8 +2,7 @@ package jrummikub;
import javax.swing.UIManager; import javax.swing.UIManager;
import jrummikub.control.RoundControl; import jrummikub.control.GameControl;
import jrummikub.model.GameState;
import jrummikub.view.impl.View; import jrummikub.view.impl.View;
/** /**
@ -15,7 +14,7 @@ public class JRummikub {
* The main method * The main method
* *
* @param args * @param args
* command line arguments * command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
String nativeLF = UIManager.getSystemLookAndFeelClassName(); String nativeLF = UIManager.getSystemLookAndFeelClassName();
@ -25,11 +24,10 @@ public class JRummikub {
} catch (Exception e) { } catch (Exception e) {
} }
GameState gameState = new GameState();
View view = new View(); View view = new View();
RoundControl roundControl = new RoundControl(gameState, view); GameControl gameControl = new GameControl(view);
roundControl.startRound(); gameControl.startGame();
} }

View 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);
}
}

View file

@ -1,6 +1,8 @@
package jrummikub.control; package jrummikub.control;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import jrummikub.model.IGameState; import jrummikub.model.IGameState;
@ -9,35 +11,39 @@ import jrummikub.model.ITable;
import jrummikub.model.Position; import jrummikub.model.Position;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.model.StoneSet; import jrummikub.model.StoneSet;
import jrummikub.util.Connection;
import jrummikub.util.Event;
import jrummikub.util.IEvent;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import jrummikub.view.IView; import jrummikub.view.IView;
public class RoundControl { 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 IGameState gameState;
private IView view; private IView view;
private ITable clonedTable; private ITable clonedTable;
private Event endRoundEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>();
public RoundControl(IGameState gameState, IView view) { public RoundControl(IGameState gameState, IView view) {
this.gameState = gameState; this.gameState = gameState;
this.view = view; this.view = view;
view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT); }
view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
public IEvent getEndRoundEvent() {
return endRoundEvent;
} }
public void startRound() { public void startRound() {
deal(); deal();
view.getStartTurnEvent().add(new IListener() { connections.add(view.getStartTurnEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
startTurn(); startTurn();
} }
}); }));
prepareTurn(); prepareTurn();
} }
@ -58,13 +64,13 @@ public class RoundControl {
private void startTurn() { private void startTurn() {
TurnControl turnControl = new TurnControl(gameState.getActivePlayer() TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
.getHand(), clonedTable, view); .getHand(), clonedTable, view);
turnControl.getEndOfTurnEvent().add(new IListener() { connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
endOfTurn(); endOfTurn();
} }
}); }));
turnControl.startTurn(); turnControl.startTurn();
} }
@ -73,14 +79,17 @@ public class RoundControl {
for (int i = 0; i < gameState.getPlayerCount(); i++) { for (int i = 0; i < gameState.getPlayerCount(); i++) {
IHand hand = gameState.getNthNextPlayer(i).getHand(); IHand hand = gameState.getNthNextPlayer(i).getHand();
for (int j = 0; j < 7; j++) { for (int j = 0; j < 7; j++) {
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0)); hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1)); 0));
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
1));
} }
} }
} }
private void endOfTurn() { 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 (!tableDiff.isEmpty()) { // Player has made a move
if (clonedTable.isValid()) { if (clonedTable.isValid()) {
@ -128,7 +137,8 @@ public class RoundControl {
.getActivePlayer() .getActivePlayer()
.getHand() .getHand()
.drop(gameState.getGameHeap().drawStone(), .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) { private void dealPenalty(int count) {
@ -137,6 +147,10 @@ public class RoundControl {
} }
private void win() { private void win() {
for (Connection c : connections) {
c.remove();
}
endRoundEvent.emit();
view.enableWinPanel(true); view.enableWinPanel(true);
} }
} }

View file

@ -30,7 +30,7 @@ public class TurnControl {
private List<Stone> selectedStones = new ArrayList<Stone>(); private List<Stone> selectedStones = new ArrayList<Stone>();
private Event endOfTurnEvent = new Event(); 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) { public TurnControl(IHand hand, ITable table, IView view) {
this.hand = hand; this.hand = hand;
@ -203,11 +203,11 @@ public class TurnControl {
for (Stone stone : stones) { for (Stone stone : stones) {
hand.drop(stone, new Position(x, y)); hand.drop(stone, new Position(x, y));
x++; x++;
if (x >= RoundControl.HAND_WIDTH) { if (x >= GameControl.HAND_WIDTH) {
x = 0; x = 0;
y++; y++;
if (y >= RoundControl.HAND_HEIGHT) { if (y >= GameControl.HAND_HEIGHT) {
throw new ArrayIndexOutOfBoundsException(); // TODO We can't throw new ArrayIndexOutOfBoundsException(); // TODO We can't
// handle // handle
// this yet... // this yet...