Question

Background: In this assignment, you will be implementing Word Guess, a variant of the game Hangman....

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Hi I need to make a hangman game for school task and it is no an...
Hi I need to make a hangman game for school task and it is no an ordinary game. It has to incorporate the pictures and everytime something wrong is guessed it has to clock over the pictures. The pictures are: hangman_pics = [''' +---+ | | | | | | =========''', ''' +---+ | | O | | | | =========''', ''' +---+ | | O | | | | | =========''', ''' +---+ | | O | /| |...