Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a simple implementation of the Lights Out game. ( https://en.wikipedia.org/wiki/Lights_Out_(game) ) Create class LightsOut with the following public methods: LightsOut(int m, int n) -

Create a simple implementation of the Lights Out game. ( https://en.wikipedia.org/wiki/Lights_Out_(game) )

Create class LightsOut with the following public methods:

  • LightsOut(int m, int n) - create a game field with m rows and n columns of patches, and randomly initialize it by calling reset(), see below
  • void reset() - randomly initialize the game field
  • boolean getPatch(int x, int y) - get the value of the patch in the x'th row and y'th column; if either x or y is not a valid position, throw an exception
  • void setPatch(int x, int y, boolean newValue) - set the value of the patch in the x'th row and y'th column to newValue; if either x or y is not a valid position, throw an exception
  • void togglePatch(int x, int y) - toggle the state of the patch in the x'th row and y'th and its immediate 4 neighbors; if either x or y is not a valid position, throw an exception
  • boolean isDark() - return true if all patches are dark (set to true) and false, otherwise
  • boolean isWhite() - return true if all patches are white (set to false) and false, otherwise

Represent the field as a private 2D boolean array. Assume that the array is wrapped-around both horizontally and vertically (the right neighbor of a patch in the m'th column is a patch in the same row in the 1st column, etc).

Create the main class LightsOutTest. Ask the user to enter the size of the field (m and n) and create a LightsOut object of the appropriate size. Toggle random patches until the field becomes either completely dark or white, whatever comes first. Display the number of steps.

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

Students also viewed these Databases questions

Question

What is the relationship between humans?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago