-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeriodicChessManager.pde
More file actions
111 lines (99 loc) · 2.64 KB
/
PeriodicChessManager.pde
File metadata and controls
111 lines (99 loc) · 2.64 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
105
106
107
108
109
110
111
public class PeriodicChessManager
{
//PeriodicTableElements[][] table = new PeriodicTableElements[10][10];
TableSquare[][] tableS = new TableSquare[10][10];
PImage background;
TableSquare selectedPiece;
boolean[][] allowedMove = new boolean[10][10];
PeriodicChessManager(PImage bg)
{
this.background = bg;
}
public void DrawBackground()
{
image(background, 0, 0, width, height);
}
public void DrawTable()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
manager.tableS[i][j].DrawButton();
}
}
}
public void CheckButtons()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
manager.tableS[i][j].isInside(new PVector(mouseX, mouseY));
}
}
}
public void setPositionInTable(int y, int x, TableSquare piece)
{
tableS[y][x] = piece;
}
public void SelectPiece(TableSquare piece)
{
selectedPiece = piece;
allowedMove = HighLight(selectedPiece.element.PossibleMove());
}
public boolean[][] HighLight(boolean[][] pb)
{
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
if(pb[i][j])
{
tableS[i][j].isHighLight = true;
}
}
}
return pb;
}
public void MovePiece(int positionX, int positionY)
{
if(selectedPiece != null && allowedMove[positionY][positionX])
{
println(allowedMove[positionY][positionX]);
TableSquare s = tableS[positionY][positionX];
//println(s.element.playerOne);
//println(selectedPiece.element.playerOne);
if(s.element == null || s != selectedPiece && s.element.playerOne != selectedPiece.element.playerOne)
{
if(s.element != null && s.element.information.myType.elementsType() == 5)
{
gameEnd = true;
if(selectedPiece.element.playerOne){
textEnd = "Player One Won";
}else
{
textEnd = "Player Two Won";
}
}
s.element = selectedPiece.element;
s.element.positionX = positionX;
s.element.positionY = positionY;
selectedPiece.element = null;
}
playerTurnGame = !playerTurnGame;
}
DeselectPieces();
selectedPiece = null;
}
public void DeselectPieces()
{
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
tableS[i][j].isHighLight = false;
}
}
}
}