This challenge is an English twist on the Japanese word game Shiritori. The basic premise is to follow two rules:
Below is an example of a Shiritori game:
["word", "dowry", "yodel", "leader", "righteous", "serpent"] #valid!
["motive", "beach"] # invalid! - beach should start with "e"
["hive", "eh", "hive"] # invalid! - "hive" has already been said
Write a Shiritori class that has two instance variables:
and two instance methods:
play: a method that takes in a word as an argument and checks if it is valid (the word should follow rules #1 and #2 above).
restart: a method that sets the words list to an empty one [] and sets the game_over boolean to false. It should return "game restarted".
my_shiritori = Shiritori()
my_shiritori.play("apple") ➞ ["apple"]
my_shiritori.play("ear") ➞ ["apple", "ear"]
my_shiritori.play("rhino") ➞ ["apple", "ear", "rhino"]
my_shiritori.play("corn") ➞ "game over"
# Corn does not start with an "o".
my_shiritori.words ➞ ["apple", "ear", "rhino"]
# Words should be accessible.
my_shiritori.restart() ➞ "game restarted"
my_shiritori.words ➞ []
# Words list should be set back to empty.
my_shiritori.play("hostess") ➞ ["hostess"]
my_shiritori.play("stash") ➞ ["hostess", "stash"]
my_shiritori.play("hostess") ➞ "game over"
# Words cannot have already been said.