mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-10-31 05:10:22 +01:00 
			
		
		
		
	shcakc no werk men man man får inte gå in i schackl
This commit is contained in:
		| @@ -10,6 +10,7 @@ import java.awt.event.MouseListener; | ||||
| import java.io.IOException; | ||||
| import java.util.Arrays; | ||||
| import java.util.LinkedHashSet; | ||||
| import javax.swing.JOptionPane; | ||||
| import javax.swing.JPanel; | ||||
|  | ||||
| public class Board extends JPanel implements MouseListener { | ||||
| @@ -150,8 +151,24 @@ public class Board extends JPanel implements MouseListener { | ||||
|                     } | ||||
|  | ||||
|                     LinkedHashSet validMoves = p.validMoves(pieces); | ||||
|  | ||||
|                     // Funkar | ||||
|                     if (p.supremeRuler) { | ||||
|                         validMoves.removeAll(turn ? blackAttacks : whiteAttacks); | ||||
|                     } | ||||
|                     // Funkar inte | ||||
|                     for (Point attack : turn ? whiteAttacks : blackAttacks) { | ||||
|                         Piece attacked = pieces[attack.x][attack.x]; | ||||
|                         if (attacked == null) { | ||||
|                             continue; | ||||
|                         } | ||||
|                         if (attacked.supremeRuler) { | ||||
|                             JOptionPane.showMessageDialog(this, "Du står i schack"); | ||||
|                         } | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     validMovesToDraw.addAll(validMoves); | ||||
|                     validMovesToDraw.addAll(blackAttacks); | ||||
|  | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|   | ||||
| @@ -10,6 +10,7 @@ public final class King extends PieceKnownIfMoved { | ||||
|     public King(boolean isWhite, Point startingPosition) throws IOException { | ||||
|         super(isWhite, startingPosition); | ||||
|         setPieceIcon("King"); | ||||
|         supremeRuler= true;                 | ||||
|     } | ||||
|  | ||||
|     public boolean isSeen(ArrayList<Piece> pieces) { | ||||
|   | ||||
| @@ -12,6 +12,8 @@ public abstract class Piece { | ||||
|  | ||||
|     public Point position; | ||||
|     public boolean white; | ||||
|     /** SPECIAL RULÖES APPLY TO THE KING, (ITS GOOD TO BE THE KING:)*/ | ||||
|     public boolean supremeRuler= false; | ||||
|     protected BufferedImage icon; | ||||
|  | ||||
|     public Piece(boolean white, Point startingPosition) throws IOException { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 loveb
					loveb