Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Nov 15, 2023
1 parent f7ed97c commit 84e7e4b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public class Connect4 {

private String[][] board = new String[ROWS][COLUMNS];

private static final String RED = "R";

private static final String GREEN = "G";

private String currentPlayer = RED;

// private final int maxDiscsInColumn = 6;
// private int discNum;

Expand All @@ -30,6 +36,21 @@ public class Connect4 {
}
}


public String getCurrentPlayer(){

return this.currentPlayer;
}

public void SwitchPlayer(){

if (RED.equals(this.currentPlayer)){
this.currentPlayer = GREEN;
}else{
this.currentPlayer = RED;
}
}

public int getNumberOfDiscs() {

//return this.discNum; //0;
Expand All @@ -53,7 +74,11 @@ public int putDiscInColumn(int column) {
this.checkPositionToInsert(row, column);
board[row][column] = "X";
System.out.println(">>> putDiscInColumn");
return column; //row;

// switch player
SwitchPlayer();

return column; //row; // TODO : verify should return column or row
}

private void checkPositionToInsert(int row, int column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,21 @@ public void whenNoMoreRoomInColumnThenRuntimeException(){
System.out.println(exception);
}

// book p.96
@Test
public void whenFirstPlayerPlaysThenDiscColorIsRed(){

Connect4 tested = new Connect4();
assertEquals(tested.getCurrentPlayer(), "R");
}

@Test
public void whenSecondPlayerPlaysThenDiscColorIsRed(){

Connect4 tested = new Connect4();
int column = 1;
tested.putDiscInColumn(column);
assertEquals(tested.getCurrentPlayer(), "G");
}

}

0 comments on commit 84e7e4b

Please sign in to comment.