NickandChris/lights/LightsOut

From ggc

Jump to: navigation, search

001 package NickandChris.lights;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * All about my game here.
010  @author Nmckee
011  */
012 //Graphical interface class
013 public class LightsOut extends GameLoop
014 {
015   //Sets up the squares and declares how many elements are in the array
016   private OvalSprite[][] lights = new OvalSprite[5][5];
017   private RectangleSprite[][] squares = new RectangleSprite[5][5];
018   private LightsOutModel model;
019   private StringSprite youWin;
020 
021   //Declares the LightsOutModel class to model and creates the sprites
022   public void startGame()
023   {
024     model=new LightsOutModel();
025     makeSprites();
026     youWin();
027 
028   }
029 
030   //Sets up the for loops on how wide and high the board will be while giving declaring their colors and size
031   private void makeSprites()
032   {
033     for(int = 0; i < 5; i++)
034     {
035       for(int = 0; u < 5; u++)
036       {
037         squares[i][u] = new RectangleSprite(11);
038         squares[i][u].setScale(0.18);
039         squares[i][u].setColor(Color.WHITE);
040         squares[i][u].setLocation(.1 + .2 * i, .2 * u + .1);
041 
042         lights[i][u] = new OvalSprite(11);
043         lights[i][u].setScale(0.17);
044         lights[i][u].setColor(Color.RED);
045         lights[i][u].setLocation(.1 + .2 * i, .2 * u + .1);
046 
047         canvas.addSprite(squares[i][u], lights[i][u]);
048         lights[i][u].setVisible(model.isOn(u, i));
049       }
050     }
051   }
052   //Defines what happens when all lights are cleared
053   private void youWin()
054   {
055     youWin=new StringSprite("You Win");
056     youWin.setHeight(0.1);
057     youWin.setLocation(.5.5);
058     youWin.setVisible(false);
059   }
060 
061 
062   //Sets up the boundaries between each light(column & row) if clicked on
063   public void advanceFrame(double timePassed)
064   {
065     Point2D.Double click = getPlayer().getMouse().getClickLocation();
066     if(click!=null)
067     {
068       int row=0;
069       int col=0;
070       if(click.x> && click.x <= .2)
071       {
072         col=0;
073       }
074       else if(click.x> .2 && click.x <= .4)
075       {
076         col=1;
077       }
078       else if(click.x> .4 && click.x <= .6)
079       {
080         col=2;
081       }
082       else if (click.x> .6 && click.x <= .8)
083       {
084         col=3;
085       }
086       else if (click.x> .8 && click.x <= 1)
087       {
088         col=4;
089       }
090       if(click.y> && click.y <= .2)
091       {
092         row=0;
093       }
094       else if(click.y> .2 && click.y <= .4)
095       {
096         row=1;
097       }
098       else if (click.y> .4 && click.y <= .6)
099       {
100         row=2;
101       }
102       else if(click.y> .6 && click.y <= .8)
103       {
104         row=3;
105       }
106       else if(click.y> .8 && click.y <= 1)
107       {
108         row=4;
109       }
110       //Goes to LightsOutModel to find which row and column is in use
111       model.play(row,col);
112       for(int i=0; i<5; i++)
113       {
114         for(int u=0; u<5; u++)
115         {
116           //Goes to LightsOutModel won and turns off visibility for lights
117 
118           youWin.setVisible(model.won());
119           lights[i][u].setVisible(model.isOn(u, i));
120         }
121       }
122 
123     }
124 
125 
126   }
127 }


Download/View NickandChris/lights/LightsOut.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