diff options
author | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-01 01:16:42 +0200 |
---|---|---|
committer | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-01 01:16:42 +0200 |
commit | 561409f0d9d3215a1d8e6b31a7b0d848343bd8e8 (patch) | |
tree | 135029c56b428cced9b77c7db86f0b7b7c8fd0ea | |
parent | 257ce0ba9534aa026edf38723d69fb9ea3d666d7 (diff) | |
download | JRummikub-561409f0d9d3215a1d8e6b31a7b0d848343bd8e8.tar JRummikub-561409f0d9d3215a1d8e6b31a7b0d848343bd8e8.zip |
Abstract turn control has player, doesn't need hand
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@372 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | src/jrummikub/control/turn/AbstractTurnControl.java | 3 | ||||
-rw-r--r-- | src/jrummikub/control/turn/BaseAIControl.java | 12 | ||||
-rw-r--r-- | src/jrummikub/control/turn/HumanTurnControl.java | 34 | ||||
-rw-r--r-- | test/jrummikub/control/turn/BaseAIControlTest.java | 1 |
4 files changed, 22 insertions, 28 deletions
diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java index 688e147..088849d 100644 --- a/src/jrummikub/control/turn/AbstractTurnControl.java +++ b/src/jrummikub/control/turn/AbstractTurnControl.java @@ -1,7 +1,6 @@ package jrummikub.control.turn; import jrummikub.model.GameSettings; -import jrummikub.model.IHand; import jrummikub.model.IPlayer; import jrummikub.model.ITable; import jrummikub.util.Event; @@ -17,7 +16,6 @@ public abstract class AbstractTurnControl implements ITurnControl { protected Event redealEvent = new Event(); protected GameSettings settings; protected IPlayer player; - protected IHand hand; protected ITable table; protected IView view; protected TurnMode turnMode; @@ -37,7 +35,6 @@ public abstract class AbstractTurnControl implements ITurnControl { IView view, TurnMode turnMode) { this.settings = settings; this.player = player; - this.hand = player.getHand(); this.table = table; this.view = view; this.turnMode = turnMode; diff --git a/src/jrummikub/control/turn/BaseAIControl.java b/src/jrummikub/control/turn/BaseAIControl.java index 3c48341..cd68c37 100644 --- a/src/jrummikub/control/turn/BaseAIControl.java +++ b/src/jrummikub/control/turn/BaseAIControl.java @@ -77,14 +77,14 @@ public class BaseAIControl extends AbstractTurnControl { } private Stone findMatchingStone(Stone target) { - for (Pair<Stone, Position> entry : hand) { + for (Pair<Stone, Position> entry : player.getHand()) { Stone stone = entry.getFirst(); if (stone.getValue() == target.getValue() && stone.getColor() == target.getColor()) { return stone; } } - for (Pair<Stone, Position> entry : hand) { + for (Pair<Stone, Position> entry : player.getHand()) { Stone stone = entry.getFirst(); if (stone.isJoker()) { return stone; @@ -95,14 +95,14 @@ public class BaseAIControl extends AbstractTurnControl { private Stone pickUpMatchingStone(Stone target) { Stone match = findMatchingStone(target); - hand.pickUp(match); + player.getHand().pickUp(match); return match; } private void turn() { List<Stone> stones = new ArrayList<Stone>(); - for (Pair<Stone, Position> entry : hand) { + for (Pair<Stone, Position> entry : player.getHand()) { stones.add(entry.getFirst()); } @@ -147,8 +147,8 @@ public class BaseAIControl extends AbstractTurnControl { private void emitEndOfTurn() { long timeElapsed = System.currentTimeMillis() - startTime; - long timeNeeded = Math.min((long) (1000 + Math.random() * hand.getSize() - * 100), 50000); + long timeNeeded = Math.min((long) (1000 + Math.random() + * player.getHand().getSize() * 100), 50000); long waitTime = timeNeeded - timeElapsed; if (waitTime > 0) { diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java index 85f242f..427fe53 100644 --- a/src/jrummikub/control/turn/HumanTurnControl.java +++ b/src/jrummikub/control/turn/HumanTurnControl.java @@ -76,8 +76,8 @@ public class HumanTurnControl extends AbstractTurnControl { if (turnMode == TurnMode.NORMAL_TURN) { addTablePanelHandlers(); } - - view.getHandPanel().setStones(hand.clone()); + + view.getHandPanel().setStones(player.getHand().clone()); view.getHandPanel().resetCurrentRow(); view.setBottomPanel(BottomPanelType.HUMAN_HAND_PANEL); @@ -226,7 +226,7 @@ public class HumanTurnControl extends AbstractTurnControl { private void handClick(Position pos) { List<Stone> handStones = new ArrayList<Stone>(); for (Stone s : selectedStones) { - if (hand.pickUp(s)) { + if (player.getHand().pickUp(s)) { handStones.add(s); } } @@ -235,27 +235,27 @@ public class HumanTurnControl extends AbstractTurnControl { for (Stone s : handStones) { float x = Math.max(0, Math.min(13, pos.getX() - handStones.size() / 2.0f + i)); - hand.drop(s, new Position(x, (float) Math.floor(pos.getY()))); + player.getHand().drop(s, new Position(x, (float) Math.floor(pos.getY()))); selectedStones.remove(s); i++; } view.setSelectedStones(selectedStones); - view.getHandPanel().setStones(hand); + view.getHandPanel().setStones(player.getHand()); } private void sortStones(Comparator<Stone> comparator) { List<Stone> stones = new ArrayList<Stone>(); - for (Pair<Stone, Position> entry : hand) { + for (Pair<Stone, Position> entry : player.getHand()) { stones.add(entry.getFirst()); } for (Stone stone : stones) { - hand.pickUp(stone); + player.getHand().pickUp(stone); } Collections.sort(stones, comparator); int x = 0, y = 0; for (Stone stone : stones) { - hand.drop(stone, new Position(x, y)); + player.getHand().drop(stone, new Position(x, y)); x++; if (x >= Hand.WIDTH) { x = 0; @@ -263,7 +263,7 @@ public class HumanTurnControl extends AbstractTurnControl { } } - view.getHandPanel().setStones(hand); + view.getHandPanel().setStones(player.getHand()); } private void sortByRuns() { @@ -304,7 +304,7 @@ public class HumanTurnControl extends AbstractTurnControl { private void pickUpSelectedStones() { for (Stone stone : selectedStones) { - hand.pickUp(stone); + player.getHand().pickUp(stone); table.pickUpStone(stone); } } @@ -320,7 +320,7 @@ public class HumanTurnControl extends AbstractTurnControl { selectedStones.clear(); view.getTablePanel().setStoneSets(table); - view.getHandPanel().setStones(hand); + view.getHandPanel().setStones(player.getHand()); view.setSelectedStones(selectedStones); } @@ -380,7 +380,7 @@ public class HumanTurnControl extends AbstractTurnControl { return; } List<Pair<Stone, Position>> handPairs = new ArrayList<Pair<Stone, Position>>(); - for (Pair<Stone, Position> entry : hand) { + for (Pair<Stone, Position> entry : player.getHand()) { handPairs.add(entry); } @@ -436,17 +436,15 @@ public class HumanTurnControl extends AbstractTurnControl { new Position(newPos.getX() - selectedStones.size(), newPos.getY())); } } else { - table.drop( - new StoneSet(selectedStones), - new Position( - pos.getX() + (set.getSize() - selectedStones.size()) * 0.5f, pos - .getY())); + table.drop(new StoneSet(selectedStones), + new Position(pos.getX() + (set.getSize() - selectedStones.size()) + * 0.5f, pos.getY())); } selectedStones.clear(); view.getTablePanel().setStoneSets(table); - view.getHandPanel().setStones(hand); + view.getHandPanel().setStones(player.getHand()); view.setSelectedStones(selectedStones); } diff --git a/test/jrummikub/control/turn/BaseAIControlTest.java b/test/jrummikub/control/turn/BaseAIControlTest.java index dc9998a..2c7b1fe 100644 --- a/test/jrummikub/control/turn/BaseAIControlTest.java +++ b/test/jrummikub/control/turn/BaseAIControlTest.java @@ -1,7 +1,6 @@ package jrummikub.control.turn;
import static org.junit.Assert.*;
-import static org.junit.Assert.assertFalse;
import java.awt.Color;
|