File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
dev_projects/TddPlayGround/src
main/java/com/yen/TddPlayGround/Connect4
test/java/com/yen/TddPlayGround/Connect4 Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ public class Connect4 {
20
20
21
21
private String [][] board = new String [ROWS ][COLUMNS ];
22
22
23
+ private static final String RED = "R" ;
24
+
25
+ private static final String GREEN = "G" ;
26
+
27
+ private String currentPlayer = RED ;
28
+
23
29
// private final int maxDiscsInColumn = 6;
24
30
// private int discNum;
25
31
@@ -30,6 +36,21 @@ public class Connect4 {
30
36
}
31
37
}
32
38
39
+
40
+ public String getCurrentPlayer (){
41
+
42
+ return this .currentPlayer ;
43
+ }
44
+
45
+ public void SwitchPlayer (){
46
+
47
+ if (RED .equals (this .currentPlayer )){
48
+ this .currentPlayer = GREEN ;
49
+ }else {
50
+ this .currentPlayer = RED ;
51
+ }
52
+ }
53
+
33
54
public int getNumberOfDiscs () {
34
55
35
56
//return this.discNum; //0;
@@ -53,7 +74,11 @@ public int putDiscInColumn(int column) {
53
74
this .checkPositionToInsert (row , column );
54
75
board [row ][column ] = "X" ;
55
76
System .out .println (">>> putDiscInColumn" );
56
- return column ; //row;
77
+
78
+ // switch player
79
+ SwitchPlayer ();
80
+
81
+ return column ; //row; // TODO : verify should return column or row
57
82
}
58
83
59
84
private void checkPositionToInsert (int row , int column ) {
Original file line number Diff line number Diff line change @@ -110,4 +110,21 @@ public void whenNoMoreRoomInColumnThenRuntimeException(){
110
110
System .out .println (exception );
111
111
}
112
112
113
+ // book p.96
114
+ @ Test
115
+ public void whenFirstPlayerPlaysThenDiscColorIsRed (){
116
+
117
+ Connect4 tested = new Connect4 ();
118
+ assertEquals (tested .getCurrentPlayer (), "R" );
119
+ }
120
+
121
+ @ Test
122
+ public void whenSecondPlayerPlaysThenDiscColorIsRed (){
123
+
124
+ Connect4 tested = new Connect4 ();
125
+ int column = 1 ;
126
+ tested .putDiscInColumn (column );
127
+ assertEquals (tested .getCurrentPlayer (), "G" );
128
+ }
129
+
113
130
}
You can’t perform that action at this time.
0 commit comments