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() {
// 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

View file

@ -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]);
}
}

View file

@ -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);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB