-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameController
More file actions
75 lines (66 loc) · 3.18 KB
/
GameController
File metadata and controls
75 lines (66 loc) · 3.18 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
package check;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class GameController {
public static String[] player = {"Player", "AI1", "AI2"};
public static void main(String[] args){
JFrame frame = new JFrame();
String name1 = JOptionPane.showInputDialog("Enater Player one's name: ");
String name2 = JOptionPane.showInputDialog("Enter Player two's name: ");
String Player1 = (String) JOptionPane.showInputDialog(frame,
"Player one",
"Player one",
JOptionPane.QUESTION_MESSAGE, null,player,player[0]);
String[] Array2 = new String[2];
int count = 0;
for(int i = 0; i < player.length; i++){
if (Player1 != player[i]){
Array2[count] = player[i];
count++;
}
}
String Player2 = (String) JOptionPane.showInputDialog(frame,
"Player two",
"Player two",
JOptionPane.QUESTION_MESSAGE, null,Array2,Array2[0]);
GUI checkers = new GUI(name1, name2);
}
public static boolean checkWonB(String isBlueP[][], String isWhiteP[][]){
for(int y = 0; y <8; y++){
for (int x = 0; x<8; x++){
if(isWhiteP[y][x] != ""){
if(isWhiteP[y][x] == "k" && y+1 < 8 && x+1 < 8 && isWhiteP[y+1][x+1] == "" && isBlueP[y+1][x+1] == ""
|| isWhiteP[y][x] == "k" && y+1 <8 && x-1 >= 0 && isBlueP[y+1][x-1] == "" && isWhiteP[y+1][x-1] == ""
|| y-1>= 0 && x-1>=0 && isWhiteP[y-1][x-1] == "" && isBlueP[y-1][x-1] == ""
|| y-1 >= 0 && x+1 <8 && isWhiteP[y-1][x+1] == "" && isBlueP[y-1][x+1] == ""
||(y - 2 >=0 && x - 2 >=0 && isBlueP[y-1][x-1] != "" && (isWhiteP[y-2][x-2] == "" && isBlueP[y-2][x-2] == "" ))
|| (y-2 >= 0 && x + 2 <8 && isBlueP[y-1][x+1] != "" && (isWhiteP[y-2][x+2] == "" && isBlueP[y-2][x+2] == ""))
|| isWhiteP[y][x] == "k" && y+2 < 8 && x+2 < 8 && isBlueP[y+1][x+1] != "" && (isWhiteP[y+2][x+2] == "" && isBlueP[y+2][x+2] == "")
|| isWhiteP[y][x] == "k" && y+2 < 8 && x-2 >= 0 && isBlueP[y+1][x-1] != "" && (isWhiteP[y+2][x-2] == "" && isBlueP[y+2][x-2] == "")){
return false;
}
}
}
}
return true;
}
public static boolean checkWonW(String isBlueP[][], String isWhiteP[][]){
for(int y = 0; y < 8; y++){
for (int x = 0; x<8; x++){
if(isBlueP[y][x] != ""){
if(isBlueP[y][x] == "k" && y-1 >= 0 && x-1 >= 0 && isWhiteP[y-1][x-1] == "" && isBlueP[y-1][x-1] == ""
||isBlueP[y][x] == "k" && y-1 >= 0 && x+1 < 8 && isWhiteP[y-1][x+1] == "" && isBlueP[y-1][x+1] == ""
||y+1 < 8 && x+1 < 8 && isWhiteP[y+1][x+1] == "" && isBlueP[y+1][x+1] == ""
||y+1 < 8 && x-1 >= 0 && isWhiteP[y+1][x-1] == "" && isBlueP[y+1][x-1] == ""
|| (y +2 < 8 && x + 2 < 8 && isWhiteP[y+1][x+1] != "" && (isWhiteP[y+2][x+2] == "" && isBlueP[y+2][x+2] == "" ))
|| (y+2 <8 && x-2 >= 0 && isWhiteP[y+1][x-1] != "" && (isWhiteP[y+2][x-2] == "" && isBlueP[y+2][x-2] == ""))
|| isBlueP[y][x] == "k" && y-2 >= 0 && x+2 < 8 && isWhiteP[y-1][x+1] != "" && (isWhiteP[y-2][x+2] == "" && isBlueP[y-2][x+2] == "")
|| isBlueP[y][x] == "k" && y-2 >= 0 && x-2 >= 0 && isWhiteP[y-1][x-1] != "" && (isWhiteP[y-2][x-2] == "" && isBlueP[y-2][x-2] == "")){
return false;
}
}
}
}
return true;
}
}