Build an app that randomly creates a 10 by 10 grid

Assignment Help Computer Engineering
Reference no: EM133382871

SUMMARY

Build an app that randomly creates a 10 by 10 grid of 0s and 1s where the 0s represent open spaces and 1s represent blocked spaces (like we did in class), and then see if user can navigate from position 0,0 to where either the first index or second index equal 9 w/o hitting a 1. In other words the user must move clear across the grid without hitting a 1 or the game is over.

This lab will involve the following new features:
java.util.SecureRandom class
Two-dimensional arrays

DETAILS

There won't be as much detail on the grid creation part of this as we already created an example of the grid in class together.

Classes

GameGrid_Test
Will have main method and will instantiate instance of GameGrid and call run... that's it.

GameGrid
This will have one public "run" method and this will be called by the GameGrid_Test class's main method. ALL CODE can be in the "run" method.
Create game grid: This method will create a game grid (two-dimensional int array) and fill each cell with 1 or 0 randomly using the Random class.
There should be a LESS CHANCE to have a 1 fill the spot than a 0.

Reminder Tip:
Set an int variable called iWallChance to a number like 30, and then use the bound parameter of the SecureRandom class's nextInt method to control the range of possible numbers just like we did in class.
Then you'd compare the returned random number to see if it's less than your iWallChance variable.
If it was less, you'd set that cell to 1... if not, then the cell would be set to 0.
Change the location [0][0] of the grid to 0 so that the first space is open and not a wall because that's where we'll start our user.
Create two int variables for the user's position... iUserRow and iUserCol... and set each to 0.
Create a boolean variable for the following loop to know when to exit.
Create while loop for moving: This loop will keep asking user whether to move down or to the right.
If the user chooses down, then that will affect the first array value (row); and if the user chooses right, that will affect the second array value.

With each user answer, adjust the iUserRow or iUserCol positions depending whether down or right by increasing the correct variable by 1.
Check if this new user position is a 1 in the grid. If it's a 1, tell the user they failed and exit loop.
If it was not a 1, then check if either user position is now a 9.
If one of them is 9, they have reached either the right side or bottom and tell them they have won and exit loop.
After loop is over, then print out the grid as we did in class (nested for loop (which is a for loop within a for loop)).
With each cell, before you print out 0 or 1, check if that cell (x and y) equals the user position (iUserRow and iUserCol).
If it does, print out a capital X in that spot.

Otherwise, simply print out the value of that spot in the array.

Printing tip: Remember in class that we used System.out.print... within the inner for loop for printing so no line break was done. Then use System.out.println(""); after the closing curly bracket of the inner for loop but before the closing curly bracket of the outer for loop. That way each row will be printed out on a separate line for a nice readable layout.

Lab: "MERKLE MADNESS"

SUMMARY

Build an app that randomly creates a 10 by 10 grid of 0s and 1s where the 0s represent open spaces and 1s represent blocked spaces (like we did in class), and then see if user can navigate from position 0,0 to where either the first index or second index equal 9 w/o hitting a 1. In other words the user must move clear across the grid without hitting a 1 or the game is over.

This lab will involve the following new features:
java.util.SecureRandom class
Two-dimensional arrays

DETAILS

There won't be as much detail on the grid creation part of this as we already created an example of the grid in class together.

Classes

GameGrid_Test
Will have main method and will instantiate instance of GameGrid and call run... that's it.

