A skeleton codebase for the Curling Animation project
// CurlingRock
package curling;
importjava.awt.Color;
importjava.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
publicclassCurlingRock {
finalpublicstaticintDEFAULT_DIAMETER = 10;
finalpublicstatic Color DEFAULT_COLOR = Color.GREEN;
/*
privateint x;
privateint y;
privateint diameter;
*/
Ellipse2D rockOutline;
private Color rockColor;
publicCurlingRock(intx, inty, intdiameter, Color rockColor) {
rockOutline = new Ellipse2D.Double(x, y, diameter, diameter);
this.rockColor = rockColor;
}
publicCurlingRock(intx, inty) {
this(x, y, DEFAULT_DIAMETER, DEFAULT_COLOR);
}
publicvoid move(intdx, intdy) {
//x += dx;
//y += dy;
rockOutline = new Ellipse2D.Double(rockOutline.getX() + dx,
rockOutline.getY() + dy, rockOutline.getWidth(),
rockOutline.getHeight());
}
publicvoid draw(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(rockColor);
g2d.fill(rockOutline);
g2d.setColor(Color.BLACK);
g2d.draw(rockOutline);
}
}
// CurlingRink
package curling;
importjava.awt.Color;
importjava.awt.Dimension;
importjava.awt.Graphics;
importjava.awt.Image;
importjavax.swing.ImageIcon;
importjavax.swing.JComponent;
publicclassCurlingRinkextendsJComponent {
private Image backgroungImg = null;
privateCurlingRockrock = null;
intinitialSpeed = 80;
publicCurlingRink() {
}
publicCurlingRink(Image img) {
backgroungImg = img;
Dimension d = newDimension(img.getWidth(null),
img.getHeight(null));
this.setMaximumSize(d);
this.setMinimumSize(d);
this.setPreferredSize(d);
}
publicvoidpaintComponent(Graphics g) {
Image img;
if (backgroungImg == null)
img = newImageIcon("image\\curling-court.png").getImage();
else
img = backgroungImg;
g.drawImage(img, 0, 0, null);
if (rock != null) {
Color tempColor = g.getColor();
rock.draw(g);
g.setColor(tempColor);
}
}
protectedvoidsetRock(CurlingRockrock) {
// TODO Auto-generated method stub
this.rock = rock;
}
voidmoveRock(intdx, intdy) {
rock.move(dx, dy);
}
}
// CurlingGameFrame
package curling;
importjavax.swing.ImageIcon;
importjavax.swing.JFrame;
publicclassCurlingGameFrameextendsJFrame {
privateCurlingRinkrink = newCurlingRink(
newImageIcon("image\\curling-court.png").getImage());
publicCurlingGameFrame() {
super("Curling Game");
add(rink);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setIconImage(newImageIcon("image/curling-icon.png").getImage());
rink.setRock(newCurlingRock(130, 65));
pack();
setVisible(true);
}
publicstaticvoid main(String[] args) {
newCurlingGameFrame();
}
}
Images that you can use
image/curling-court.png
image/curling-icon.png
image/PyeongChang-logo.png
You may add team pictures to make it fancy, …
Or even fancier.
Right on the bull’s eye!