made the board for 4 connect
This commit is contained in:
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -5,6 +5,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/ATM-Machine/ATM-Machine.iml" filepath="$PROJECT_DIR$/ATM-Machine/ATM-Machine.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/BruitForce/BruitForce.iml" filepath="$PROJECT_DIR$/BruitForce/BruitForce.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/CodingChallanges/CodingChallanges.iml" filepath="$PROJECT_DIR$/CodingChallanges/CodingChallanges.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/ConnectFour/ConnectFour.iml" filepath="$PROJECT_DIR$/ConnectFour/ConnectFour.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/DemoProjects/DemoProjects.iml" filepath="$PROJECT_DIR$/DemoProjects/DemoProjects.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Doodles/Doodles.iml" filepath="$PROJECT_DIR$/Doodles/Doodles.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/ImageToText/ImageToText.iml" filepath="$PROJECT_DIR$/ImageToText/ImageToText.iml" />
|
||||
|
||||
11
ConnectFour/ConnectFour.iml
Normal file
11
ConnectFour/ConnectFour.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
ConnectFour/res/redChip.png
Normal file
BIN
ConnectFour/res/redChip.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
BIN
ConnectFour/res/yellowChip.png
Normal file
BIN
ConnectFour/res/yellowChip.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
42
ConnectFour/src/Board.java
Normal file
42
ConnectFour/src/Board.java
Normal file
@@ -0,0 +1,42 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class Board extends JPanel implements ActionListener {
|
||||
|
||||
private final int DELAY = 15;
|
||||
private final int BOARD_W = 700;
|
||||
private final int BOARD_H = 600;
|
||||
private boolean isInitialized = false;
|
||||
|
||||
private Painter painter;
|
||||
private Timer timer;
|
||||
|
||||
public Board(){
|
||||
initBoard();
|
||||
initGame();
|
||||
}
|
||||
|
||||
private void initBoard(){
|
||||
setPreferredSize(new Dimension(BOARD_W,BOARD_H));
|
||||
setBackground(Color.LIGHT_GRAY);
|
||||
}
|
||||
|
||||
private void initGame(){
|
||||
painter = new Painter();
|
||||
timer = new Timer(15, this);
|
||||
timer.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
painter.paintBoard(g, BOARD_W, BOARD_H);
|
||||
}
|
||||
}
|
||||
21
ConnectFour/src/Executor.java
Normal file
21
ConnectFour/src/Executor.java
Normal file
@@ -0,0 +1,21 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class Executor extends JFrame {
|
||||
|
||||
public Executor(){
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI(){
|
||||
Board board = new Board();
|
||||
add(board);
|
||||
pack();
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Executor executor = new Executor();
|
||||
executor.setVisible(true);
|
||||
}
|
||||
}
|
||||
2
ConnectFour/src/Game.java
Normal file
2
ConnectFour/src/Game.java
Normal file
@@ -0,0 +1,2 @@
|
||||
public class Game {
|
||||
}
|
||||
64
ConnectFour/src/Painter.java
Normal file
64
ConnectFour/src/Painter.java
Normal file
@@ -0,0 +1,64 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.ImageObserver;
|
||||
|
||||
public class Painter {
|
||||
|
||||
private int board_w, board_h, tileWidth, tileHeight;
|
||||
|
||||
public Painter(int width, int height){
|
||||
board_w = width;
|
||||
board_h = height;
|
||||
tileWidth = width/7;
|
||||
tileHeight = height/6;
|
||||
}
|
||||
|
||||
private Color holeBlue = new Color(61, 209, 165);
|
||||
|
||||
public void paintBoard(Graphics g){
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setStroke(new BasicStroke(2));
|
||||
for (int i = 0; i < board_w/tileWidth; i++){
|
||||
for (int j = 0; j < board_h/tileHeight; j++){
|
||||
g2d.setColor(holeBlue);
|
||||
g2d.fillOval(i * tileWidth + 10, j * tileHeight + 5, tileWidth - 15, tileHeight - 20);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(i * tileWidth+ 10 , j * tileHeight+5, tileWidth - 15, tileHeight - 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void paintYellowChip(Graphics g){
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g.drawImage(new redChip().getRedChip(), 0,0, g);
|
||||
}
|
||||
|
||||
class redChip{
|
||||
private ImageIcon imageIcon;
|
||||
private Image redChip;
|
||||
private String path = "../res/redChip.png";
|
||||
public redChip(){
|
||||
imageIcon = new ImageIcon(path);
|
||||
redChip = imageIcon.getImage().getScaledInstance(tileWidth, tileHeight, 0);
|
||||
}
|
||||
|
||||
public Image getRedChip() {
|
||||
return redChip;
|
||||
}
|
||||
}
|
||||
|
||||
class yellowChip{
|
||||
private ImageIcon imageIcon;
|
||||
private Image redChip;
|
||||
private String path = "../res/yellowChip.png";
|
||||
public yellowChip(){
|
||||
imageIcon = new ImageIcon(path);
|
||||
redChip = imageIcon.getImage().getScaledInstance(tileWidth, tileHeight, 0);
|
||||
}
|
||||
|
||||
public Image getRedChip() {
|
||||
return redChip;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
out/production/ConnectFour/Board.class
Normal file
BIN
out/production/ConnectFour/Board.class
Normal file
Binary file not shown.
BIN
out/production/ConnectFour/Executor.class
Normal file
BIN
out/production/ConnectFour/Executor.class
Normal file
Binary file not shown.
BIN
out/production/ConnectFour/Game.class
Normal file
BIN
out/production/ConnectFour/Game.class
Normal file
Binary file not shown.
BIN
out/production/ConnectFour/Painter.class
Normal file
BIN
out/production/ConnectFour/Painter.class
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user