MNewman/LightsOutModel

From ggc

Jump to: navigation, search

01 package MNewman;
02 //start auto-imports
03 import java.util.*;
04 //end auto-imports
05 
06 import fang.*;
07 import java.awt.*;
08 import java.awt.geom.*;
09 
10 /**
11  * All about my game.
12  @author Moriah
13  */
14 
15 public class LightsOutModel extends Game
16 {
17 
18   private int numClicks;
19   private RectangleSprite square;
20   private ArrayList<Sprite> allSquares;
21   private OvalSprite light;
22   private ArrayList<Sprite> allLights;
23 
24 
25 
26   /**sets up the game*/
27   public void setup()
28   {
29 
30     makeAndAddLights();
31     makeAndAddSquares();
32 
33   }
34 
35   private void makeAndAddSquares()
36   {
37     allSquares=new ArrayList<Sprite>();
38     int squareAcross=5;
39     int squareDown=5;
40     for (int = 1; i<=squareAcross; i++)
41     {
42       for (int = 0; j<=squareDown; j++)
43       {
44         square=new RectangleSprite(44);
45         square.setSize(0.8/squareAcross);
46         double x=.70/squareAcross+0.9/squareAcross*(i-1);
47         double y=0.05/squareAcross+(j+0.5)/squareAcross;
48         square.setLocation(x, y);
49         square.setColor(Palette.getColor("Green"));
50         square.setVisible(true);
51         allSquares.add(square);
52         addSprite(square);
53       }
54     }
55   }
56 
57   private void makeAndAddLights()
58   {
59     allLights=new ArrayList<Sprite>();
60     int lightAcross=5;
61     int lightDown=5;
62     for (int = 1; i<=lightAcross; i++)
63     {
64       for (int = 0; j<=lightDown; j++)
65       {
66         light=new OvalSprite(44);
67         light.setSize(0.8/lightAcross);
68         double x=.70/lightAcross+0.9/lightAcross*(i-1);
69         double y=0.05/lightAcross+(j+0.5)/lightAcross;
70         light.setLocation(x, y);
71         light.setColor(Palette.getColor("Purple"));
72         light.setVisible(true);
73         allLights.add(light);
74         addSprite(light);
75       }
76     }
77   }
78 
79 
80   /**handle input and game events*/
81   public void advance()
82   {
83     Point2D.Double click=getPlayer().getMouse().getClickLocation();
84     if(click!=null)
85     {
86 
87       if (square.intersects (click))
88       {
89         canvas.removeSprite(square);
90       }
91     }
92   }
93 }


Download/View MNewman/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