formatting and compiling
This commit is contained in:
BIN
Chess.class
BIN
Chess.class
Binary file not shown.
51
Chess.java
51
Chess.java
@@ -1,25 +1,24 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import javax.swing.border.*;
|
|
||||||
import java.awt.Color;
|
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
|
||||||
|
|
||||||
//pieces stuff
|
|
||||||
ArrayList<Piece> white;
|
ArrayList<Piece> white;
|
||||||
ArrayList<Piece> black;
|
ArrayList<Piece> black;
|
||||||
|
|
||||||
//game vars
|
// game vars
|
||||||
int boardWidth, boardHeight;
|
int boardWidth, boardHeight;
|
||||||
boolean whiteTurn;
|
boolean whiteTurn;
|
||||||
Timer gameTimer;
|
Timer gameTimer;
|
||||||
Color creme = new Color(254,245,218);
|
Color creme = new Color(254, 245, 218);
|
||||||
Color brown = new Color(121,92,50);
|
Color brown = new Color(121, 92, 50);
|
||||||
|
|
||||||
public Chess(int boardWidth, int boardHeight){
|
public Chess(int boardWidth, int boardHeight) {
|
||||||
this.boardWidth = boardWidth;
|
this.boardWidth = boardWidth;
|
||||||
this.boardHeight = boardHeight;
|
this.boardHeight = boardHeight;
|
||||||
setPreferredSize(new Dimension(this.boardWidth, this.boardHeight));
|
setPreferredSize(new Dimension(this.boardWidth, this.boardHeight));
|
||||||
@@ -29,44 +28,42 @@ public class Chess extends JPanel implements ActionListener{
|
|||||||
white = new ArrayList<>();
|
white = new ArrayList<>();
|
||||||
black = new ArrayList<>();
|
black = new ArrayList<>();
|
||||||
|
|
||||||
for (int i =0 ; i <= 7; i++){
|
for (int i = 0; i <= 7; i++) {
|
||||||
white.add(new Pawn(i+1,2,"White"));
|
white.add(new Pawn(i + 1, 2, "White"));
|
||||||
}
|
}
|
||||||
for (int i =0 ; i <= 7; i++){
|
for (int i = 0; i <= 7; i++) {
|
||||||
black.add(new Pawn(i+1,7,"Black"));
|
black.add(new Pawn(i + 1, 7, "Black"));
|
||||||
}
|
}
|
||||||
|
|
||||||
gameTimer = new Timer(200,this);
|
gameTimer = new Timer(200, this);
|
||||||
|
|
||||||
gameTimer.start();
|
gameTimer.start();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameLoop(){
|
public void gameLoop() {}
|
||||||
|
|
||||||
}
|
public void draw(Graphics g) {
|
||||||
|
|
||||||
public void draw(Graphics g){
|
// draw board
|
||||||
|
for (int i = 1; i <= 8; i++) {
|
||||||
//draw board
|
for (int j = 1; j <= 8; j++) {
|
||||||
for (int i = 1; i <= 8; i++){
|
g.setColor((i % 2 == 1 && j % 2 == 1) || (i % 2 == 0 && j % 2 == 0) ? creme : brown);
|
||||||
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);
|
g.fillRect(i * 40, j * 40, 40, 40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw pieces
|
// draw pieces
|
||||||
for (Piece p : white) p.draw(g);
|
for (Piece p : white) p.draw(g);
|
||||||
for (Piece p : black) p.draw(g);
|
for (Piece p : black) p.draw(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g){
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
draw(g);
|
draw(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e) {
|
||||||
gameLoop();
|
gameLoop();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Display.class
BIN
Display.class
Binary file not shown.
@@ -1,12 +1,13 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Display {
|
public class Display {
|
||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args) throws Exception {
|
||||||
//creating instance of JFrame
|
// creating instance of JFrame
|
||||||
int boardWidth = 400;
|
int boardWidth = 400;
|
||||||
int boardHeight = 400;
|
int boardHeight = 400;
|
||||||
|
|
||||||
JFrame game = new JFrame();
|
JFrame game = new JFrame();
|
||||||
|
game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
game.setSize(boardWidth, boardHeight);
|
game.setSize(boardWidth, boardHeight);
|
||||||
game.setVisible(true);
|
game.setVisible(true);
|
||||||
game.setLocationRelativeTo(null);
|
game.setLocationRelativeTo(null);
|
||||||
@@ -19,5 +20,5 @@ public class Display {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// images :
|
||||||
//images : https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQN6qOyhiUDLlTlwl19PaMTeiY5rSOqkUqu-g&s
|
// https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQN6qOyhiUDLlTlwl19PaMTeiY5rSOqkUqu-g&s
|
||||||
|
|||||||
BIN
Pawn.class
BIN
Pawn.class
Binary file not shown.
@@ -1,10 +1,9 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Pawn extends Piece{
|
public class Pawn extends Piece {
|
||||||
|
|
||||||
|
public Pawn(int x, int y, String color) {
|
||||||
public Pawn(int x, int y,String color){
|
super(x, y, new ImageIcon("Sprites/" + color + "/pawn.png").getImage());
|
||||||
super(x,y,new ImageIcon("Sprites/" + color + "/Pawn.png").getImage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
Piece.java
10
Piece.java
@@ -1,18 +1,18 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Piece{
|
public class Piece {
|
||||||
ArrayList<Integer> legalMoves;
|
ArrayList<Integer> legalMoves;
|
||||||
int x,y;
|
int x, y;
|
||||||
Image sprite;
|
Image sprite;
|
||||||
|
|
||||||
public Piece(int x, int y, Image sprite){
|
public Piece(int x, int y, Image sprite) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.sprite = sprite;
|
this.sprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics g){
|
public void draw(Graphics g) {
|
||||||
g.drawImage(sprite,x * 40,y * 40,null);
|
g.drawImage(sprite, x * 40, y * 40, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user