GameGrid
This will have one public "run" method and this will be called by the GameGrid_Test class's main method. ALL CODE can be in the "run" method.
Create game grid: This method will create a game grid (two-dimensional int array) and fill each cell with 1 or 0 randomly using the Random class.
There should be a LESS CHANCE to have a 1 fill the spot than a 0.
Reminder Tip:
Set an int variable called iWallChance to a number like 30, and then use the bound parameter of the SecureRandom class's nextInt method to control the range of possible numbers just like we did in class.
Then you'd compare the returned random number to see if it's less than your iWallChance variable.
If it was less, you'd set that cell to 1... if not, then the cell would be set to 0.
Change the location [0][0] of the grid to 0 so that the first space is open and not a wall because that's where we'll start our user.
Create two int variables for the user's position... iUserRow and iUserCol... and set each to 0.
Create a boolean variable for the following loop to know when to exit.
Create while loop for moving: This loop will keep asking user whether to move down or to the right.
If the user chooses down, then that will affect the first array value (row); and if the user chooses right, that will affect the second array value.
With each user answer, adjust the iUserRow or iUserCol positions depending whether down or right by increasing the correct variable by 1.
Check if this new user position is a 1 in the grid. If it's a 1, tell the user they failed and exit loop.
If it was not a 1, then check if either user position is now a 9.
If one of them is 9, they have reached either the right side or bottom and tell them they have won and exit loop.
After loop is over, then print out the grid as we did in class (nested for loop (which is a for loop within a for loop)).
With each cell, before you print out 0 or 1, check if that cell (x and y) equals the user position (iUserRow and iUserCol).
If it does, print out a capital X in that spot.
Otherwise, simply print out the value of that spot in the array.
Printing tip: Remember in class that we used System.out.print... within the inner for loop for printing so no line break was done. Then use System.out.println(""); after the closing curly bracket of the inner for loop but before the closing curly bracket of the outer for loop. That way each row will be printed out on a separate line for a nice readable layout.

Reference no: EM133382871

Questions Cloud

Specific legislative requirement : How to designing a checklist to help make sure that a specific legislative requirement has been covered in aged care/ disability service.
Why is utilitarianism not a form of egoism : Why is utilitarianism NOT a form of egoism? What are key features of the utilitarian (or hedonic) calculus? Can you show how it might be applied to a decision
Successful operation of child care setting : parent-teacher training and other formal and informal get-togethers of the adults who share responsibility for the successful operation of a child care setting.
Write five arguments on nietzsche or alice in the wonderland : Write five arguments on the Nietzsche / Alice in the wonderland couplet. Claim; quote; interpretation of the quote and select something from the film
Build an app that randomly creates a 10 by 10 grid : Build an app that randomly creates a 10 by 10 grid of 0s and 1s where the 0s represent open spaces and 1s represent blocked spaces (like we did in class)
How might we benefit collectively and personally : How might we benefit collectively? How might we benefit personally? After you present his arguments, critique them. That critique could take this form
Difficulty in maintaining good personal hygiene : Ms A has difficulty in maintaining good personal hygiene. What are some methods for assisting Ms A in maintaining personal hygiene?
Compare and contrast the one according to parmenides : Compare and contrast "the one" according to Parmenides, the Idea/Form of the Good according to Plato, the Unmoved Mover ("God") of Aristotle's Metaphysics
Decreasing infection rate for hemodialysis patients : Abstract regarding decreasing the infection rate for hemodialysis patients by using specialized educational classes for patient.

Reviews

Write a Review

Computer Engineering Questions & Answers

  How are secure software update, management

CSC 120 Hampton University How are secure software update, management of trusted applications, and attestation used to automate security assurance verification

  Describe process for developing talent within organization

Discuss best practices for hiring the best talent and the process for developing that talent within the organization. Be specific as to how you will develop.

  Write some statements that use a while loop to associate s

Associate the sum of the non-negative values in the list numbers with the variable sum .

  Consider a system with three smoker processes

Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it.

  Explain briefly the reasons behind the given trend

In parallel processing systems with multiple processors, there has been a trend away from shared media interconnects. Explain briefly reasons behind this trend.

  Describe design and implementation of applications

What are baseline security requirements that should be applied to the design and implementation of applications, databases, systems, network infrastructure.

  Describe the systems component functions

System architecture is the descriptive representation of the system's component functions and the communication flows between those components.

  Write a user program to access the physical memory

Please write a user program to access the physical memory using /dev/mem. Please note that, addresses you need to use here must be physical addresses.

  Make program that has a declaration in main () to store

require a C program that has a declaration in main () to store the following numbers into an array named rates:2.3,3.3,4.4,5.5,6.0. There should be a function call to show () that accepts rates in a parameter named rates and then displays the numb..

  What is a task pane

What are the different kinds of Window controls? What is the purpose of each.

  What is the average queuing delay experienced by message

What is the average queuing delay experienced by the message?What is the average end-to-end delay experienced by the message?

  What transformations must be made on the models

What transformations must be made on those models to specify an implementation? How can the two levels be made better integrated?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd