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
def getData(self):
""" Returns the element """
return self.data
def getNext(self):
""" Returns the next node """
return self.next
def getDisplay(self):
#TODO
def setData(self, newData):
""" Sets newData as the element """
self.data = newData
def setNext(self, newNext):
""" Sets newNext as the next node """
self.next = newNext
def setDisplay(self, newDisplay):
#TODO
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
self.display = False
def getData(self):
""" Returns the element """
return self.data
def getNext(self):
""" Returns the next node """
return self.next
def getDisplay(self):
return self.display:
def setData(self, newData):
""" Sets newData as the element """
self.data = newData
def setNext(self, newNext):
""" Sets newNext as the next node """
self.next = newNext
def setDisplay(self, newDisplay):
self.display = newDisplay
Get Answers For Free
Most questions answered within 1 hours.