-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
49 lines (39 loc) · 1.21 KB
/
Game.java
File metadata and controls
49 lines (39 loc) · 1.21 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
package models;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Game {
private Board board;
private List<Player> players;
private int availableMoves = 42;
public Game() {
this.board = new Board();
this.players = new ArrayList<Player>();
}
public void addPlayer(int id, String name) {
players.add(new Player(id, name));
}
public void printBoard() {
board.printBoard();
}
public void play() {
int chance = 0;
Scanner scan = new Scanner(System.in);
while (availableMoves > 0) {
board.printBoard();
final Player player = players.get(chance);
int id = player.getPlayerId();
System.out.println("Enter your column number: ");
int col = scan.nextInt();
col--;
int insertedRow = board.move(col, id);
if (insertedRow != -1 && board.checkWinner(insertedRow, col, id) == 1) {
System.out.println("Winner is player: " + player.getName());
return;
}
availableMoves--;
chance = 1-chance;
}
System.out.println("Draw!!");
}
}