-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit.java
More file actions
69 lines (61 loc) · 1.36 KB
/
Unit.java
File metadata and controls
69 lines (61 loc) · 1.36 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
package chessGame;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
public abstract class Unit {
String unitType;
int color; //0 == white, 1 == black
int value;
boolean captured;
ImageIcon img;
List<int[]> possibleMoves = new ArrayList<>();
Unit[][] units;
boolean isFirstTurn = true;
public void clearMoves() {
possibleMoves.clear();
}
//Creates the set of possible moves
public abstract void setAvailableMoves(int currentX, int currentY, int moveNum);
//Checks if the move is in the set of possible moves
public abstract boolean checkMove(int desiredX, int desiredY);
public abstract void setUnits(Unit[][] units);
protected boolean onBoard(int[] coordinates)
{
int x = coordinates[0];
int y = coordinates[1];
if (x >= 0 && x <= 7 && y >= 0 && y <= 7)
{
return true;
}
else
{
return false;
}
}
protected boolean isFirstMove(int moveNum)
{
if(moveNum == 0 || moveNum == 1)
{
return true;
}
else
{
return false;
}
}
protected void removeFriendlyMoves()
{
int [] moves;
for (int i = possibleMoves.size() - 1; i >= 0; --i)
{
moves = possibleMoves.get(i);
if (units[moves[1]][moves[0]] != null)
{
if (units[moves[1]][moves[0]].color == this.color)
{
possibleMoves.remove(i);
}
}
}
}
}