lights/LightsOutModel

From ggc

Jump to: navigation, search

01 package lights;
02 
03 import wiki.Wiki;
04 /**
05  * All about my class here.
06  @author Jam Jenkins
07  */
08 public class LightsOutModel
09 {
10   private boolean[][] cells;
11 
12   /**
13    * Initializes all of the lights to on.
14    */
15   public LightsOutModel()
16   {
17     cells=new boolean[5][5];
18     for(int r=0; r<cells.length; r++)
19     {
20       for(int c=0; c<cells[0].length; c++)
21       {
22         cells[r][c]=false;
23       }
24     }
25     java.util.Random random=new java.util.Random();
26     for(int k=0; k<10; k++)
27       play(random.nextInt(cells.length), random.nextInt(cells[0].length));
28   }
29 
30   public void play(int row, int col)
31   {
32     cells[row][col]=!cells[row][col];
33   }
34 
35   public boolean won()
36   {
37     return false;
38   }
39 
40   public boolean isOn(int row, int col)
41   {
42     return cells[row][col];
43   }
44 
45   public String toString()
46   {
47     String total="";
48     for(int r=0; r<cells.length; r++)
49     {
50       for(int c=0; c<cells[0].length; c++)
51       {
52         total+=cells[r][c]+"\t";
53       }
54       total+="\n";
55     }
56     return total;
57   }
58 
59 }


Download/View lights/LightsOutModel.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter