Challenge: Solution Review
Understand how to implement the Adapter pattern to modify turn-taking logic in a JavaScript game class while maintaining a consistent interface, enabling you to adapt existing code effectively in structural design patterns.
We'll cover the following...
We'll cover the following...
Solution
Explanation
In the code above, we have a TruthAndDare class, which has a playGame function that decides which player’s turn it is, depending on the turn variable. The constructor initializes turn to either 1 or 2 randomly.
The turn variable is accessed through the Getturn function.
Getturn(){
if(this.turn == 1){
this.turn = 2
}else{
...