Bug 616

Summary: Want to implement state pattern for player module
Product: CS3343 Chinese Checker Reporter: yutongmen2-c
Component: Algorithm ComponentAssignee: yutongmen2-c
Status: CONFIRMED ---    
Severity: enhancement CC: yutongmen2-c
Priority: ---    
Version: unspecified   
Hardware: All   
OS: All   

Description yutongmen2-c 2021-11-29 10:33:03 HKT
Steps To Reproduce:

Add toString() method to the Player Interface



Actual Output:

Compilation Error



Expected Output:

Player 1 and 2 alternatively showed.
Comment 1 yutongmen2-c 2021-11-29 10:33:35 HKT
Previous code:

private static Player turnPlayer = (Player) new PlayerOne();

public static void addTurn(){

    	if(turnPlayer==PlayerOne()) {

    		turnPlayer = (Player) new PlayerTwo();

    	}

    	else if(turnPlayer==PlayerTwo()) {

    		turnPlayer = (Player) new PlayerOne();

    	}

        turn++;

}



Modified code:

private static Player turnPlayer = (Player) new PlayerOne();

 public static void addTurn(){

    	if(turnPlayer.toString()=="Player 1") {

    		turnPlayer = (Player) new PlayerTwo();

    	}

    	else if(turnPlayer.toString()=="Player 2") {

    		turnPlayer = (Player) new PlayerOne();

    	}

        turn++;

    }