The inspiration for this challenge should be ridiculously obvious at the time of posting.
The Task
You must create a Shut the Box style program (not function, program). The basics of shut the box are:
Players attempt to shut the box by turning a set of levers labelled 1-9. They must do so by flipping levers. The sequence of events of each turn are as follows:
- The current position of the levers are shown.
- On a new game, the position of the levers should be displayed as
123456789
. - On a game with shut levers, all shut levers are displayed as
-
. For example, on a game that has 1, 5, and 9 shut, the output would be-234-678-
.
- On a new game, the position of the levers should be displayed as
- The di(c)e (is|are) rolled.
- If levers 7, 8, and 9 are all off, only one six-faced die is thrown. Otherwise, 2 six-faced dice are thrown.
- The player is prompted to choose how many levers they wish to flip.
- If the player chooses a number >9 or <0, the game ends.
- If the player chooses an already shut lever, the game ends.
- The player selects that many levers.
- If the sum of the levers does not equal the value of the di(c)e thrown, the game ends.
- If all the levers are shut, congratulations, you win. Otherwise, go back to step 1.
Rules for the Program
- On each turn, you should output the current positions of levers.
- You must output the value of the roll with the phrase
You rolled:
(note the space). - You must prompt (and wait) for the number of levers to switch with the phrase
How many levers to flip:
(note the space). - You must prompt (and wait) for as many levers as the player specified with the phrase
Which lever to flip:
(note the space). - You must flip the specified levers.
- If at any point the game ends, you must output
Game Over
. - If the player finishes a turn with no levers open, you must output
You win!
Example Games
123456789
You rolled: 5
How many levers to flip: 5
Which lever to flip: 1
Which lever to flip: 2
Which lever to flip: 3
Which lever to flip: 4
Which lever to flip: 5
Game Over
123456789
You rolled: 5
How many levers to flip: 3
Which lever to flip: 2
Which lever to flip: 2
Which lever to flip: 1
Game Over
123456789
You rolled: 12
How many levers to flip: 2
Which lever to flip: 3
Which lever to flip: 9
12-45678-
You rolled: 6
How many levers to flip: 2
Which lever to flip: 2
Which lever to flip: 4
1---5678-
You rolled: 11
How many levers to flip: 2
Which lever to flip: 5
Which lever to flip: 6
1-----78-
You rolled: 8
How many levers to flip: 1
Which lever to flip: 8
1-----7--
You rolled: 8
How many levers to flip: 2
Which lever to flip: 1
Which lever to flip: 7
---------
You win!