-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathInputService.java
More file actions
43 lines (37 loc) · 1.28 KB
/
InputService.java
File metadata and controls
43 lines (37 loc) · 1.28 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
package Entities;
import java.util.Objects;
import java.util.Scanner;
public class InputService {
public InputService(){
}
public void startGame(){
ChessBoard chessgame = new ChessBoard();
Player player = new Player(true);
chessgame.showBoard();
boolean isGameRunning=true;
Scanner sc = new Scanner(System.in);
while(isGameRunning){
String start = sc.next();
if(Objects.equals(start, "exit")){
System.out.println("Game Over");
break;
}
String end = sc.next();
int startX = 8 - (start.charAt(1)-'0');
int startY = start.charAt(0)-'a';
int endX = 8 - (end.charAt(1)-'0');
int endY = end.charAt(0)-'a';
Peice p = chessgame.getPeice(startX,startY);
if(p!=null && player.isWhite()==p.isWhite() && p.isValidMove(chessgame,startX,startY,endX,endY)) {
chessgame.setPeice(endX, endY, p);
chessgame.setPeice(startX, startY, null);
chessgame.showBoard();
}else{
System.out.println("Invalid Move");
continue;
}
// change the player
player.switchPlayer();
}
}
}