mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-03 22:50:24 +01:00 
			
		
		
		
	Ändra till en generisk toString()
Generisk toString() som är skriven i Piece vilket hämtar klassnamnet för den klass den är i
This commit is contained in:
		@@ -14,14 +14,10 @@ public class Bishop extends LongWalkers {
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public ArrayList<Point> validMoves(Piece[][] pieces, boolean isSelected) {
 | 
					    public ArrayList<Point> validMoves(Piece[][] pieces, boolean isSelected) {
 | 
				
			||||||
        return getMoves(
 | 
					        return getMoves(
 | 
				
			||||||
                new int[][]{{-1,-1},{1, 1}, {-1, 1}, {1, -1}},
 | 
					                new int[][]{{-1, -1}, {1, 1}, {-1, 1}, {1, -1}},
 | 
				
			||||||
                pieces,
 | 
					                pieces,
 | 
				
			||||||
                isSelected
 | 
					                isSelected
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String toString() {
 | 
					 | 
				
			||||||
        return "Bishop{" + "position=" + position + ", isWhite=" + white + '}';
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -99,7 +99,7 @@ public final class King extends PieceKnownIfMoved {
 | 
				
			|||||||
                if (loopY == 0 && loopX == 0) {
 | 
					                if (loopY == 0 && loopX == 0) {
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces,  isSelected);
 | 
					                addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces, isSelected);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -107,9 +107,4 @@ public final class King extends PieceKnownIfMoved {
 | 
				
			|||||||
        return movable;
 | 
					        return movable;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String toString() {
 | 
					 | 
				
			||||||
        return "Piece{" + "hasMoved=" + moved + "position=" + position + ", isWhite=" + white + '}';
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -107,8 +107,4 @@ public class Pawn extends PieceKnownIfMoved {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String toString() {
 | 
					 | 
				
			||||||
        return "Pawn{" + "position=" + position + ", isWhite=" + white + '}';
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -164,7 +164,8 @@ public abstract class Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public String toString() {
 | 
					    public String toString() {
 | 
				
			||||||
        return "Piece{" + "position=" + position + ", isWhite=" + white + '}';
 | 
					        return this.getClass().getSimpleName() + "{" + "position=" + position + ", isWhite=" + white + '}';
 | 
				
			||||||
 | 
					//        return "Piece{" + "position=" + position + ", isWhite=" + white + '}';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean isWhite() {
 | 
					    public boolean isWhite() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ public class Schack {
 | 
				
			|||||||
        // Set theme
 | 
					        // Set theme
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
//            FlatSolarizedLightIJTheme.setup();
 | 
					//            FlatSolarizedLightIJTheme.setup();
 | 
				
			||||||
            //FlatLightLaf.setup();
 | 
					//            FlatLightLaf.setup();
 | 
				
			||||||
            //embedMenuBarIfSupported();
 | 
					            //embedMenuBarIfSupported();
 | 
				
			||||||
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 | 
					            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 | 
				
			||||||
        } catch (Exception cantThemeWithFlatLaf) {
 | 
					        } catch (Exception cantThemeWithFlatLaf) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user