mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-04 07:00:21 +01:00 
			
		
		
		
	bröt ut checkAttack
This commit is contained in:
		@@ -32,10 +32,18 @@ public class Pawn extends Piece {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Logik för att ta
 | 
					        // Kolla ifall vi kan ta någon
 | 
				
			||||||
        for (int pawnX : new int[]{-1, 1}) {
 | 
					        for (int pawnX : new int[]{-1, 1}) {
 | 
				
			||||||
            // Position vi kollar just nu, snett upp åt höger & vänster
 | 
					            // Position vi kollar just nu, snett upp åt höger & vänster
 | 
				
			||||||
            Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
 | 
					            Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
 | 
				
			||||||
 | 
					            checkAttack(pos, movable, pieces);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return movable;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Känns som det här skulle kunnat vara i validMoves, men nu är det såhär
 | 
				
			||||||
 | 
					    private void checkAttack(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
				
			||||||
        Piece p = pieces[pos.x][pos.y];
 | 
					        Piece p = pieces[pos.x][pos.y];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
 | 
					        // Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
 | 
				
			||||||
@@ -44,9 +52,6 @@ public class Pawn extends Piece {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return movable;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
					    protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
				
			||||||
        // Instead of checking index and null, try-catch
 | 
					        // Instead of checking index and null, try-catch
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user