diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64e11b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/withAnim/ diff --git a/graphics.xcf b/graphics.xcf new file mode 100644 index 0000000..7baa137 Binary files /dev/null and b/graphics.xcf differ diff --git a/res/container.png b/res/container.png new file mode 100644 index 0000000..108b673 Binary files /dev/null and b/res/container.png differ diff --git a/res/highlight.png b/res/highlight.png new file mode 100644 index 0000000..3952336 Binary files /dev/null and b/res/highlight.png differ diff --git a/res/plateRed.png b/res/plateRed.png new file mode 100644 index 0000000..450067b Binary files /dev/null and b/res/plateRed.png differ diff --git a/res/plateYellow.png b/res/plateYellow.png new file mode 100644 index 0000000..530b263 Binary files /dev/null and b/res/plateYellow.png differ diff --git a/res/test.png b/res/test.png new file mode 100755 index 0000000..6bd23fd Binary files /dev/null and b/res/test.png differ diff --git a/src/de/itsblue/ConnectFour/ConnectFour.java b/src/de/itsblue/ConnectFour/ConnectFour.java index a8df36d..9f65b1f 100644 --- a/src/de/itsblue/ConnectFour/ConnectFour.java +++ b/src/de/itsblue/ConnectFour/ConnectFour.java @@ -325,7 +325,7 @@ public class ConnectFour extends JFrame implements ActionListener { public void validate() { // determine optimal size for board Dimension boardSize = new Dimension(); - boardSize.width = this.landscape() ? this.getSize().height / 2 : this.getSize().width / 2; + boardSize.width = (int)(this.landscape() ? this.getSize().height * 0.7 : this.getSize().width * 0.7); boardSize.height = this.landscape() ? this.getSize().width : this.getSize().height; // set board size diff --git a/src/de/itsblue/ConnectFour/Plate.java b/src/de/itsblue/ConnectFour/Plate.java index b80a913..618a915 100644 --- a/src/de/itsblue/ConnectFour/Plate.java +++ b/src/de/itsblue/ConnectFour/Plate.java @@ -101,14 +101,18 @@ public class Plate { * @return the color of the PlateType */ public static Color getColor(PlateType type) { + + float[] hsb = new float[3]; switch (type) { case O: - return Color.BLACK; + Color.RGBtoHSB(249, 227, 6, hsb); + break; case X: - return Color.RED; - default: - return Color.WHITE; + Color.RGBtoHSB(246, 33, 61, hsb); + break; } + + return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } } \ No newline at end of file diff --git a/src/de/itsblue/ConnectFour/PlateContainer.java b/src/de/itsblue/ConnectFour/PlateContainer.java index ed42768..b57c37e 100644 --- a/src/de/itsblue/ConnectFour/PlateContainer.java +++ b/src/de/itsblue/ConnectFour/PlateContainer.java @@ -18,7 +18,8 @@ package de.itsblue.ConnectFour; -import javax.swing.JPanel; +import de.itsblue.ConnectFour.Plate.PlateType; + import java.awt.*; /** @@ -29,7 +30,7 @@ import java.awt.*; * * @author Dorian Zedler */ -public class PlateContainer extends JPanel { +public class PlateContainer extends Canvas { /** * @@ -46,10 +47,20 @@ public class PlateContainer extends JPanel { */ private boolean highlighted = false; + private Image containerImg; + private Image plateRedImg; + private Image plateYellowImg; + private Image highlightImg; + /** * Constructor */ PlateContainer() { + // initialize all images + containerImg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/res/container.png")); + plateRedImg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/res/plateRed.png")); + plateYellowImg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/res/plateYellow.png")); + highlightImg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/res/highlight.png")); } /** @@ -125,30 +136,26 @@ public class PlateContainer extends JPanel { * Override the paint function to draw the shape of the plate */ @Override - public void paint(Graphics g) { - if(g == null) + public void paint(Graphics g1) { + if (g1 == null) return; + + Graphics2D g = (Graphics2D) g1; + // draw background - g.setColor(Color.lightGray); - g.fillRect(0, 0, this.getWidth(), this.getHeight()); + g.drawImage(containerImg, 0, 0, this.getWidth(), this.getHeight(), this); - // set color according to contained plate - if (this.containsPlate()) - g.setColor(this.containedPlate.getColor()); - else - g.setColor(Color.white); - - // draw plate - g.fillOval((int) (this.getWidth() * 0.1), (int) (this.getHeight() * 0.1), (int) (this.getWidth() * 0.8), - (int) (this.getHeight() * 0.8)); + // draw contained plate + if (this.containsPlate()) { + Image plateImage = this.getContainedPlate().getType().equals(PlateType.O) ? this.plateYellowImg + : this.plateRedImg; + g.drawImage(plateImage, -1, -1, this.getWidth() + 2, this.getHeight() + 2, this); + } + // draw Highlight if (this.highlighted) { - g.setColor(Color.green); - Graphics2D g2 = (Graphics2D) g; - g2.setStroke(new BasicStroke((int) (this.getWidth() * 0.1))); - - g2.drawOval((int) (this.getWidth() * 0.1), (int) (this.getHeight() * 0.1), (int) (this.getWidth() * 0.8), - (int) (this.getHeight() * 0.8)); + g.drawImage(highlightImg, 0, 0, this.getWidth(), this.getHeight(), this); } } + } \ No newline at end of file diff --git a/src/de/itsblue/ConnectFour/res/test.png b/src/de/itsblue/ConnectFour/res/test.png new file mode 100755 index 0000000..6bd23fd Binary files /dev/null and b/src/de/itsblue/ConnectFour/res/test.png differ