Question
Background: In this assignment, you will be implementing Word Guess, a variant of the game Hangman. In this game, a word is first randomly chosen.
Background:
In this assignment, you will be implementing Word Guess, a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.
For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”.
Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the corresponding "_” are replaced with the letter. If the letter appears more than once in the secret word, then "_” is replaced with the letter for each instance. For example, if the player guesses the letter "l”, then the game's progress will be updated to "_ _ l l _ _”. The player has a finite number of guesses to guess all the letters in the randomly chosen word. This finite number of guesses depends upon the word to be guessed. Details will be given later (See Task 3). If the user correctly guesses all the letters in the secret word within the allotted number of guesses, they win. If the player uses up all their guesses before they correctly guess all the letters in the randomly chosen word, they lose.
Tasks to do:
In this assignment, there are four files: Node.py , SecretWord.py , WordGuess.py , and main.py . Node.py contains a Node class. SecretWord.py contains the LinkedList class and the SecretWord class. The SecretWord class represents the randomly chosen word that is being guessed in the Word Guess game. It contains an attribute self.linkedList which stores a LinkedList object. The LinkedList class is exactly the same as the Singly-Linked List class presented in the lecture and is composed of Node objects. WordGuess.py includes the WordGuess class, which contains the logic of the Word Guess game. Finally, main.py consists of the functions needed to run this game.
Task 1:
Your task will be to complete the Node class in Node.py . The Node class was modelled after the SLinkedListNode class presented in the lecture. The methods setData(element), setNext(reference), getData(), and getNext(), which make up the Node ADT, have already been written for you. Now write the following two additional methods:
- getDisplay(): Returns True if the letter stored in self.data should be displayed when the Word Guess game prints the current game progress. Returns False otherwise.
- setDisplay(newDisplay): Sets whether or not the letter being stored in self.data should be displayed when the Word Guess game prints the current game progress.
Note: You may need to introduce a new class attribute to implement these two methods
class Node:
def __init__(self, initData, initNext):
""" Constructs a new node and initializes it to contain
the given object (initData) and link to the given next node. """
self.data = initData
self.next = initNext
# Additional attributes
defgetData(self):
""" Returns the element """
return self.data
defgetNext(self):
""" Returns the next node """
return self.next
defgetDisplay(self):
#TODO
defsetData(self, newData):
""" Sets newData as the element """
self.data = newData
defsetNext(self, newNext):
""" Sets newNext as the next node """
self.next = newNext
defsetDisplay(self, newDisplay):
#TODO
Step by Step Solution
3.29 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
class Node def initself initData initNext Constructs a ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started