mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-04 07:00:21 +01:00 
			
		
		
		
	Horse funkar
This commit is contained in:
		@@ -13,7 +13,35 @@ public class Horse extends Piece {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
 | 
			
		||||
        return new LinkedHashSet<>();
 | 
			
		||||
        LinkedHashSet<Point> movable = new LinkedHashSet<>();
 | 
			
		||||
 | 
			
		||||
        // Postitioner att checka
 | 
			
		||||
        Point[] positions = {
 | 
			
		||||
            // Snett höger uppåt
 | 
			
		||||
            new Point(this.position.x + 1, this.position.y - 2),
 | 
			
		||||
            // Snett höger neråt
 | 
			
		||||
            new Point(this.position.x + 1, this.position.y + 2),
 | 
			
		||||
            // Långt höger åt sidan uppåt
 | 
			
		||||
            new Point(this.position.x + 2, this.position.y - 1),
 | 
			
		||||
            // Långt höger åt sidan neråt
 | 
			
		||||
            new Point(this.position.x + 2, this.position.y + 1),
 | 
			
		||||
            // Snett vänster uppåt
 | 
			
		||||
            new Point(this.position.x - 1, this.position.y - 2),
 | 
			
		||||
            // Snett vänster neråt
 | 
			
		||||
            new Point(this.position.x - 1, this.position.y + 2),
 | 
			
		||||
            // Långt vänster åt sidan uppåt
 | 
			
		||||
            new Point(this.position.x - 2, this.position.y - 1),
 | 
			
		||||
            // Långt vänster åt sidan neråt
 | 
			
		||||
            new Point(this.position.x - 2, this.position.y + 1)
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        for (Point pos : positions) {
 | 
			
		||||
            // Ifall en är blockerad så ska vi inte sluta kolla
 | 
			
		||||
            checkMove(pos.x, pos.y, movable, pieces);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return movable;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user