Lab 4: 30 pts
The main new components in this lab are discussed in Chapter 3’s section on singly linked lists and were reviewed in class.
IMPORTANT: This lab builds on Lab 3, so if you didn’t do it, then complete Lab 3 as a part of this lab, but see next comment on GRADING to understand how that works.
GRADING: I won’t be deducting points if you didn’t do parts of the Lab 3 piece correctly.
I will only be grading your implementation of the Linked List and how you use it and the player move count.
SUMMARY
Add to Lab 3 by tracking the player’s moves in a linked list. Then, before printing out the maze at the end, cycle through all the nodes of the linked list and change the cell value of each grid spot where the user has been to a number like 8 or 5 or 3 or any integer other than 0 or 1. This way the grid print out at the end will show the player’s path.
Secondly, track the number of moves the player makes and print that out at the end as well.
This lab will involve the following new features:
Singly Linked List
DETAILS
There won’t be as much detail on the singly linked list since we went over an implementation in class.
Classes and Adjustments to Lab 3.
Node – This is a new class that needs to be added to Lab 3.
Instance variables:
xPosition – int type.
yPosition – int type.
nextNode – Node type.
LinkedList – This class will hold the linked list.
Instance variables:
headNode – Node type.
Methods:
addHeadNode
Takes in two parameters, x and y, which are integer types.
Returns nothing.
With the x and y params, it creates a new node object and sets the nextNode on the new node object to the existing headNode object.
It then assigns this new node object to the headNode variable.
removeHeadNode
Takes in no parameters.
This is tricky so you need to carefully think through how to do this, but the following is what it needs to accomplish:
It needs to change the current head node to the node that is in the head node’s nextNode variable; and it needs to return that previous head node to the method caller.
Essentially, you’re taking the head node out of the linked list and returning it and setting the next node in line as the new head node.
Updating run method in GameGrid class.
You need to instantiate a LinkedList instance.
In the while loop, use the iUserRow and iUserCol values to call the addHeadNode method on the LinkedList instance to add a node for every user move.
Create second while loop: AFTER the existing while loop exits but BEFORE the grid print out.
This loop will run until all LinkedList nodes have been processed.
In the loop, call the removeHeadNode method on the LinkedList instance and use the returned node’s xPosition and yPosition to update the grid at that position with any number you choose besides 0 and 1.
You can also use this loop to count the number of player moves.
Print out the total number of player moves at the end when printing the grid.
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount! Use Discount Code “Newclient” for a 15% Discount!NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.
What Students Are Saying About Us
.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"
.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."