Skip to content

Commit 7b11fa9

Browse files
committed
Add a help command
1 parent 0ba3534 commit 7b11fa9

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

example.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,18 @@ class RockPaperScissors extends TextGame {
5151
}
5252
this.addLine("Choose your move:")
5353
}
54-
54+
55+
showHelp() {
56+
this.addLine(`You can choose from the following options:
57+
rock - select rock as your move
58+
paper - select paper as your move
59+
scissors - select scissors as your move
60+
clear - clear the screen
61+
help - show this screen again
62+
63+
You can also type the first letter of rock, paper, or scissors as a shorthand way of declaring a move.
64+
`);
65+
}
5566
playerWinsWhen(winCondition) {
5667
if(winCondition) {
5768
this.addLine("Player won!");
@@ -61,7 +72,7 @@ class RockPaperScissors extends TextGame {
6172
this.computerScore += 1;
6273
}
6374
}
64-
75+
6576
handleInput(input) {
6677
this.addLine(input);
6778
let playerChoice = input.toLowerCase();
@@ -72,11 +83,12 @@ class RockPaperScissors extends TextGame {
7283
}
7384

7485
if ( ! options.has(playerChoice) ) {
75-
76-
if (playerChoice === "clear") {
86+
if (playerChoice === "help" ) {
87+
this.showHelp();
88+
} else if (playerChoice === "clear") {
7789
this.clearLines();
7890
} else {
79-
this.addLine("'" + playerChoice + "' is not a valid move.");
91+
this.addLine("'" + playerChoice + "' is not a valid move. type 'help' to see available options.");
8092
}
8193

8294
} else {

0 commit comments

Comments
 (0)