Repository navigation
Expand file tree
/
Copy pathPawn.java
More file actions
62 lines (53 loc) · 1.53 KB
/
Copy pathPawn.java
File metadata and controls
62 lines (53 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Pawn extends Piece{
public Pawn( int x , int y , boolean isBlack){
super( isBlack );
this.X=x; this.Y=y;
}
@Override
public void drawYourself(Graphics g, int positionX, int positionY, int squareWidth) {
// TODO Auto-generated method stub
BufferedImage img=null;
try {
if( this.isBlack ) img=ImageIO.read(new File("images/BlackPawn.png"));
else img=ImageIO.read(new File("images/WhitePawn.png"));
} catch (IOException e){}
g.drawImage(img, positionX, positionY , null );
}
@Override
public boolean canMove(int x, int y) {
// TODO Auto-generated method stub
boolean ret=false;
int tempY=6;
if( this.isBlack ) tempY=1;
if( this.Y == tempY ){
if( isBlack && y == 2 && x == 0 && ChessFrame.pieces[this.X][this.Y+1]==null ) ret=true;
if( !isBlack && y == -2 && x == 0 && ChessFrame.pieces[this.X][this.Y-1]==null ) ret=true;
}
if( isBlack && y == 1 && x == 0) ret=true;
if( !isBlack && y == -1 && x == 0) ret=true;
return ret;
}
@Override
public boolean canCapture(int x, int y) {
// TODO Auto-generated method stub
if(isBlack){
if((x == -1 || x == 1) && y == 1) return true;
else return false;
}
else{
if((x == -1 || x == 1) && y == -1) return true;
else return false;
}
}
@Override
public String getName() {
// TODO Auto-generated method stub
if( super.isBlack ) return "black-pawn";
return "white-pawn";
}
}