Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Lights out Java

shawnspencer12
shawnspencer12 


Visit this link to familiarize yourself with Lights Out. Notice that the playing board is a 5x5 grid of lights. A light is either on or off. When you click on a light, the on/off state of that light—as well as the lights above, below, to the left, and to the right of it—toggle. The goal of the puzzle is to turn all of the lights off. The following are the requirements of your program. The GUI must have a 5x5 grid of buttons. The shape of the buttons (round, square, etc.) is your choice. When a button's light is off, its color should be white. When a button's light is on, its color should be yellow. The change in color can be accomplished with the setBackground(Color) method. However, this does not read well on all platforms. Therefore, you must also set two additional properties. Call the setOpaque(boolean) method for each button. You need do this only once per button. Use the button text and/or icon as a second indicator of whether the light is on or off. The GUI must have a "Randomize" button that randomly sets the state of each grid button (i.e., whether the light is on or off). Recall that a java.util.Random object is used to generate random numbers. The GUI must have an "Enter Manual Setup" button. When clicked, the text of the button should change to "Exit Manual Setup" and the game should enter manual-setup mode. In this mode, clicking on a grid button toggles only the grid button itself, and not any of its neighbors. When the "Exit Manual Setup" button is clicked, normal game play resumes (i.e., clicking on a grid button toggles the button itself and its neighbors). The purpose of manual setup mode is to allow a player to configure a game any way he or she pleases. The program must report when the player has won the game (i.e., turned all of the lights off) in a way that is easy to see and uses the GUI. One option is to display a message using a label. Another is to display a dialog box. Do not simply print to the console. The program must close the GUI window and terminate when the window's X icon is clicked. The GUI should look good and be user friendly. The main method used to start your program must be in a class called LightsOut that is contained in the assign9 package. You may create additional classes, as needed, also in the assign9 package. As always, your entire program should have good coding style. It is critical that all of your code be well documented, since you are responsible for its organization. That is, you are deciding what classes and methods to create, what they are called, and what they do. It is expected that no two solutions will look the same. Therefore, you must work extra hard to make certain that your code is easy to read and understand. Attachments Tags Clarifications

Answers

Answer

mariobeka
mariobeka 



Check out email. Attachments
Lightsout.zip (17 K) Download














Preview
Tools | Templates * and open the template in the editor. */ package lightsout; import

Preview
java.awt.event.ActionListener; public class GameController implements ActionListener { GameModel model; GameView view; public GameController(GameModel modelIn) {

Preview
rows = 5; columns = 5; isFinished = false; gridManager = new GridManager(rows, columns); gridObservers = new ArrayList<GridObserver>(); gameStateObservers = new ArrayList<GameStateObserver>(); } public void toggleCell(int x, int y) { gridManager.toggleCell(x, y); notifyGridObservers(); isFinished = gridManager.gameIsFinished; if (isFinished) { notifyGameStateObservers(); } } public void toggleCellManual(int x, int

Preview
and open the template in the editor. */ package

Preview
CellButton(); button.set(i, j); button.setSize(16, 16); button.addActionListener(controller); button.setOpaque(true); buttonGrid[i][j] = button; pane.add(button); } } mainWindow.add(menuBar, BorderLayout.NORTH); mainWindow.add(pane, BorderLayout.CENTER); drawGrid(); mainWindow.setVisible(true); } @Override public void updateGameState(boolean isFinished) { if (isFinished) { int response = JOptionPane.showConfirmDialog(mainWindow, "Congratulations!, play again?", "You Win!",

Preview
the template in the editor. */ package lightsout; public class GridManager { LightGrid mainGrid; boolean gameIsFinished; public GridManager(int rowsIn, int columnsIn) { mainGrid = new LightGridStandardImpl(rowsIn, columnsIn); gameIsFinished = false; }

Preview
Templates * and open the template in the

Preview
and open the template in the editor. */ package lightsout; public interface LightGrid { public

Preview
j < columns; j++) { if (grid[i][j] == true) { rowHasActiveCells = true; break; } else { continue; } } if (rowHasActiveCells) { gridHasActiveCells = true; break; } else { continue; } } if (gridHasActiveCells) { isSolved = false; } else { isSolved = true; } }

Preview
the view. // Program runs until user exits the view. //Set Look & Feel GameModel model = new GameModel(); GameController controller =

Screen Shot 2013-11-19 at 10.05.21 PM.png (34 K) Download Preview

Screenshots
Screenshot
Purchase Answer