Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Node - This is a new class that needs to be added to Lab 3.Instance variables: xPosition - int type. yPosition - int type. nextNode

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 the current 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.

--------------------------------------------------

ort java.security.SecureRandom; import java.util.Scanner; public class GameGrid1 { Scanner sc = new Scanner ( System.in ); static SecureRandom oRand = new SecureRandom (); static int iUserCol = 0; static int iUserRow = 0; public void run() { int[][] aiGrid = new int[10][10]; fillGrid ( aiGrid ); printGrid ( aiGrid ); fillSmartGrid ( aiGrid ); boolean z = true; while (z) { System.out.print ( " Enter (r)ight or (d)own: " ); char ch = Character.toLowerCase ( sc.next ().charAt ( 0 ) ); if (ch == 'r') { iUserCol++; } else if (ch == 'd') { iUserRow++; } else { System.out.println ( "invalid selection." ); } if (aiGrid[iUserRow][iUserCol] == 1) { System.out.println ( "You have failed to cross successfully." ); } if (iUserCol == 9 || iUserRow == 9) { System.out.println ( "you have successfully crossed." ); } } printGrid ( aiGrid ); } private static void fillGrid ( int[][] aiGrid){ SecureRandom oRand = new SecureRandom (); for (int y = 0; y < aiGrid.length; y++) { for (int x = 0; x < aiGrid[y].length; x++) { aiGrid[y][x] = oRand.nextInt ( 2 ); } } aiGrid[0][0] = 0; } private static void fillSmartGrid ( int[][] aiGrid) { int iWallChance = 30; int iTempNum; SecureRandom oRand = new SecureRandom (); for (int y = 0; y < aiGrid.length; y++) { for (int x = 0; x < aiGrid[y].length; x++) { iTempNum = oRand.nextInt ( 100 ); if (iTempNum < iWallChance) { aiGrid[y][x] = 1; } else { aiGrid[y][x] = 0; } } } } private static void printGrid ( int[][] aiGrid){ for (int y = 0; y < aiGrid.length; y++) { //Cols for (int x = 0; x < aiGrid[y].length; x++) { if (y == iUserRow && x == iUserCol) { System.out.print ( "X " ); } else { System.out.print ( aiGrid[x][y] + " " ); aiGrid[y][x] = oRand.nextInt ( 2 ); } }//End for X loop System.out.println (); }//End For Y loop }// End printGrid }//End Week3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

What does it mean to give legal advice?

Answered: 1 week ago

Question

4. How does social marketing differ from commercial marketing?

Answered: 1 week ago