-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
137 lines (100 loc) · 2.86 KB
/
Main.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
public static void main(String args[]) throws Exception
{
Scanner scan=new Scanner(System.in);
Player white_player=new Player("white");
Player black_player=new Player("black");
System.out.println("Enter 1-continue the previous game");
System.out.println(" 2-start a new game");
int choice=scan.nextInt();
int chance=0;
int ch=0;
if(choice==1)
{
FileInputStream fin=new FileInputStream("aditya.txt"); // to continue with the previous game
ObjectInputStream ois=new ObjectInputStream(fin);
chance=ois.readInt();
white_player=(Player)ois.readObject();
black_player=(Player)ois.readObject();
Board.piece=(Piece[][])ois.readObject();
ois.close();
}
while(ch!=2)
{
if(chance<=1)
{
System.out.println("Enter 1 - print and continue");
System.out.println("Enter any other number - save & exit");
System.out.println("Enter ur choice");
ch=scan.nextInt();
if(ch==1)
{
print();
}
else if(ch==2)
{
FileOutputStream fos=new FileOutputStream("aditya.txt"); // if want to save the game and play again in the future
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeInt(1);
oos.writeObject(white_player);
oos.writeObject(black_player);
oos.writeObject(Board.piece);
oos.close();
System.exit(0);
}
else
{
System.exit(0);
}
white_player.chance();
if(black_player.kingcheck())
{
System.out.println("the black_player king has a check");
if(!black_player.posible())
{
System.out.println("the black_player king cannot make a move ");
}
else
{
System.out.println("the black_player king has a move to make");
}
}
chance--;
}
if(chance<=2)
{
System.out.println("Enter 1 - print and continue");
System.out.println("Enter any other number - save & exit");
System.out.println("Enter ur choice");
ch=scan.nextInt();
if(ch==1)
{
print();
}
else if(ch==2)
{
FileOutputStream fos=new FileOutputStream("aditya.txt");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeInt(1);
oos.writeObject(white_player);
oos.writeObject(black_player);
oos.writeObject(Board.piece);
oos.close();
System.exit(0);
}
black_player.chance();
if(white_player.kingcheck())
{
System.out.println("the white_player king is in check");
if(!white_player.posible())
{
System.out.println("the white_player king cannot make a move ");
}
else
{
System.out.println("the white_player king has a make to move");
}
}
chance--;
}
}
}