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.io.IOException; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.LinkedHashSet; | import java.util.LinkedHashSet; | ||||||
|  | import javax.swing.JOptionPane; | ||||||
| import javax.swing.JPanel; | import javax.swing.JPanel; | ||||||
|  |  | ||||||
| public class Board extends JPanel implements MouseListener { | public class Board extends JPanel implements MouseListener { | ||||||
| @@ -128,7 +129,7 @@ public class Board extends JPanel implements MouseListener { | |||||||
|                 Piece p = pieces[mouseCoordinateX][mouseCoordinateY]; |                 Piece p = pieces[mouseCoordinateX][mouseCoordinateY]; | ||||||
|  |  | ||||||
|                 // Kolla endast ifall vi kan röra på pjäsen om det är samma färg som den tur vi är på |                 // Kolla endast ifall vi kan röra på pjäsen om det är samma färg som den tur vi är på | ||||||
|                 if (p.isWhite() == turn||developerMode) { |                 if (p.isWhite() == turn || developerMode) { | ||||||
|  |  | ||||||
|                     LinkedHashSet<Point> blackAttacks = new LinkedHashSet<>(); |                     LinkedHashSet<Point> blackAttacks = new LinkedHashSet<>(); | ||||||
|                     LinkedHashSet<Point> whiteAttacks = new LinkedHashSet<>(); |                     LinkedHashSet<Point> whiteAttacks = new LinkedHashSet<>(); | ||||||
| @@ -150,8 +151,24 @@ public class Board extends JPanel implements MouseListener { | |||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     LinkedHashSet validMoves = p.validMoves(pieces); |                     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(validMoves); | ||||||
|                     validMovesToDraw.addAll(blackAttacks); |  | ||||||
|  |  | ||||||
|                 } |                 } | ||||||
|             } catch (Exception e) { |             } catch (Exception e) { | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ public final class King extends PieceKnownIfMoved { | |||||||
|     public King(boolean isWhite, Point startingPosition) throws IOException { |     public King(boolean isWhite, Point startingPosition) throws IOException { | ||||||
|         super(isWhite, startingPosition); |         super(isWhite, startingPosition); | ||||||
|         setPieceIcon("King"); |         setPieceIcon("King"); | ||||||
|  |         supremeRuler= true;                 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isSeen(ArrayList<Piece> pieces) { |     public boolean isSeen(ArrayList<Piece> pieces) { | ||||||
|   | |||||||
| @@ -12,6 +12,8 @@ public abstract class Piece { | |||||||
|  |  | ||||||
|     public Point position; |     public Point position; | ||||||
|     public boolean white; |     public boolean white; | ||||||
|  |     /** SPECIAL RULÖES APPLY TO THE KING, (ITS GOOD TO BE THE KING:)*/ | ||||||
|  |     public boolean supremeRuler= false; | ||||||
|     protected BufferedImage icon; |     protected BufferedImage icon; | ||||||
|  |  | ||||||
|     public Piece(boolean white, Point startingPosition) throws IOException { |     public Piece(boolean white, Point startingPosition) throws IOException { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 loveb
					loveb