Merima/LightsOutProject

From ggc

Jump to: navigation, search

001 package Merima;
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 Merima Omanovic
011  */
012 public class LightsOutProject extends GameLoop
013 {
014 
015   private OvalSprite[][] circles;
016   private StringSprite youWin;
017   private LightsOutModel model;
018   private RectangleSprite[][] squares;
019 
020   public void startGame()
021   {
022 
023     model=new LightsOutModel();
024     makeCircles();
025     makeSquares();
026     addSprites();
027     youWin();
028     canvas.addSprite(youWin);
029 
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   /**Makes the circles*/
040   private void makeCircles()
041   {
042     int index=0;
043     circles=new OvalSprite[5][5];
044     int numBlocksHigh=5;
045     double startLocationY=.17;
046     double endLocationY=1-startLocationY;
047     double distanceHigh=endLocationY+startLocationY;
048     for(int j=0; j<numBlocksHigh; j++)
049     {
050       double y=j*distanceHigh/(numBlocksHigh+1)+startLocationY;
051 
052       int numBlocksAcross=5;
053       double startLocationX=0.17;
054       double endLocationX=1-startLocationX;
055       double distanceAcross=endLocationX+startLocationX;
056       for(int i=0; i<numBlocksAcross; i++)
057       {
058         double x=i*distanceAcross/(numBlocksAcross+1)+startLocationX;
059         circles[i][j]=new OvalSprite(2,2);
060         circles[i][j].setScale(0.18);
061         circles[i][j].setLocation((0.2 (+ 1)) 0.1(0.2 (+ 1)) 0.1);
062 
063         circles[i][j].setColor(Color.GREEN);
064         //canvas.addSprite(circles[index]);
065         index++;
066         /*Add the circles to the game.*/
067       }
068     }
069 
070     for(int j=0; j<5; j++)
071     {
072       for(int i=0; i<5; i++)
073       {
074 
075 
076         circles[j][i].setVisible(model.isOn(i, j));
077       }
078     }
079   }
080   private void makeSquares()
081   {
082     int index=0;
083     squares=new RectangleSprite[5][5];
084     int numBlocksHigh=5;
085     double startLocationY=.17;
086     double endLocationY=1-startLocationY;
087     double distanceHigh=endLocationY+startLocationY;
088     for(int j=0; j<numBlocksHigh; j++)
089     {
090       double y=j*distanceHigh/(numBlocksHigh+1)+startLocationY;
091 
092       int numBlocksAcross=5;
093       double startLocationX=0.17;
094       double endLocationX=1-startLocationX;
095       double distanceAcross=endLocationX+startLocationX;
096       for(int i=0; i<numBlocksAcross; i++)
097       {
098         double x=i*distanceAcross/(numBlocksAcross+1)+startLocationX;
099         squares[i][j]=new RectangleSprite(2,2);
100         squares[i][j].setScale(0.18);
101         squares[i][j].setLocation((0.2 (+ 1)) 0.1(0.2 (+ 1)) 0.1);
102 
103         squares[i][j].setColor(Color.WHITE);
104         index++;
105         /*Make the squares.*/
106       }
107     }
108   }
109 
110 
111   /**adds the sprites to the screen*/
112   private void addSprites()
113 
114   {
115     for(int r=0; r<squares.length; r++)
116     {
117       for(int c=0; c<squares[0].length; c++)
118       {
119         canvas.addSprite(squares[r][c]);;
120       }
121     }
122     for(int r=0; r<circles.length; r++)
123     {
124       for(int c=0; c<circles[0].length; c++)
125       {
126         canvas.addSprite(circles[r][c]);;
127       }
128     }
129 
130   }
131   /**handle input and game events*/
132   public void advanceFrame(double timePassed)
133   {
134 
135     Point2D.Double click=getPlayer().getMouse().getClickLocation();
136     if(click!=null)
137     {
138       int row=0;
139       int col=0;
140       if(click.x> && click.x <= .2)
141       {
142         col=0;
143       }
144       else if(click.x> .2 && click.x <= .4)
145       {
146         col=1;
147       }
148       else if(click.x> .4 && click.x <= .6)
149       {
150         col=2;
151       }
152       else if (click.x> .6 && click.x <= .8)
153       {
154         col=3;
155       }
156       else if (click.x> .8 && click.x <= 1)
157       {
158         col=4;
159       }
160       if(click.y> && click.y <= .2)
161       {
162         row=0;
163       }
164       else if(click.y> .2 && click.y <= .4)
165       {
166         row=1;
167       }
168       else if (click.y> .4 && click.y <= .6)
169       {
170         row=2;
171       }
172       else if(click.y> .6 && click.y <= .8)
173       {
174         row=3;
175       }
176       else if(click.y> .8 && click.y <= 1)
177       {
178         row=4;
179       }
180 
181       model.play(row,col);
182       for(int j=0; j<5; j++)
183       {
184         for(int i=0; i<5; i++)
185         {
186 
187           youWin.setVisible(model.won());
188           circles[j][i].setVisible(model.isOn(i, j));
189         }
190       }
191 
192     }
193 
194   }
195 
196 }


Download/View Merima/LightsOutProject.java /**

  • I received helped from Kim,Matt,Chris and my BreakOutGame.
*/




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