-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect4.txt
169 lines (158 loc) · 4.5 KB
/
connect4.txt
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import java.util.Scanner;
import java.util.Arrays;
public class CONNECT4{
static String[][] board = new String [6][7];
static int yfill0=5;
static int yfill1=5;
static int yfill2=5;
static int yfill3=5;
static int yfill4=5;
static int yfill5=5;
static int yfill6=5;
public static void player1(){
System.out.println(Arrays.deepToString(board).replace("], ", "]\n").replace("[[", "[").replace("]]", "]"));
System.out.println("Player 1 (O), enter the row (1-7) of the spot you'd like to place your piece in");
Scanner move1=new Scanner(System.in);
int x1= move1.nextInt();
x1--;
if(yfill0==0||x1==0){
System.out.println("You can't go in the 1st column!");
player1();
}
if(yfill1==0||x1==1){
System.out.println("You can't go in the 2nd column!");
player1();
}
if(yfill2==0||x1==2){
System.out.println("You can't go in the 3rd column!");
player1();
}
if(yfill3==0||x1==3){
System.out.println("You can't go in the 4th column!");
player1();
}
if(yfill4==0||x1==4){
System.out.println("You can't go in the 5th column!");
player1();
}
if(yfill5==0||x1==5){
System.out.println("You can't go in the 6th column!");
player1();
}
if(yfill6==0||x1==6){
System.out.println("You can't go in the 7th column!");
player1();
}
if(x1==0){
board[yfill0][x1] = "O";
yfill0--;
}
if(x1==1){
board[yfill1][x1] = "O";
yfill1--;
}
if(x1==2){
board[yfill2][x1] = "O";
yfill2--;
}
if(x1==3){
board[yfill3][x1] = "O";
yfill3--;
}
if(x1==4){
board[yfill4][x1] = "O";
yfill4--;
}
if(x1==5){
board[yfill5][x1] = "O";
yfill5--;
}
if(x1==6){
board[yfill6][x1] = "O";
yfill6--;
}
System.out.println("\f");
player2();
}
public static void player2(){
System.out.println(Arrays.deepToString(board).replace("], ", "]\n").replace("[[", "[").replace("]]", "]"));
System.out.println("Player 2 (X), enter the row (1-6) of the spot you'd like to place your piece in");
Scanner move2=new Scanner(System.in);
int x2= move2.nextInt();
x2--;
if(yfill0==0||x2==0){
System.out.println("You can't go in the 1st column!");
player2();
}
if(yfill1==0||x2==1){
System.out.println("You can't go in the 2nd column!");
player2();
}
if(yfill2==0||x2==2){
System.out.println("You can't go in the 3rd column!");
player2();
}
if(yfill3==0||x2==3){
System.out.println("You can't go in the 4th column!");
player2();
}
if(yfill4==0||x2==4){
System.out.println("You can't go in the 5th column!");
player2();
}
if(yfill5==0||x1==5){
System.out.println("You can't go in the 6th column!");
player2();
}
if(yfill6==0||x2==6){
System.out.println("You can't go in the 7th column!");
player2();
}
if(x2==0){
board[yfill0][x2] = "X";
yfill0--;
}
if(x2==1){
board[yfill1][x2] = "X";
yfill1--;
}
if(x2==2){
board[yfill2][x2] = "X";
yfill2--;
}
if(x2==3){
board[yfill3][x2] = "X";
yfill3--;
}
if(x2==4){
board[yfill4][x2] = "X";
yfill4--;
}
if(x2==5){
board[yfill5][x2] = "X";
yfill5--;
}
if(x2==6){
board[yfill6][x2] = "X";
yfill6--;
}
System.out.println(Arrays.deepToString(board).replace("], ", "]\n").replace("[[", "[").replace("]]", "]"));
System.out.println("\f");
}
public static void main(String[] args){
System.out.println("Welcome to Arjan's CONNECT4 game! Rules can be ");
System.out.println("at wikipedia.org/wiki/Connect_Four/.");
System.out.println("");
System.out.println("Press 1 and hit enter to start...");
Scanner enterchecker = new Scanner(System.in);
String entercheck=enterchecker.next();
for(int y = 0; y < 7; y++){
for(int x=0; x<6;x++){
board[x][y] = " ";
}
}
if (entercheck.equals("1")){
player1();
}
}
}