mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-03 22:50:24 +01:00 
			
		
		
		
	Lös problem där bönders attack inte registereas av kung
This commit is contained in:
		@@ -228,7 +228,7 @@ public class Board extends JPanel implements MouseListener {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                // Lägg till alla attacker för respektive färg
 | 
			
		||||
                attacks.addAll(piece.validAttacks(pieces));
 | 
			
		||||
                attacks.addAll(piece.validAttacks(pieces, true));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ public class Pawn extends PieceKnownIfMoved {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ArrayList<Point> validAttacks(Piece[][] pieces) {
 | 
			
		||||
    public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
 | 
			
		||||
        ArrayList<Point> movable = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        // Kolla ifall vi kan ta någon
 | 
			
		||||
@@ -22,7 +22,8 @@ public class Pawn extends PieceKnownIfMoved {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            Piece piece = pieces[pos.x][pos.y];
 | 
			
		||||
            if (piece == null || piece.isWhite() != piece.isWhite()) {
 | 
			
		||||
            if (piece == null || piece.isWhite() != this.isWhite()
 | 
			
		||||
                    || (shouldNotCareIfAttackSpaceIsEmptyOrNot && piece.isWhite() != this.isWhite())) {
 | 
			
		||||
                movable.add(pos);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -69,9 +69,10 @@ public abstract class Piece {
 | 
			
		||||
     * Ger tillbaks alla ställen pjäsen kan attackera
 | 
			
		||||
     *
 | 
			
		||||
     * @param pieces
 | 
			
		||||
     * @param shouldNotCareIfAttackSpaceIsEmptyOrNot Ifall man inte ska bry sig ifall 
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public ArrayList<Point> validAttacks(Piece[][] pieces) {
 | 
			
		||||
    public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
 | 
			
		||||
        return validMoves(pieces, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -110,6 +111,7 @@ public abstract class Piece {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Lägg till move ifall det går, alltså inte är schack där
 | 
			
		||||
     *
 | 
			
		||||
     * @param pos drag att lägga till ifall det går
 | 
			
		||||
     * @param movable lägger till drag i denna ArrayList<Point>
 | 
			
		||||
     * @param pieces Piece[][] över brädet
 | 
			
		||||
@@ -204,7 +206,7 @@ public abstract class Piece {
 | 
			
		||||
            for (Piece piece : pieceArr) {
 | 
			
		||||
                if (piece != null && piece.isWhite != this.isWhite()) {
 | 
			
		||||
                    // Lägg till alla attacker för mostståndaren
 | 
			
		||||
                    enemyAttacks.addAll(piece.validAttacks(pieces));
 | 
			
		||||
                    enemyAttacks.addAll(piece.validAttacks(pieces, false));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -226,7 +228,7 @@ public abstract class Piece {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     *
 | 
			
		||||
     * @return true ifall pjäsen är vit
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isWhite() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user