-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystem.java
More file actions
50 lines (50 loc) · 1.58 KB
/
Copy pathFileSystem.java
File metadata and controls
50 lines (50 loc) · 1.58 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
// Andrew Boles - ckj771
// FileSystem.java
import java.util.*;
import java.io.*;
public class FileSystem{
private String fileName; // file to be manipulated
private boolean inOrOut; // input = true, output = false
private Plateau plateau; // dynamic game plateau
private int turn; // white = 0, black = 1
// default constructor
public FileSystem(){}
// file name constructor
public FileSystem(String fileName, boolean inOrOut){
this.fileName = fileName;
this.inOrOut = inOrOut;
}
// get plateau
public Plateau getPlateau(){
return plateau;
}
// returns list of pieces in file
public void piecesInFile() throws IOException{
try{
if(true){ // outputting to file
DataOutputStream outputFile = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
outputFile.writeUTF(fileName); // write String fileName out to file first
outputFile.write(getPlateau().getTurn()); // write current turn to second line in file
ArrayList<Piece> pieces = getPlateau().getPieces(); // get current game pieces
//ListIterator<Player> playerIter = players.listIterator();
for(Piece p : pieces){ // iterate through pieces
if(p.getCouleur() == 0){ // output white rows, cols
outputFile.write(p.getLig());
outputFile.write(p.getCol());
}
}
for(Piece p : pieces){ // black piece loop
if(p.getCouleur() == 1){
outputFile.write(p.getLig());
outputFile.write(p.getCol());
}
}
outputFile.close();
} else {
// input file
}
} catch(Exception except){
//return null;
}
}
}