From 433a0c3561eeaec96c23656a347e38e3a3602597 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 5 May 2011 13:16:46 +0200 Subject: Moved mock classes to separate source folder git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@142 72836036-5685-4462-b002-a69064685172 --- mock/jrummikub/model/MockGameState.java | 54 ++++++++++++++ mock/jrummikub/model/MockHand.java | 54 ++++++++++++++ mock/jrummikub/model/MockPlayer.java | 26 +++++++ mock/jrummikub/model/MockTable.java | 70 ++++++++++++++++++ mock/jrummikub/util/MockEvent.java | 23 ++++++ mock/jrummikub/util/MockEvent1.java | 23 ++++++ mock/jrummikub/util/MockEvent2.java | 23 ++++++ mock/jrummikub/view/MockHandPanel.java | 42 +++++++++++ mock/jrummikub/view/MockPlayerPanel.java | 39 ++++++++++ mock/jrummikub/view/MockStoneCollectionPanel.java | 28 +++++++ mock/jrummikub/view/MockTablePanel.java | 89 +++++++++++++++++++++++ mock/jrummikub/view/MockView.java | 68 +++++++++++++++++ 12 files changed, 539 insertions(+) create mode 100644 mock/jrummikub/model/MockGameState.java create mode 100644 mock/jrummikub/model/MockHand.java create mode 100644 mock/jrummikub/model/MockPlayer.java create mode 100644 mock/jrummikub/model/MockTable.java create mode 100644 mock/jrummikub/util/MockEvent.java create mode 100644 mock/jrummikub/util/MockEvent1.java create mode 100644 mock/jrummikub/util/MockEvent2.java create mode 100644 mock/jrummikub/view/MockHandPanel.java create mode 100644 mock/jrummikub/view/MockPlayerPanel.java create mode 100644 mock/jrummikub/view/MockStoneCollectionPanel.java create mode 100644 mock/jrummikub/view/MockTablePanel.java create mode 100644 mock/jrummikub/view/MockView.java (limited to 'mock') diff --git a/mock/jrummikub/model/MockGameState.java b/mock/jrummikub/model/MockGameState.java new file mode 100644 index 0000000..102e9fb --- /dev/null +++ b/mock/jrummikub/model/MockGameState.java @@ -0,0 +1,54 @@ +package jrummikub.model; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +public class MockGameState implements IGameState { + public MockTable table; + public List players; + public int activePlayer; + public StoneHeap gameHeap; + + public MockGameState() { + table = new MockTable(); + players = new ArrayList(); + players.add(new MockPlayer(Color.red)); + players.add(new MockPlayer(Color.yellow)); + players.add(new MockPlayer(Color.green)); + players.add(new MockPlayer(Color.black)); + activePlayer = 0; + gameHeap = new StoneHeap(); + } + + @Override + public ITable getTable() { + return table; + } + + @Override + public int getPlayerCount() { + return players.size(); + } + + @Override + public IPlayer getPlayer(int i) { + return players.get(i); + } + + /** Changes the activePlayer to the next {@link Player} in the list */ + @Override + public void nextPlayer() { + activePlayer = (activePlayer + 1) % players.size(); + } + + @Override + public IPlayer getActivePlayer() { + return players.get(activePlayer); + } + + @Override + public StoneHeap getGameHeap() { + return gameHeap; + } +} diff --git a/mock/jrummikub/model/MockHand.java b/mock/jrummikub/model/MockHand.java new file mode 100644 index 0000000..2132ff4 --- /dev/null +++ b/mock/jrummikub/model/MockHand.java @@ -0,0 +1,54 @@ +package jrummikub.model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import jrummikub.util.Pair; + +public class MockHand implements IHand { + + public List stones = new ArrayList(); + + public Iterable> iterable; + + @Override + public Stone pickUp(Position position) { + return null; + } + + @Override + public void drop(Stone object, Position position) { + stones.add(object); + } + + @Override + public Position getPosition(Stone object) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void pickUp(Stone object) { + // TODO Auto-generated method stub + + } + + @Override + public int getSize() { + return stones.size(); + } + + @Override + public Iterator> iterator() { + return iterable.iterator(); + } + + public MockHand clone() { + try { + return (MockHand) super.clone(); + } catch (CloneNotSupportedException e) { + return null; + } + } +} diff --git a/mock/jrummikub/model/MockPlayer.java b/mock/jrummikub/model/MockPlayer.java new file mode 100644 index 0000000..adb9d85 --- /dev/null +++ b/mock/jrummikub/model/MockPlayer.java @@ -0,0 +1,26 @@ +package jrummikub.model; + +import java.awt.Color; + +public class MockPlayer implements IPlayer { + + public MockHand hand; + public Color color; + + // private String name; + + public MockPlayer(Color color) { + hand = new MockHand(); + this.color = color; + } + + @Override + public IHand getHand() { + return hand; + } + + @Override + public Color getColor() { + return color; + } +} diff --git a/mock/jrummikub/model/MockTable.java b/mock/jrummikub/model/MockTable.java new file mode 100644 index 0000000..4d7ef1a --- /dev/null +++ b/mock/jrummikub/model/MockTable.java @@ -0,0 +1,70 @@ +package jrummikub.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import jrummikub.util.Pair; + +public class MockTable implements ITable { + public Map findStoneSet = new HashMap(); + public boolean valid = false; + public MockTable clonedTable; + public List> sets = new ArrayList>(); + + @Override + public void pickUpStone(Stone stone) { + // TODO Auto-generated method stub + + } + + @Override + public boolean isValid() { + return valid; + } + + @Override + public StoneSet pickUp(Position position) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void drop(StoneSet object, Position position) { + sets.add(new Pair(object, position)); + } + + @Override + public Position getPosition(StoneSet object) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void pickUp(StoneSet object) { + // TODO Auto-generated method stub + + } + + @Override + public Iterator> iterator() { + return sets.iterator(); + } + + @Override + public StoneSet findStoneSet(Stone stone) { + return findStoneSet.get(stone); + } + + public MockTable clone() { + return clonedTable; + } + + @Override + public int getSize() { + return sets.size(); + } + +} diff --git a/mock/jrummikub/util/MockEvent.java b/mock/jrummikub/util/MockEvent.java new file mode 100644 index 0000000..2f0efe5 --- /dev/null +++ b/mock/jrummikub/util/MockEvent.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class MockEvent implements IEvent { + public HashSet listeners = new HashSet(); + + @Override + public void add(IListener listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener listener) { + listeners.remove(listener); + } + + public void emit() { + for (IListener listener : listeners) { + listener.handle(); + } + } +} diff --git a/mock/jrummikub/util/MockEvent1.java b/mock/jrummikub/util/MockEvent1.java new file mode 100644 index 0000000..74cae0f --- /dev/null +++ b/mock/jrummikub/util/MockEvent1.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class MockEvent1 implements IEvent1 { + public HashSet> listeners = new HashSet>(); + + @Override + public void add(IListener1 listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener1 listener) { + listeners.remove(listener); + } + + public void emit(T value) { + for (IListener1 listener : listeners) { + listener.handle(value); + } + } +} diff --git a/mock/jrummikub/util/MockEvent2.java b/mock/jrummikub/util/MockEvent2.java new file mode 100644 index 0000000..93e8228 --- /dev/null +++ b/mock/jrummikub/util/MockEvent2.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class MockEvent2 implements IEvent2 { + public HashSet> listeners = new HashSet>(); + + @Override + public void add(IListener2 listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener2 listener) { + listeners.remove(listener); + } + + public void emit(T1 value1, T2 value2) { + for (IListener2 listener : listeners) { + listener.handle(value1, value2); + } + } +} diff --git a/mock/jrummikub/view/MockHandPanel.java b/mock/jrummikub/view/MockHandPanel.java new file mode 100644 index 0000000..4fdd58e --- /dev/null +++ b/mock/jrummikub/view/MockHandPanel.java @@ -0,0 +1,42 @@ +package jrummikub.view; + +import jrummikub.model.Position; +import jrummikub.model.Stone; +import jrummikub.util.Event2; +import jrummikub.util.IEvent1; +import jrummikub.util.IEvent2; +import jrummikub.util.Pair; + +public class MockHandPanel implements IHandPanel { + public Event2 stoneClickEvent = new Event2(); + public Iterable> stones; + + @Override + public IEvent2 getStoneClickEvent() { + return stoneClickEvent; + } + + @Override + public IEvent2 getRangeClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent2 getSetClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent1 getClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setStones(Iterable> stones) { + this.stones = stones; + } + +} diff --git a/mock/jrummikub/view/MockPlayerPanel.java b/mock/jrummikub/view/MockPlayerPanel.java new file mode 100644 index 0000000..fcf560e --- /dev/null +++ b/mock/jrummikub/view/MockPlayerPanel.java @@ -0,0 +1,39 @@ +package jrummikub.view; + +import jrummikub.util.IEvent; +import jrummikub.util.MockEvent; + +public class MockPlayerPanel implements IPlayerPanel { + public MockEvent endTurnEvent = new MockEvent(); + public MockHandPanel handPanel = new MockHandPanel(); + + @Override + public IHandPanel getHandPanel() { + // TODO Auto-generated method stub + return handPanel; + } + + @Override + public void setTimeLeft(int time) { + // TODO Auto-generated method stub + + } + + @Override + public IEvent getSortByGroupsEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent getSortByRunsEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent getEndTurnEvent() { + return endTurnEvent; + } + +} diff --git a/mock/jrummikub/view/MockStoneCollectionPanel.java b/mock/jrummikub/view/MockStoneCollectionPanel.java new file mode 100644 index 0000000..70016e5 --- /dev/null +++ b/mock/jrummikub/view/MockStoneCollectionPanel.java @@ -0,0 +1,28 @@ +package jrummikub.view; + +import jrummikub.model.Stone; +import jrummikub.util.Event2; +import jrummikub.util.IEvent2; + +public class MockStoneCollectionPanel implements IStoneCollectionPanel { + + public Event2 stoneClickEvent = new Event2(); + public Event2 setClickEvent = new Event2(); + + @Override + public IEvent2 getStoneClickEvent() { + return stoneClickEvent; + } + + @Override + public IEvent2 getRangeClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent2 getSetClickEvent() { + return setClickEvent; + } + +} diff --git a/mock/jrummikub/view/MockTablePanel.java b/mock/jrummikub/view/MockTablePanel.java new file mode 100644 index 0000000..c32946f --- /dev/null +++ b/mock/jrummikub/view/MockTablePanel.java @@ -0,0 +1,89 @@ +package jrummikub.view; + +import java.util.Map; + +import jrummikub.model.Position; +import jrummikub.model.Stone; +import jrummikub.model.StoneSet; +import jrummikub.util.Event1; +import jrummikub.util.Event2; +import jrummikub.util.IEvent1; +import jrummikub.util.IEvent2; +import jrummikub.util.Pair; + +public class MockTablePanel implements ITablePanel { + + public Event2 stoneClickEvent = new Event2(); + public Event2 setClickEvent = new Event2(); + public Event2 rangeClickEvent = new Event2(); + + public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel(); + public String leftPlayerName; + public String topPlayerName; + public String rightPlayerName; + + public Iterable> stoneSets; + + @Override + public IEvent2 getStoneClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent2 getRangeClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent2 getSetClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent1 getClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setLeftPlayerName(String playerName) { + leftPlayerName = playerName; + } + + @Override + public void setTopPlayerName(String playerName) { + topPlayerName = playerName; + } + + @Override + public void setRightPlayerName(String playerName) { + rightPlayerName = playerName; + } + + @Override + public void setStoneSets(Iterable> stoneSets) { + this.stoneSets = stoneSets; + } + + @Override + public IStoneCollectionPanel getStoneCollectionPanel() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Event1 getLeftConnectorClickEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Event1 getRightConnectorClickEvent() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java new file mode 100644 index 0000000..44b6a78 --- /dev/null +++ b/mock/jrummikub/view/MockView.java @@ -0,0 +1,68 @@ +package jrummikub.view; + +import java.util.Collection; + +import jrummikub.model.Stone; +import jrummikub.util.IEvent; +import jrummikub.util.MockEvent; + +public class MockView implements IView { + public MockPlayerPanel playerPanel = new MockPlayerPanel(); + public MockTablePanel tablePanel = new MockTablePanel(); + + public Collection selectedStones; + + public String currentPlayerName; + public boolean displayStartTurnPanel = false; + public boolean displayWinPanel = false; + + public MockEvent startTurnEvent = new MockEvent(); + public MockEvent quitEvent = new MockEvent(); + public MockEvent newGameEvent = new MockEvent(); + + @Override + public MockTablePanel getTablePanel() { + return tablePanel; + } + + @Override + public MockPlayerPanel getPlayerPanel() { + return playerPanel; + } + + @Override + public void setCurrentPlayerName(String playerName) { + currentPlayerName = playerName; + } + + @Override + public void setSelectedStones(Collection stones) { + selectedStones = stones; + } + + @Override + public void enableStartTurnPanel(boolean enable) { + displayStartTurnPanel = enable; + } + + @Override + public IEvent getStartTurnEvent() { + return startTurnEvent; + } + + @Override + public void enableWinPanel(boolean enable) { + displayWinPanel = enable; + } + + @Override + public IEvent getQuitEvent() { + return quitEvent; + } + + @Override + public IEvent getNewGameEvent() { + return newGameEvent; + } + +} \ No newline at end of file -- cgit v1.2.3