mirror of
https://github.com/lov3b/Schack.git
synced 2024-11-10 07:00:11 +01:00
changed a SCALE renamed a method removed unused var and optimized imports
This commit is contained in:
parent
7311bea07b
commit
45c58ec57d
@ -14,7 +14,7 @@ import javax.swing.JPanel;
|
||||
|
||||
public class Board extends JPanel {
|
||||
|
||||
public static final int SCALE = 100;
|
||||
public static final int SIZE_OF_TILE = 100;
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
|
||||
public Board() throws IOException {
|
||||
@ -50,9 +50,9 @@ public class Board extends JPanel {
|
||||
pieces.forEach(p -> p.draw(g2));
|
||||
|
||||
Piece p = pieces.get(1);
|
||||
LinkedHashSet<Point> legal = p.legalMoves(pieces);
|
||||
LinkedHashSet<Point> legal = p.validMoves(pieces);
|
||||
g2.setColor(Color.yellow);
|
||||
legal.forEach(point -> g2.fillOval(point.x * SCALE, point.y * SCALE, SCALE, SCALE));
|
||||
legal.forEach(point -> g2.fillOval(point.x * SIZE_OF_TILE, point.y * SIZE_OF_TILE, SIZE_OF_TILE, SIZE_OF_TILE));
|
||||
|
||||
System.out.println(legal.size());
|
||||
}
|
||||
@ -64,13 +64,13 @@ public class Board extends JPanel {
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
for (int j = 0; j < 8; j += 2) {
|
||||
g2.fillRect(i * SCALE, j * SCALE, 1 * SCALE, 1 * SCALE);
|
||||
g2.fillRect(i * SIZE_OF_TILE, j * SIZE_OF_TILE, 1 * SIZE_OF_TILE, 1 * SIZE_OF_TILE);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < 8; i += 2) {
|
||||
for (int j = 1; j < 8; j += 2) {
|
||||
g2.fillRect(i * SCALE, j * SCALE, 1 * SCALE, 1 * SCALE);
|
||||
g2.fillRect(i * SIZE_OF_TILE, j * SIZE_OF_TILE, 1 * SIZE_OF_TILE, 1 * SIZE_OF_TILE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public final class King extends Piece {
|
||||
@ -31,7 +30,7 @@ public final class King extends Piece {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedHashSet<Point> legalMoves(ArrayList<Piece> pieces) {
|
||||
public LinkedHashSet<Point> validMoves(ArrayList<Piece> pieces) {
|
||||
LinkedHashSet<Point> unmovable = new LinkedHashSet<>();
|
||||
LinkedHashSet<Point> perhapsMovable = new LinkedHashSet<>();
|
||||
for (Piece piece : pieces) {
|
||||
|
@ -20,11 +20,11 @@ public abstract class Piece extends Component {
|
||||
this.position = startingPosition;
|
||||
}
|
||||
|
||||
public abstract LinkedHashSet<Point> legalMoves(ArrayList<Piece> pieces);
|
||||
public abstract LinkedHashSet<Point> validMoves(ArrayList<Piece> pieces);
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
|
||||
g2.drawImage(icon, position.x * Board.SCALE, position.y * Board.SCALE, (ImageObserver) this);
|
||||
g2.drawImage(icon, position.x * Board.SIZE_OF_TILE, position.y * Board.SIZE_OF_TILE, (ImageObserver) this);
|
||||
// g2.drawImage(icon, 4 * Board.SCALE, 6* Board.SCALE, (ImageObserver) this);
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,6 @@ import javax.swing.JOptionPane;
|
||||
*/
|
||||
public class Schack extends JFrame {
|
||||
|
||||
public Dimension size = new Dimension(800, 800);
|
||||
|
||||
public Schack() throws IOException {
|
||||
setTitle("Schack");
|
||||
setAlwaysOnTop(true);
|
||||
|
Loading…
Reference in New Issue
Block a user