-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChessPiece.java
More file actions
104 lines (95 loc) · 2.23 KB
/
ChessPiece.java
File metadata and controls
104 lines (95 loc) · 2.23 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
public abstract class ChessPiece {
private Color color;
private int row1;
private int col1;
private int row2;
private int col2;
public ChessPiece(Color c){
color = c;
}
void Move(String mv)
{
String temp=mv.toUpperCase();
switch(temp.charAt(0))
{
case 'A':
row1=0;
break;
case 'B':
row1=1;
break;
case 'C':
row1=2;
break;
case 'D':
row1=3;
break;
case 'E':
row1=4;
break;
case 'F':
row1=5;
break;
case 'G':
row1=6;
break;
case 'H':
row1=7;
break;
default:
throw new IllegalArgumentException("Invalid Move! Please try again!");
}
col1=Character.getNumericValue(temp.charAt(1))-1;
switch(temp.charAt(2))
{
case 'A':
row2=0;
break;
case 'B':
row2=1;
break;
case 'C':
row2=2;
break;
case 'D':
row2=3;
break;
case 'E':
row2=4;
break;
case 'F':
row2=5;
break;
case 'G':
row2=6;
break;
case 'H':
row2=7;
break;
default:
throw new IllegalArgumentException("Invalid Move! Please try again!");
}
col2=Character.getNumericValue(temp.charAt(3))-1;
}
public int getRow1()
{
return row1;
}
public int getCol1()
{
return col1;
}
public int getRow2()
{
return row2;
}
public int getCol2()
{
return col2;
}
abstract boolean parseMove(String mv) throws Exception;
public Color getColor()
{
return color;
}
}