From 94e437736433bc60f5edb98de7374da63722e588 Mon Sep 17 00:00:00 2001 From: Cool Guy <4052244-CoolGuy27@users.noreply.replit.com> Date: Tue, 21 Apr 2026 16:20:03 +0000 Subject: [PATCH] formatting and compiling --- Chess.class | Bin 2194 -> 2194 bytes Chess.java | 129 ++++++++++++++++++++++++-------------------------- Display.class | Bin 711 -> 764 bytes Display.java | 37 ++++++++------- Pawn.class | Bin 804 -> 804 bytes Pawn.java | 13 +++-- Piece.java | 30 ++++++------ 7 files changed, 103 insertions(+), 106 deletions(-) diff --git a/Chess.class b/Chess.class index 0a418374f1b7eec9b10ba11ce620d4963cb9b699..dfad50b7399bb3b7b568dcb45661ebe13068461a 100644 GIT binary patch delta 167 zcmWNLJq`h37=)h{)>2s;zajn-L1dFfg9HgHQEY@nBhf3B9Dqi*U+Dm%;sg?fLgggx z;H_q+cxJ{oeeaNyQKmAp5FlZ5zwk{oJ;^#Q5B<<;Op|8H-Lu5dRAyGzZVc6DKzD$I3(PRk% Foc_cn8w>yd delta 167 zcmWNLy$V5b9EP7Gj>F`13No?_w`KAe600Z3_lhLqLhf^h}B3kBE^g}OEPT8vL(k3o1^ed9z}th@J^AZlyAy> zsHm$x)T-*IzibzSIuRPQXfhR_nf>KiH EAJy6$Pyhe` diff --git a/Chess.java b/Chess.java index 8369341..46ee31e 100644 --- a/Chess.java +++ b/Chess.java @@ -1,73 +1,70 @@ -import java.util.ArrayList; import java.awt.*; -import javax.swing.*; -import java.awt.event.*; -import javax.swing.border.*; import java.awt.Color; +import java.awt.event.*; +import java.util.ArrayList; +import javax.swing.*; +import javax.swing.border.*; +public class Chess extends JPanel implements ActionListener { -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(); + // 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")); } - - public void gameLoop(){ - + for (int i = 0; i <= 7; i++) { + black.add(new Pawn(i + 1, 7, "Black")); } - - 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); + + 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); + } } - - public void paintComponent(Graphics g){ - super.paintComponent(g); - draw(g); - } - - public void actionPerformed(ActionEvent e){ - gameLoop(); - repaint(); - } -} \ No newline at end of file + + // 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(); + } +} diff --git a/Display.class b/Display.class index 73014439adc3fe77396308b4440c6d792fd402ae..2cb4db04b053f5ed66b7f85b39652ee8c28ee8e8 100644 GIT binary patch delta 406 zcmWlVO-mb56o#K`CNpMwt0pmNY+@U&Us139(4ra4YmT744bDIh>F8Jm=nXpZu5f|32K@0iUUb{@!vSu)Qz#sM+uIHap$G z?wr`OX0P4-rEr$MR=)XojB6%Hhd=UeRx?R1yePQOGzF%@-?fdRrbJGmg|usf_IdN5 zV?ACdlAFgi2z;g~Ym%g6)~x0ga|1`cuPkU5ab?d*v-LApRW!?SL7&;vz72YfZmS=7 ztPT#tY{o@%D$L zwv8L%n_?+q%s3GlqayMq5%K(%>HT79$jc9onUdDbcM~xmM@xT%q=)?Og=L~l{9rSd?L%19Ph1+IRbenwjuEd)&KTOLLvYF delta 408 zcmYLEOG^S#6#lNxI5}PORhEsGJuJ0unN&s(D1yLE3j@n&V=~ZC(BtaHO{@0G{E{{! zB(yB(Z}c}JI=2=r&hz`uch33J-*xlj`{fnD0ZKjdY|D^#>%{5U40^6o$=6I62y;Xb zWiSb=InuejAy~_u|Dkb?QH=H8HrK~FCKQhouWC!D(;%jSNzyvJvZXYUM2bU4NU2V7 zOe5nKSvfz;F^2$Y-Zh%nik0P9P!0ZI-?weqI=XGPrGcE=WmUH7ezJ|nMfm7ykSBQr z$mgj_Q)CqNLLcmz5{3eK1p|Hrv4mwBQPd}BG)Rv}S$CIgZvdm-NAOr!DG#R5Jd6nD zAtwAD5(6abR;mwcTN6owF4CvM!;DJj|M!%@f46D$-w>!4H#35)xqx)9Kij@1X_5+raJthDE diff --git a/Display.java b/Display.java index c02317e..fc7b48e 100644 --- a/Display.java +++ b/Display.java @@ -1,23 +1,24 @@ 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(); - } + public static void main(String[] args) throws Exception { + // creating instance of JFrame + int boardWidth = 400; + int boardHeight = 400; + + JFrame game = new JFrame(); + game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + 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 +// images : +// https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQN6qOyhiUDLlTlwl19PaMTeiY5rSOqkUqu-g&s diff --git a/Pawn.class b/Pawn.class index c2d667e58b2ad5b84715d6252b45662cb5446db2..4ac6511dc540de4fc2ac8314e2a3c0ecb6d1ffa3 100644 GIT binary patch delta 24 fcmZ3&wuEg%E+b>X<~+tuMpkwPF$Rvwf0#4?SvCf9 delta 24 fcmZ3&wuEg%E+b>W<~+tuMph06F$T`bf0#4?S40L? diff --git a/Pawn.java b/Pawn.java index 718b7e4..31d309a 100644 --- a/Pawn.java +++ b/Pawn.java @@ -1,10 +1,9 @@ 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 +public class Pawn extends Piece { + + public Pawn(int x, int y, String color) { + super(x, y, new ImageIcon("Sprites/" + color + "/pawn.png").getImage()); + } +} diff --git a/Piece.java b/Piece.java index e1fc13f..1cd1439 100644 --- a/Piece.java +++ b/Piece.java @@ -1,18 +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 +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); + } +}