-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.java
More file actions
62 lines (51 loc) · 1.67 KB
/
Copy pathSetup.java
File metadata and controls
62 lines (51 loc) · 1.67 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
import java.io.*;
import java.util.*;
public class Setup {
public static void main(String args[])throws FileNotFoundException
{
ChessBoard board = new ChessBoard();
readFile(board);
board.printBoard();
}
// reads files and calls functions from ChessBoard
public static void readFile(ChessBoard board) throws FileNotFoundException
{
Scanner scan = new Scanner(new File("input1.txt"));
System.out.println("\nReading file...\n");
String line;
String[] linePart;
boolean passedBlank = false;
boolean firstPrint = false;
while(scan.hasNextLine())
{
line = scan.nextLine();
linePart = line.split(" ");
String text = linePart[0];
int col = Integer.parseInt(linePart[1]);
int row = Integer.parseInt(linePart[2]);
// moving piece
if (text.equals("move"))
{
if (firstPrint == false)
{
firstPrint = true;
board.printBoard();
}
int newCol = Integer.parseInt(linePart[3]);
int newRow = Integer.parseInt(linePart[4]);
try
{
board.MovePiece(col, row, newCol, newRow);
}
catch (OutOfBoardException | IllegalChessMoveException ex)
{
System.out.println(ex.getMessage());
}
}
else // adding piece
{
board.addPiece(text, col, row);
}
}
}
}