created new look for GameBoard

This commit is contained in:
Dorian Zedler 2020-02-25 20:07:11 +01:00
parent d77963ccdb
commit 7235dc86d5
11 changed files with 38 additions and 26 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/withAnim/

BIN
graphics.xcf Normal file

Binary file not shown.

BIN
res/container.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
res/highlight.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
res/plateRed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
res/plateYellow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
res/test.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -325,7 +325,7 @@ public class ConnectFour extends JFrame implements ActionListener {
public void validate() { public void validate() {
// determine optimal size for board // determine optimal size for board
Dimension boardSize = new Dimension(); 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; boardSize.height = this.landscape() ? this.getSize().width : this.getSize().height;
// set board size // set board size

View file

@ -101,14 +101,18 @@ public class Plate {
* @return the color of the PlateType * @return the color of the PlateType
*/ */
public static Color getColor(PlateType type) { public static Color getColor(PlateType type) {
float[] hsb = new float[3];
switch (type) { switch (type) {
case O: case O:
return Color.BLACK; Color.RGBtoHSB(249, 227, 6, hsb);
break;
case X: case X:
return Color.RED; Color.RGBtoHSB(246, 33, 61, hsb);
default: break;
return Color.WHITE;
} }
return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
} }
} }

View file

@ -18,7 +18,8 @@
package de.itsblue.ConnectFour; package de.itsblue.ConnectFour;
import javax.swing.JPanel; import de.itsblue.ConnectFour.Plate.PlateType;
import java.awt.*; import java.awt.*;
/** /**
@ -29,7 +30,7 @@ import java.awt.*;
* *
* @author Dorian Zedler * @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 boolean highlighted = false;
private Image containerImg;
private Image plateRedImg;
private Image plateYellowImg;
private Image highlightImg;
/** /**
* Constructor * Constructor
*/ */
PlateContainer() { 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 the paint function to draw the shape of the plate
*/ */
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g1) {
if(g == null) if (g1 == null)
return; return;
Graphics2D g = (Graphics2D) g1;
// draw background // draw background
g.setColor(Color.lightGray); g.drawImage(containerImg, 0, 0, this.getWidth(), this.getHeight(), this);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
// set color according to contained plate // draw contained plate
if (this.containsPlate()) if (this.containsPlate()) {
g.setColor(this.containedPlate.getColor()); Image plateImage = this.getContainedPlate().getType().equals(PlateType.O) ? this.plateYellowImg
else : this.plateRedImg;
g.setColor(Color.white); g.drawImage(plateImage, -1, -1, this.getWidth() + 2, this.getHeight() + 2, this);
}
// 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 Highlight
if (this.highlighted) { if (this.highlighted) {
g.setColor(Color.green); g.drawImage(highlightImg, 0, 0, this.getWidth(), this.getHeight(), this);
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));
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB