-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckers.java
116 lines (105 loc) · 2.85 KB
/
Checkers.java
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
112
113
114
115
116
package com.gdxtemplate.game;
import com.badlogic.gdx.*;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.GL20;
public class Checkers extends ApplicationAdapter {
ShapeRenderer sr;
CheckerPiecesSuperclass ChPiSu = new CheckerPiecesSuperclass();
Highlighting HiLi = new Highlighting();
Move Mo = new Move();
private static int piece = 0;
private int state = 0;
private int gameEndA = 0;
private int gameEndB = 0;
@Override
public void create () {
sr = new ShapeRenderer();
ChPiSu.createArray();
}
@Override
public void render () {
gameEndA = 0;
gameEndB = 0;
Gdx.gl.glClearColor(1,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
int[][] a = ChPiSu.ArrayA();
int[][] b = ChPiSu.ArrayB();
for(int i = 0; i < 12 ;i++) {
if (a[i][4] != 3) {
gameEndA = 1;
}
}
for(int i = 0; i < 12 ;i++) {
if (b[i][4] != 3) {
gameEndB = 1;
}
}
if(gameEndA == 0) {
System.out.println("Player 2 wins");
}
if(gameEndB == 0) {
System.out.println("Player wins");
}
if (gameEndA != 0 || gameEndB != 0) {
RenderCheckers Render = new RenderCheckers();
RenderPieces RenderPieces = new RenderPieces();
Render.render(sr);
HiLi.highlight(sr);
if (Mo.Turn() % 2 == 0) {
for(int i = 0; i < 12; i++) {
if (a[i][2] == HiLi.GetX() && a[i][3] == HiLi.GetY()) {
piece = a[i][1];
state = a[i][4];
}
}
}
if(Mo.Turn() % 2 == 1) {
for(int i = 0; i < 12; i++) {
if (b[i][2] == HiLi.GetX() && b[i][3] == HiLi.GetY()) {
piece = b[i][1];
state = b[i][4];
}
}
}
if (Mo.Turn() % 2 == 0) {
HiLi.MovesA(sr, state);
if (Gdx.input.isKeyJustPressed(Keys.Q)) {
Mo.AMoveLeftForward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
if(Gdx.input.isKeyJustPressed(Keys.E)) {
Mo.AMoveRightForward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
if (state == 1) {
if(Gdx.input.isKeyJustPressed(Keys.Z)) {
Mo.AMoveRightBackward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
if(Gdx.input.isKeyJustPressed(Keys.C)) {
Mo.AMoveLeftBackward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
}
}
else {
HiLi.MovesB(sr, state);
if (Gdx.input.isKeyJustPressed(Keys.NUMPAD_1)) {
Mo.BMoveLeftForward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
if(Gdx.input.isKeyJustPressed(Keys.NUMPAD_3)) {
Mo.BMoveRightForward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
if (state == 1) {
if(Gdx.input.isKeyJustPressed(Keys.NUMPAD_9)) {
Mo.BMoveRightBackward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
if(Gdx.input.isKeyJustPressed(Keys.NUMPAD_7)) {
Mo.BMoveLeftBackward(ChPiSu.ArrayA(),ChPiSu.ArrayB(), piece);
}
}
}
RenderPieces.render(100, 100, sr, ChPiSu);
}
}
@Override
public void dispose () {
}
}