-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnect4Test.java
More file actions
43 lines (40 loc) · 1.49 KB
/
Connect4Test.java
File metadata and controls
43 lines (40 loc) · 1.49 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
import java.util.Scanner;
public class Connect4Test{
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
System.out.println("Welcome to Connect4!\n In this game, you must get four in a row to win\nGood Luck!");
Connect4 Connect = new Connect4();
while(true){
Connect.printArray();
System.out.println("What column would you like your chip in?(0-6)");
int need = kb.nextInt();
while (need>6){
System.out.println("That is an invalid column, or the column has already been filled. Please pick another");
need = kb.nextInt();
}
int lastChipRow = Connect.addchip(need, 1, Connect.getBoard());
while(lastChipRow == -1){
System.out.println("This is not a valid spot, pick another column");
int newc = kb.nextInt();
lastChipRow=Connect.addchip(newc,1,Connect.getBoard());
}
Connect.AIMove(need);
if(Connect.isFinished(1, lastChipRow, need, Connect.getBoard()) == true){ //if the player wins
Connect.printArray();
System.out.println("Yay! You won!");
break;
}
if(Connect.isFinished(2, Connect.getAIRow(), Connect.getAIColumn(), Connect.getBoard()) == true){ //if the CPU wins
Connect.printArray();
System.out.println("Oh no, the computer won!");
break;
}
if(Connect.isDraw()){
Connect.printArray();
System.out.println("It's a draw!");
break;
}
}
kb.close();
}
}