mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-10-31 13:20:21 +01:00 
			
		
		
		
	Lägg till debug samt ta bort schackmatt
This commit is contained in:
		| @@ -20,6 +20,7 @@ public class Board extends JPanel implements MouseListener { | |||||||
|     public static final int SIZE_OF_TILE = 100; |     public static final int SIZE_OF_TILE = 100; | ||||||
|     private Piece[][] pieces = new Piece[8][8]; |     private Piece[][] pieces = new Piece[8][8]; | ||||||
|     private LinkedHashSet<Point> validMovesToDraw = new LinkedHashSet<>(); |     private LinkedHashSet<Point> validMovesToDraw = new LinkedHashSet<>(); | ||||||
|  |     private LinkedHashSet<Point> validDebugMovesToDraw = new LinkedHashSet<>(); | ||||||
|     private Point selectedPiece = new Point(); |     private Point selectedPiece = new Point(); | ||||||
|     private Color moveableColor = new Color(255, 191, 0); |     private Color moveableColor = new Color(255, 191, 0); | ||||||
|     public static boolean turn = true; |     public static boolean turn = true; | ||||||
| @@ -63,6 +64,12 @@ public class Board extends JPanel implements MouseListener { | |||||||
|         Graphics2D g2 = (Graphics2D) g; |         Graphics2D g2 = (Graphics2D) g; | ||||||
|         drawSquares(g2); |         drawSquares(g2); | ||||||
|          |          | ||||||
|  |  | ||||||
|  |         validDebugMovesToDraw.stream().filter(point -> point != null).forEach(point -> { | ||||||
|  |             g2.setColor(Color.CYAN); | ||||||
|  |             g2.fillRect(point.x * SIZE_OF_TILE, point.y * SIZE_OF_TILE, SIZE_OF_TILE, SIZE_OF_TILE); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|         // måla alla ställen man kan gå¨till |         // måla alla ställen man kan gå¨till | ||||||
|         validMovesToDraw.forEach(point -> { |         validMovesToDraw.forEach(point -> { | ||||||
|             if (point != null) { |             if (point != null) { | ||||||
| @@ -77,6 +84,7 @@ public class Board extends JPanel implements MouseListener { | |||||||
|                 piece.draw(g2); |                 piece.draw(g2); | ||||||
|             } |             } | ||||||
|         })); |         })); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void drawSquares(Graphics2D g2) { |     private void drawSquares(Graphics2D g2) { | ||||||
| @@ -153,10 +161,11 @@ public class Board extends JPanel implements MouseListener { | |||||||
|  |  | ||||||
|                     // Funkar |                     // Funkar | ||||||
|                     if (selectedPiece.supremeRuler) { |                     if (selectedPiece.supremeRuler) { | ||||||
|                         validMoves.removeAll(attacks); |                         //validMoves.removeAll(attacks); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     allValidMoves.removeAll(attacks); |                     allValidMoves.removeAll(attacks); | ||||||
|  |                     validDebugMovesToDraw = allValidMoves; | ||||||
|                     boolean weCanMove = allValidMoves.size() > 0; |                     boolean weCanMove = allValidMoves.size() > 0; | ||||||
|  |  | ||||||
|                     boolean hasShowedMessageAboutSchack = false; |                     boolean hasShowedMessageAboutSchack = false; | ||||||
| @@ -165,8 +174,8 @@ public class Board extends JPanel implements MouseListener { | |||||||
|                     System.out.println("WeCanMo´vsadadade: " + weCanMove); |                     System.out.println("WeCanMo´vsadadade: " + weCanMove); | ||||||
|  |  | ||||||
|                     ArrayList<Point> opposingAttacks = checkAttacks(!turn); |                     ArrayList<Point> opposingAttacks = checkAttacks(!turn); | ||||||
|                     System.out.println("opposingAttacks: "+opposingAttacks); |                     System.out.println("opposingAttacks: " + opposingAttacks); | ||||||
|                     System.out.println("attacks: "+attacks); |                     System.out.println("attacks: " + attacks); | ||||||
|                     opposingAttacks.removeAll(allValidMoves); |                     opposingAttacks.removeAll(allValidMoves); | ||||||
|  |  | ||||||
|                     // Kollar ifall kungen står i schack just nu |                     // Kollar ifall kungen står i schack just nu | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 loveb
					loveb