mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-03 22:50:24 +01:00 
			
		
		
		
	Fixa så att boden kan bli annan pjäs vid kanten (förlorade på det här)
This commit is contained in:
		@@ -41,12 +41,12 @@ public class Board extends JPanel implements MouseListener {
 | 
			
		||||
    private Piece[][] getPieces() throws IOException {
 | 
			
		||||
        Piece[][] piecesRet = {
 | 
			
		||||
            {new Rook(false, new Point(0, 0)), null, null, null, null, null, null, new Rook(true, new Point(0, 7))},
 | 
			
		||||
            {new Horse(false, true, new Point(1, 0)), null, null, null, null, null, null, new Horse(true, true, new Point(1, 7))},
 | 
			
		||||
            {new Horse(false, new Point(1, 0)), null, null, null, null, null, null, new Horse(true, new Point(1, 7))},
 | 
			
		||||
            {new Bishop(false, new Point(2, 0)), null, null, null, null, null, null, new Bishop(true, new Point(2, 7))},
 | 
			
		||||
            {new Queen(false, new Point(3, 0)), null, null, null, null, null, null, new Queen(true, new Point(3, 7))},
 | 
			
		||||
            {new King(false, new Point(4, 0)), null, null, null, null, null, null, new King(true, new Point(4, 7))},
 | 
			
		||||
            {new Bishop(false, new Point(5, 0)), null, null, null, null, null, null, new Bishop(true, new Point(5, 7))},
 | 
			
		||||
            {new Horse(false, true, new Point(6, 0)), null, null, null, null, null, null, new Horse(true, true, new Point(6, 7))},
 | 
			
		||||
            {new Horse(false, new Point(6, 0)), null, null, null, null, null, null, new Horse(true, new Point(6, 7))},
 | 
			
		||||
            {new Rook(false, new Point(7, 0)), null, null, null, null, null, null, new Rook(true, new Point(7, 7))}
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class Horse extends Piece {
 | 
			
		||||
 | 
			
		||||
    public Horse(boolean isWhite, boolean isLeft, Point startingPosition) throws IOException {
 | 
			
		||||
    public Horse(boolean isWhite, Point startingPosition) throws IOException {
 | 
			
		||||
        super(isWhite, startingPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,10 @@
 | 
			
		||||
package schack;
 | 
			
		||||
 | 
			
		||||
import java.awt.HeadlessException;
 | 
			
		||||
import java.awt.Point;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import javax.swing.JOptionPane;
 | 
			
		||||
 | 
			
		||||
public class Pawn extends Piece {
 | 
			
		||||
 | 
			
		||||
@@ -13,7 +15,7 @@ public class Pawn extends Piece {
 | 
			
		||||
    /**
 | 
			
		||||
     * Ger tillbaks alla ställen pjäsen kan attackera
 | 
			
		||||
     *
 | 
			
		||||
     * @param pieces 
 | 
			
		||||
     * @param pieces
 | 
			
		||||
     * @param shouldNotCareIfAttackSpaceIsEmptyOrNot Ifall man ska kolla ifall
 | 
			
		||||
     * det är något i möjliga attackrutor ifall
 | 
			
		||||
     * @return Alla lämpliga attackMoves
 | 
			
		||||
@@ -105,4 +107,46 @@ public class Pawn extends Piece {
 | 
			
		||||
        return true;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void move(Piece[][] pieces, Point toMove) {
 | 
			
		||||
        super.move(pieces, toMove);
 | 
			
		||||
 | 
			
		||||
        // Check if the pawn has moved to the end and should be transformed
 | 
			
		||||
        if (this.position.y == 0 && this.isWhite()
 | 
			
		||||
                || this.position.y == 7 && !this.isWhite()) {
 | 
			
		||||
            transform(pieces);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void transform(Piece[][] pieces) throws HeadlessException {
 | 
			
		||||
        String[] transformations = {"Queen", "Rook", "Bishop", "Horse"};
 | 
			
		||||
        int choosenTransformations = JOptionPane.showOptionDialog(null,
 | 
			
		||||
                "What do you want to transform into?",
 | 
			
		||||
                "Click a button",
 | 
			
		||||
                JOptionPane.DEFAULT_OPTION,
 | 
			
		||||
                JOptionPane.INFORMATION_MESSAGE,
 | 
			
		||||
                null,
 | 
			
		||||
                transformations,
 | 
			
		||||
                transformations[0]
 | 
			
		||||
        );
 | 
			
		||||
        try {
 | 
			
		||||
            switch (choosenTransformations) {
 | 
			
		||||
                case 0:
 | 
			
		||||
                    pieces[position.x][position.y] = new Queen(this.isWhite(), this.position);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 1:
 | 
			
		||||
                    pieces[position.x][position.y] = new Rook(this.isWhite(), this.position);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 2:
 | 
			
		||||
                    pieces[position.x][position.y] = new Bishop(this.isWhite(), this.position);
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    pieces[position.x][position.y] = new Horse(this.isWhite(), this.position);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        } catch (IOException ioe) {
 | 
			
		||||
            System.out.println(ioe);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user