Create a program from scratch a one-dimensional game

Assignment Help JAVA Programming
Reference no: EM131711651

Assignment: Introduction to Java Programming Using arrays

In this assignment you will create a program from scratch; a one-dimensional game of Lights Out. Briefly, the game consists of a row of lights that can be either on or off. By choosing a particular light, you switch its state and the state of its neighbors. That is, you turn the chosen light from off to on or from on to off, and you turn each neighbor from off to on or from on to off, depending on their initial states. The game is won when all of the lights are turned off.

Procedure

Step 1: Open BlueJ and create a new project called Assignment07-userName, where username is your USC username You will have one file called LightsOut that contains all the logic for the game.

Game Overview: Your program should first prompt the user for a number of lights. This must be between 3 and 15 (inclusive). If it is not in that range, your program should enter a small loop in which it continues to prompt the user for an integer in the valid range until one is typed. You may assume the user will always input an integer.

Your program should create an array of the specified length and go through each value in the array and randomly set it to "on" or "off". This randomization is for each value separately -- we want a random pattern of lights to begin with.

You should then print out the pattern of lights so that each "on" light is a 4x4 block of *'s and each "off" light is a 4x4 block of spaces. Each light should be separated by vertical bars (|). After printing the lights, you should include numbers beneath each light, starting from 0.

Then, you should ask the user what light they would like to select (it must be an integer). You should check to be sure that the light selected is actually valid for the current game -- if not, you should enter a small loop and continue prompting the user until a correct input is typed in. See the run below as an example. (Also note: For some numbers of lights and some initial states, the Lights Out puzzle isn't even solvable. So there needs to be an option to let the user quit if they can't get to a solution!)

Once a valid light number is input, your program should make the appropriate changes to the light array, and then continue by printing out the new array and prompting the user again. When the user wins the game by turning off all of the lights, the program should stop, print a congratulatory message, and quit. There is no need to prompt the user to play again; in this case, we'll let the user rerun the program if they would like to.

LightsOut Specifics

• Variables:

o The boolean array of lights
o A boolean that represents if the game is won or not
o Optional:

- 2 constants (boolean ON = true and boolean OFF = false). I find it helpful to think of ON and OFF instead of true/false, but it is up to you.
- Scanner for user input (optional, can be a local variable or instance variable)

• Methods: each individual task of the game belongs in a method. You must have at least the following methods in your program (in no particular order):

o public void start() - this method controls the whole flow of the game. It is the only public method.

o private int getNumberOfLights() - this method is responsible for prompting the user for the number of lights he/she wants in the games. It will only return a valid number, [3-15]

o private void initializeLights() - this method will initialize each spot in the array to true or false. Note that the Random class has a nextBoolean() method that can be used.

o private void checkWin() - this method updates the boolean instance variable if needed and displays a message to the user

o private boolean isValid(int light) - this method returns true if a given light is valid for the game (that is, it's between valid array indices: 0 to number of lights)

o private int getLightNum() - this method handles the user input for which light they want to choose. It only returns a valid light number or -1.

o private void changeLights(int lightNum) - this method controls the flow of changing lights, based on the lightNum. It switches the light at spot lightNum, and then makes sure neighboring lights are valid before switching their colors.

- Note: At the end of this method or in the start method after the call to changeLights, you should check to see if the game is won after these lights are changed.

o private void printLights() - this method "pretty" prints the lights according to the printing specifications above

• Make sure to comment your code and use good style like proper indentation.

Attachment:- Array-Game.pdf

Reference no: EM131711651

Questions Cloud

Record year-end adjusting entry for the depletion expense : Prepare the December 31, 2017, entries to record both the ore deposit depletion and the mining machinery depreciation
Discuss about the undercover operations : Propose one (1) overall strategy in which you combine problem-oriented policing and investigation to tackle the identified issues.
How cole hardware used technology to manage inventory : Explain how Cole Hardware used technology to manage inventory and identify at least two (2) benefits of the use of this technology by the company
Lineups and other means of pretrial identification : Discuss two (2) situations in which you feel that Miranda warnings are not required as it relates to arrest, custody, and interrogation.
Create a program from scratch a one-dimensional game : create a program from scratch; a one-dimensional game of Lights Out. Briefly, the game consists of a row of lights that can be either on or off.
Critical paper using the library as well as the internet : critical paper using the library as well as the internet as resources. The paper should discuss a work of art chosen from the course textbook
Define significant difference and an important difference : Write sentences that distinguish between a statistically significant difference and an important difference.
How group norms exert influence on an individuals behavior : Discuss ways employees can avoid the pitfalls of negative peer pressure and how employers can use mentors to foster positive peer pressure .
Journalize april transaction using periodic inventory system : Tennis Shop showed Cash $2,500; Inventory $1,700; and Common Stock $4,200. Journalize the April transactions using a periodic inventory system

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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