diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-04-30 15:05:01 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-04-30 15:05:01 +0200 |
commit | 3e6817388f5d0c7e687f0aa5f98a09607816a4f5 (patch) | |
tree | 3e2a311ba26d99a6bc161d9c3d98c0709b71cdf6 /src/jrummikub/view | |
parent | df2a40b16c722f6d8ccc783c24d3b6ca1e5d91c6 (diff) | |
download | JRummikub-3e6817388f5d0c7e687f0aa5f98a09607816a4f5.tar JRummikub-3e6817388f5d0c7e687f0aa5f98a09607816a4f5.zip |
Make stone list on Board settable
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@23 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r-- | src/jrummikub/view/IBoard.java | 8 | ||||
-rw-r--r-- | src/jrummikub/view/impl/Board.java | 23 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StonePainter.java | 33 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 12 |
4 files changed, 49 insertions, 27 deletions
diff --git a/src/jrummikub/view/IBoard.java b/src/jrummikub/view/IBoard.java index 7b9f70b..f363285 100644 --- a/src/jrummikub/view/IBoard.java +++ b/src/jrummikub/view/IBoard.java @@ -1,4 +1,10 @@ package jrummikub.view; +import java.util.Map; + +import jrummikub.model.Position; +import jrummikub.model.Stone; + public interface IBoard { -}
\ No newline at end of file + public void setStones(Map<Stone, Position> stones); +} diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java index 1d7cc1a..dc26dd4 100644 --- a/src/jrummikub/view/impl/Board.java +++ b/src/jrummikub/view/impl/Board.java @@ -3,18 +3,22 @@ package jrummikub.view.impl; import java.awt.Color; import java.awt.Graphics; import java.awt.Insets; +import java.util.Collections; +import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JPanel; +import jrummikub.model.Position; import jrummikub.model.Stone; -import jrummikub.model.StoneColor; import jrummikub.view.IBoard; @SuppressWarnings("serial") 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(); + Board() { super(true); @@ -34,14 +38,13 @@ public class Board extends JPanel implements IBoard { background.paintIcon(this, g, xpos, 75); } - // TODO Rest of painting code - - // FIXME Test code - StonePainter.paintStone(g, new Stone(1, StoneColor.ORANGE, false), - 0, 0, StonePainter.BOARD_SCALE); - StonePainter.paintStone(g, new Stone(10, StoneColor.BLUE, false), - 1, 0, StonePainter.BOARD_SCALE); - StonePainter.paintStone(g, new Stone(5, StoneColor.RED, false), - 0.5f, 1, StonePainter.BOARD_SCALE); + for (Map.Entry<Stone, Position> stone : stones.entrySet()) { + StonePainter.paintStone(g, stone.getKey(), stone.getValue(), StonePainter.BOARD_SCALE); + } + } + + @Override + public void setStones(Map<Stone, Position> stones) { + this.stones = stones; } } diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java index db3a477..e536e32 100644 --- a/src/jrummikub/view/impl/StonePainter.java +++ b/src/jrummikub/view/impl/StonePainter.java @@ -8,6 +8,7 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Rectangle2D; +import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.model.StoneColor; @@ -36,7 +37,7 @@ class StonePainter { return null; } - public static void paintStone(Graphics g, Stone stone, float x, float y, float scale) { + public static void paintStone(Graphics g, Stone stone, Position p, float scale) { if (g instanceof Graphics2D) { ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -45,33 +46,33 @@ class StonePainter { int width = (int)(DEFAULT_WIDTH*scale); int height = (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO); - int xpos = (int)(x*width); - int ypos = (int)(y*height); + int x = (int)(p.getX()*width); + int y = (int)(p.getY()*height); // Paint background g.setColor(BACKGROUND_COLOR); - g.fillRect(xpos, ypos, width, height); + g.fillRect(x, y, width, height); // Paint bevel border g.setColor(BACKGROUND_COLOR.brighter().brighter()); - g.fillRect(xpos, ypos, 1, height); + g.fillRect(x, y, 1, height); g.setColor(BACKGROUND_COLOR.brighter()); - g.fillRect(xpos+1, ypos+1, 1, height-2); + g.fillRect(x+1, y+1, 1, height-2); g.setColor(BACKGROUND_COLOR.brighter().brighter()); - g.fillRect(xpos, ypos, width, 1); + g.fillRect(x, y, width, 1); g.setColor(BACKGROUND_COLOR.brighter()); - g.fillRect(xpos+1, ypos+1, width-2, 1); + g.fillRect(x+1, y+1, width-2, 1); g.setColor(BACKGROUND_COLOR.darker().darker()); - g.fillRect(xpos+width-1, ypos, 1, height); + g.fillRect(x+width-1, y, 1, height); g.setColor(BACKGROUND_COLOR.darker()); - g.fillRect(xpos+width-2, ypos+1, 1, height-2); + g.fillRect(x+width-2, y+1, 1, height-2); g.setColor(BACKGROUND_COLOR.darker().darker()); - g.fillRect(xpos, ypos+height-1, width, 1); + g.fillRect(x, y+height-1, width, 1); g.setColor(BACKGROUND_COLOR.darker()); - g.fillRect(xpos+1, ypos+height-2, width-2, 1); + g.fillRect(x+1, y+height-2, width-2, 1); // Paint number g.setFont(new Font("SansSerif", Font.BOLD, height/4)); @@ -80,15 +81,15 @@ class StonePainter { Rectangle2D stringRect = fm.getStringBounds(value, g); g.setColor(getColor(stone.getColor()).darker()); - g.drawString(value, (int)(xpos+width/2-stringRect.getWidth()/2)+1, ypos+height/4+(fm.getAscent()-fm.getDescent())/2+1); + g.drawString(value, (int)(x+width/2-stringRect.getWidth()/2)+1, y+height/4+(fm.getAscent()-fm.getDescent())/2+1); g.setColor(getColor(stone.getColor())); - g.drawString(value, (int)(xpos+width/2-stringRect.getWidth()/2), ypos+height/4+(fm.getAscent()-fm.getDescent())/2); + g.drawString(value, (int)(x+width/2-stringRect.getWidth()/2), y+height/4+(fm.getAscent()-fm.getDescent())/2); // Paint circle g.setColor(BACKGROUND_COLOR.darker()); - g.drawArc((int)(xpos+width/2-width*CIRCLE_WIDTH/2), (int)(ypos+height*0.65f-width*CIRCLE_WIDTH/2), (int)(width*CIRCLE_WIDTH), (int)(width*CIRCLE_WIDTH), 50, 170); + g.drawArc((int)(x+width/2-width*CIRCLE_WIDTH/2), (int)(y+height*0.65f-width*CIRCLE_WIDTH/2), (int)(width*CIRCLE_WIDTH), (int)(width*CIRCLE_WIDTH), 50, 170); g.setColor(BACKGROUND_COLOR.brighter()); - g.drawArc((int)(xpos+width/2-width*CIRCLE_WIDTH/2), (int)(ypos+height*0.65f-width*CIRCLE_WIDTH/2), (int)(width*CIRCLE_WIDTH), (int)(width*CIRCLE_WIDTH), -130, 170); + g.drawArc((int)(x+width/2-width*CIRCLE_WIDTH/2), (int)(y+height*0.65f-width*CIRCLE_WIDTH/2), (int)(width*CIRCLE_WIDTH), (int)(width*CIRCLE_WIDTH), -130, 170); } } diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 5b0295c..7019977 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -3,10 +3,15 @@ package jrummikub.view.impl; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; +import java.util.HashMap; +import java.util.Map; import javax.swing.JFrame; import javax.swing.UIManager; +import jrummikub.model.Position; +import jrummikub.model.Stone; +import jrummikub.model.StoneColor; import jrummikub.util.IListener; import jrummikub.view.IPlayerPanel; import jrummikub.view.ITable; @@ -82,6 +87,13 @@ public class View extends JFrame implements IView { System.out.println("'End turn' fired"); }}); + Map<Stone, Position> stones = new HashMap<Stone, Position>(); + stones.put(new Stone(1, StoneColor.ORANGE, false), new Position(0, 0)); + stones.put(new Stone(1, StoneColor.BLUE, false), new Position(1, 0)); + stones.put(new Stone(1, StoneColor.RED, false), new Position(0.5f, 1)); + + view.getPlayerPanel().getBoard().setStones(stones); + view.setVisible(true); } } |