Add highlighting to board and table
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@37 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
9ea9b11501
commit
dd46130c8c
5 changed files with 39 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
package jrummikub;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -59,10 +60,13 @@ public class JRummikub {
|
|||
stones.put(new Stone(9, StoneColor.RED, false), new Position(0.5f, 1));
|
||||
stones.put(new Stone(7, StoneColor.BLACK, false), new Position(1.75f, 1));
|
||||
|
||||
stones.put(new Stone(0, StoneColor.RED, true), new Position(2.5f, 0));
|
||||
Stone stoneJoker = new Stone(0, StoneColor.RED, true);
|
||||
stones.put(stoneJoker, new Position(2.5f, 0));
|
||||
stones.put(new Stone(0, StoneColor.BLACK, true), new Position(3.5f, 0));
|
||||
|
||||
|
||||
view.getPlayerPanel().getBoard().setStones(stones);
|
||||
view.getPlayerPanel().getBoard().setHighlightedStones(Collections.singleton(stoneJoker));
|
||||
|
||||
view.getPlayerPanel().getBoard().getClickEvent().add(new IListener1<Position>(){
|
||||
|
||||
@Override
|
||||
|
@ -87,13 +91,15 @@ public class JRummikub {
|
|||
List<Stone> stoneList = new ArrayList<Stone>();
|
||||
|
||||
stoneList.add(new Stone(7, StoneColor.BLACK, false));
|
||||
stoneList.add(new Stone(8, StoneColor.BLACK, false));
|
||||
Stone stone8 = new Stone(8, StoneColor.BLACK, false);
|
||||
stoneList.add(stone8);
|
||||
stoneList.add(new Stone(9, StoneColor.BLACK, false));
|
||||
stoneList.add(new Stone(10, StoneColor.BLACK, false));
|
||||
|
||||
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
|
||||
|
||||
view.getTable().setStoneSets(stoneSets);
|
||||
view.getTable().setHighlightedStones(Collections.singleton(stone8));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package jrummikub.view;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import jrummikub.model.Position;
|
||||
|
@ -8,6 +9,7 @@ import jrummikub.util.IEvent1;
|
|||
|
||||
public interface IBoard {
|
||||
public void setStones(Map<Stone, Position> stones);
|
||||
public void setHighlightedStones(Collection<Stone> stones);
|
||||
|
||||
public IEvent1<Position> getClickEvent();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package jrummikub.view;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import jrummikub.model.Position;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneSet;
|
||||
import jrummikub.util.IEvent1;
|
||||
|
||||
|
@ -10,6 +12,9 @@ public interface ITable {
|
|||
public void setLeftPlayerName(String playerName);
|
||||
public void setTopPlayerName(String playerName);
|
||||
public void setRightPlayerName(String playerName);
|
||||
|
||||
public void setStoneSets(Map<StoneSet, Position> stoneSets);
|
||||
public void setHighlightedStones(Collection<Stone> stones);
|
||||
|
||||
public IEvent1<Position> getClickEvent();
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.awt.Insets;
|
|||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -24,6 +25,8 @@ public class Board extends JPanel implements IBoard {
|
|||
private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png"));
|
||||
|
||||
private Map<Stone, Position> stones = Collections.emptyMap();
|
||||
private Collection<Stone> highlightedStones = Collections.emptyList();
|
||||
|
||||
private StonePainter stonePainter = new StonePainter(StonePainter.BOARD_SCALE);
|
||||
|
||||
private Event1<Position> clickEvent = new Event1<Position>();
|
||||
|
@ -65,8 +68,9 @@ public class Board extends JPanel implements IBoard {
|
|||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
for (Map.Entry<Stone, Position> stone : stones.entrySet()) {
|
||||
stonePainter.paintStone(g, stone.getKey(), stone.getValue(), false);
|
||||
for (Map.Entry<Stone, Position> entry : stones.entrySet()) {
|
||||
stonePainter.paintStone(g, entry.getKey(), entry.getValue(),
|
||||
highlightedStones.contains(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,4 +78,9 @@ public class Board extends JPanel implements IBoard {
|
|||
public void setStones(Map<Stone, Position> stones) {
|
||||
this.stones = stones;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHighlightedStones(Collection<Stone> stones) {
|
||||
highlightedStones = stones;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.awt.Insets;
|
|||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -33,6 +34,7 @@ public class Table extends JPanel implements ITable {
|
|||
private StonePainter stonePainter = new StonePainter(1);
|
||||
|
||||
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
|
||||
private Collection<Stone> highlightedStones = Collections.emptyList();
|
||||
|
||||
private Event1<Position> clickEvent = new Event1<Position>();
|
||||
|
||||
|
@ -57,6 +59,12 @@ public class Table extends JPanel implements ITable {
|
|||
this.stoneSets = stoneSets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHighlightedStones(Collection<Stone> stones) {
|
||||
highlightedStones = stones;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent1<Position> getClickEvent() {
|
||||
return clickEvent;
|
||||
|
@ -97,9 +105,10 @@ public class Table extends JPanel implements ITable {
|
|||
|
||||
public void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) {
|
||||
float x = pos.getX();
|
||||
|
||||
for(Stone stone : stoneSet){
|
||||
stonePainter.paintStone(g, stone, new Position(x, pos.getY()), false);
|
||||
|
||||
for (Stone stone : stoneSet) {
|
||||
stonePainter.paintStone(g, stone, new Position(x, pos.getY()),
|
||||
highlightedStones.contains(stone));
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue