kim/LightsOutProject

From ggc

Jump to: navigation, search

001 
002 package kim;
003 
004 import wiki.Wiki;
005 import fang.*;
006 import java.awt.*;
007 import java.awt.geom.*;
008 
009 /**
010  * All about my game here.
011  @author Kmooney               
012  */
013 
014 public class LightsOutProject extends GameLoop
015 {
016 
017   private OvalSprite[][] circles;
018   private StringSprite youWin;
019   private LightsOutModel model;
020 
021   public void startGame()
022   {
023 
024     model=new LightsOutModel();
025     makeCircles();
026     addSprites();
027     youWin();
028     canvas.addSprite(youWin);
029     setHelpText("Try to make the circles disappear by clicking them.");
030   }
031   private void youWin()
032   {
033     youWin=new StringSprite("You Win");
034     youWin.setHeight(0.1);
035     youWin.setLocation(.5.5);
036     youWin.setVisible(false);
037   }
038 
039   private void makeCircles()
040   {
041     int index=0;
042     circles=new OvalSprite[5][5];
043     int numBlocksHigh=5;
044     double startLocationY=.17;
045     double endLocationY=1-startLocationY;
046     double distanceHigh=endLocationY+startLocationY;
047     for(int j=0; j<numBlocksHigh; j++)
048     {
049       double y=j*distanceHigh/(numBlocksHigh+1)+startLocationY;
050 
051       int numBlocksAcross=5;
052       double startLocationX=0.17;
053       double endLocationX=1-startLocationX;
054       double distanceAcross=endLocationX+startLocationX;
055       for(int i=0; i<numBlocksAcross; i++)
056       {
057         double x=i*distanceAcross/(numBlocksAcross+1)+startLocationX;
058         circles[i][j]=new OvalSprite(1,1);
059         circles[i][j].setScale(0.15);
060         circles[i][j].setLocation(x,y);
061         circles[i][j].setColor(Color.BLUE);
062         //canvas.addSprite(circles[index]);
063         index++;
064       }
065     }
066 
067     for(int j=0; j<5; j++)
068     {
069       for(int i=0; i<5; i++)
070       {
071 
072 
073         circles[j][i].setVisible(model.isOn(i, j));
074       }
075     }
076   }
077 
078   private void addSprites()
079   {
080     for(int r=0; r<circles.length; r++)
081     {
082       for(int c=0; c<circles[0].length; c++)
083       {
084         canvas.addSprite(circles[r][c]);;
085       }
086     }
087 
088   }
089   public void advanceFrame(double timePassed)
090   {
091 
092     Point2D.Double click=getPlayer().getMouse().getClickLocation();
093     if(click!=null)
094     {
095       int row=0;
096       int col=0;
097       if(click.x> && click.x <= .2)
098       {
099         col=0;
100       }
101       else if(click.x> .2 && click.x <= .4)
102       {
103         col=1;
104       }
105       else if(click.x> .4 && click.x <= .6)
106       {
107         col=2;
108       }
109       else if (click.x> .6 && click.x <= .8)
110       {
111         col=3;
112       }
113       else if (click.x> .8 && click.x <= 1)
114       {
115         col=4;
116       }
117       if(click.y> && click.y <= .2)
118       {
119         row=0;
120       }
121       else if(click.y> .2 && click.y <= .4)
122       {
123         row=1;
124       }
125       else if (click.y> .4 && click.y <= .6)
126       {
127         row=2;
128       }
129       else if(click.y> .6 && click.y <= .8)
130       {
131         row=3;
132       }
133       else if(click.y> .8 && click.y <= 1)
134       {
135         row=4;
136       }
137 
138       model.play(row,col);
139       for(int j=0; j<5; j++)
140       {
141         for(int i=0; i<5; i++)
142         {
143 
144           youWin.setVisible(model.won());
145           circles[j][i].setVisible(model.isOn(i, j));
146         }
147       }
148 
149     }
150 
151   }
152 
153 }


Download/View kim/LightsOutProject.java

/**

  • I received helped from Merima.
*/




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