commit a836469b8909837f0894a72a49e4703bb6f1cf3e Author: CT <4052244-CoolGuy27@users.noreply.replit.com> Date: Mon Apr 20 20:32:23 2026 +0000 Initial commit diff --git a/Chess.java b/Chess.java new file mode 100644 index 0000000..8369341 --- /dev/null +++ b/Chess.java @@ -0,0 +1,73 @@ +import java.util.ArrayList; +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; +import javax.swing.border.*; +import java.awt.Color; + + +public class Chess extends JPanel implements ActionListener{ + + //pieces stuff + ArrayList white; + ArrayList black; + + //game vars + int boardWidth, boardHeight; + boolean whiteTurn; + Timer gameTimer; + Color creme = new Color(254,245,218); + Color brown = new Color(121,92,50); + + public Chess(int boardWidth, int boardHeight){ + this.boardWidth = boardWidth; + this.boardHeight = boardHeight; + setPreferredSize(new Dimension(this.boardWidth, this.boardHeight)); + setBackground(Color.WHITE); + setFocusable(true); + + white = new ArrayList<>(); + black = new ArrayList<>(); + + for (int i =0 ; i <= 7; i++){ + white.add(new Pawn(i+1,2,"White")); + } + for (int i =0 ; i <= 7; i++){ + black.add(new Pawn(i+1,7,"Black")); + } + + gameTimer = new Timer(200,this); + + gameTimer.start(); + repaint(); + } + + public void gameLoop(){ + + } + + public void draw(Graphics g){ + + //draw board + for (int i = 1; i <= 8; i++){ + for (int j = 1; j<= 8; j++){ + g.setColor((i%2 == 1 && j%2 == 1 ) || (i%2==0 && j%2 == 0)? creme : brown); + g.fillRect(i * 40, j * 40, 40, 40); + } + } + + //draw pieces + for (Piece p : white) p.draw(g); + for (Piece p : black) p.draw(g); + } + + public void paintComponent(Graphics g){ + super.paintComponent(g); + draw(g); + } + + public void actionPerformed(ActionEvent e){ + gameLoop(); + repaint(); + } +} \ No newline at end of file diff --git a/Display.java b/Display.java new file mode 100644 index 0000000..c02317e --- /dev/null +++ b/Display.java @@ -0,0 +1,23 @@ +import javax.swing.*; + +public class Display { + public static void main(String[] args) throws Exception{ + //creating instance of JFrame + int boardWidth = 400; + int boardHeight = 400; + + JFrame game = new JFrame(); + game.setSize(boardWidth, boardHeight); + game.setVisible(true); + game.setLocationRelativeTo(null); + game.setResizable(false); + + Chess chess = new Chess(boardWidth, boardHeight); + game.add(chess); + game.pack(); + chess.requestFocus(); + } +} + + +//images : https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQN6qOyhiUDLlTlwl19PaMTeiY5rSOqkUqu-g&s \ No newline at end of file diff --git a/Pawn.java b/Pawn.java new file mode 100644 index 0000000..718b7e4 --- /dev/null +++ b/Pawn.java @@ -0,0 +1,10 @@ +import java.awt.*; +import javax.swing.ImageIcon; + +public class Pawn extends Piece{ + + + public Pawn(int x, int y,String color){ + super(x,y,new ImageIcon("Sprites/" + color + "/Pawn.png").getImage()); + } +} \ No newline at end of file diff --git a/Piece.java b/Piece.java new file mode 100644 index 0000000..e1fc13f --- /dev/null +++ b/Piece.java @@ -0,0 +1,18 @@ +import java.awt.*; +import java.util.*; + +public class Piece{ + ArrayList legalMoves; + int x,y; + Image sprite; + + public Piece(int x, int y, Image sprite){ + this.x = x; + this.y = y; + this.sprite = sprite; + } + + public void draw(Graphics g){ + g.drawImage(sprite,x * 40,y * 40,null); + } +} \ No newline at end of file