-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSavedGameReader.java
More file actions
180 lines (161 loc) · 5.22 KB
/
Copy pathSavedGameReader.java
File metadata and controls
180 lines (161 loc) · 5.22 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
class SavedGameReader extends Player
{
Runnable Turn;
static BufferedReader br;
static boolean FILEREADpaused=false;
public SavedGameReader(Color c)
{
super(c,"");
try
{
setName(br.readLine());
}
catch(Exception e){}
renamable=false;
Turn=new Runnable()
{
public void run()
{
while(FILEREADpaused==true)
{
try
{
Thread.sleep(400);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
String flag=FileHandler.not_end;
try
{
String data=br.readLine();
if(data.equals(FileHandler.not_end) || data.equals(FileHandler.yes_end))
{
flag=data;
throw new Exception();
}
char c1=data.charAt(0);
int fx=(int)(c1-'a');
int fy=Integer.parseInt(data.charAt(1)+"")-1;
int c=2;
if(data.charAt(2)=='x')
c=3;
char c2=data.charAt(c);
int tx=(int)(c2-'a');
c++;
int ty=Integer.parseInt(data.charAt(c)+"")-1;
c++;
//System.out.println(data);
if(data.length()-1 ==c)
{
revival.setLength(0);
revival.append(""+data.charAt(c));
}
Point toMove=new Point(fx,fy);
Point moverA=new Point(tx,ty);
actualAction(toMove,moverA);
}
catch(Exception e)
{
e.printStackTrace();
if(flag.equals(FileHandler.not_end))
{
game.endGame("File ended","");
}
else
{
}
Environment.log("ending recorded play");
return;
}
}
};
}
@Override
public void playMove()
{
gui.gameEvents.execute(Turn);
}
public void endMove()
{
//no use here
}
public static JPanel getEntryMenu(JFrame container)
{
new Thread(()->{
connectFile();
}).start();
utility.GradientPanel f=new utility.GradientPanel();
JButton b=new JButton("Play last saved game");
b.setFont(new Font("",Font.PLAIN,28));
b.setFocusable(false);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Thread t=new utility.fadeout(container,false,false);
t.start();
//create 2 savedgamereader objects
SavedGameReader p1=new SavedGameReader(goti.colWhit);
SavedGameReader p2=new SavedGameReader(goti.colBlak);
//2 lines from the file have been read: the 3rd line is the perspective
Player[] players=new Player[2];
try {
String persp=br.readLine();
if(persp.equals("white"))
{
players[0]=p1;
players[1]=p2;
}
else
{
players[1]=p1;
players[0]=p2;
}
} catch (IOException ioException) {
ioException.printStackTrace();
}
new game(players,new Object[]{0,false});
}
});
f.add(b);
return f;
}
public JComponent getMouseEventCauser()
{
return this;
}
public static void connectFile()
{
try
{
FileReader fr=new FileReader("D:/chessAyush/chessgamerecording.txt");
br=new BufferedReader(fr);
}
catch (Exception fnfe)
{
Environment.log("File not found show a dialog box for it!!");
}
}
public void destroy()
{
try
{
br.close();
}
catch(Exception e)
{
}
}
@Override
public String getRevivalCandidate()
{
return revival.toString();
}
}