mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-04 07:00:21 +01:00 
			
		
		
		
	move logging logic
This commit is contained in:
		
							
								
								
									
										24
									
								
								src/main/java/com/billenius/schack/MoveLogging/Move.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/main/java/com/billenius/schack/MoveLogging/Move.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
package com.billenius.schack.MoveLogging;
 | 
			
		||||
 | 
			
		||||
import java.awt.Point;
 | 
			
		||||
 | 
			
		||||
import com.billenius.schack.Piece;
 | 
			
		||||
 | 
			
		||||
public class Move {
 | 
			
		||||
    public Piece movedPiece;
 | 
			
		||||
    public Point from;
 | 
			
		||||
    public Point to;
 | 
			
		||||
    public String color;
 | 
			
		||||
 | 
			
		||||
    public Move(Piece movedPiece, Point from, Point to) {
 | 
			
		||||
        this.from = from;
 | 
			
		||||
        this.to = to;
 | 
			
		||||
        this.color = movedPiece.isWhite() ? "White" : "Black";
 | 
			
		||||
        this.movedPiece = movedPiece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return (from.x + 1) + ":" + (from.y + 1)
 | 
			
		||||
                + " " + '\u27F6' + " " + (to.x + 1) + ":" + (to.y + 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
package com.billenius.schack.MoveLogging;
 | 
			
		||||
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
import java.awt.image.BufferedImage;
 | 
			
		||||
 | 
			
		||||
import javax.swing.ImageIcon;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
import javax.swing.JList;
 | 
			
		||||
import javax.swing.ListCellRenderer;
 | 
			
		||||
 | 
			
		||||
public class PieceRenderer extends JLabel implements ListCellRenderer<Move> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Component getListCellRendererComponent(JList<? extends Move> list, Move move, int index,
 | 
			
		||||
            boolean isSelected,
 | 
			
		||||
            boolean cellHasFocus) {
 | 
			
		||||
        BufferedImage image = move.movedPiece.getIcon();
 | 
			
		||||
        ImageIcon ii = new ImageIcon(image.getScaledInstance(40, 40, java.awt.Image.SCALE_SMOOTH));
 | 
			
		||||
 | 
			
		||||
        setIcon(ii);
 | 
			
		||||
        setText(move.toString());
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user