JacobOlson/LightsOut

From ggc

Jump to: navigation, search

01 package JacobOlson;
02 
03 import wiki.Wiki;
04 import fang.*;
05 import java.awt.*;
06 import java.awt.geom.*;
07 /**
08  * The origin of my game comes from my lights out model
09  @author Jolson
10  */
11 public class LightsOut extends GameLoop
12 
13 {
14   //these are the lights of the game
15   private OvalSprite[][] circles=new OvalSprite[5][5];
16   //this helps in making the grid 5X5
17   private RectangleSprite[][] boxs=new RectangleSprite[5][5];
18 
19   //this is what places the sprites then activates the method that randomizes the lights
20   public void startGame()
21   {
22     for(int r=0; r<5; r++)
23     {
24       for(int c=0; c<5; c++)
25       {
26         boxs[r][c]=new RectangleSprite(1,1);
27         boxs[r][c].setScale(.18);
28         boxs[r][c].setColor(Color.RED);
29         boxs[r][c].setLocation((0.2 (+ 1)) 0.1(0.2 (+ 1)) 0.1);
30 
31         circles[r][c]=new OvalSprite(1,1);
32         circles[r][c].setScale(.18);
33         circles[r][c].setColor(Color.GREEN);
34         circles[r][c].setLocation((0.2 (+ 1)) 0.1(0.2 (+ 1)) 0.1);
35 
36         canvas.addSprite(boxs[r][c], circles[r][c]);
37       }
38     }
39     mixUp();
40     //when someone clicks on the help button a window with this will appear
41     setHelpText
42     ("To win, make all the lights disappear."+
43      "to reset press r");
44   }
45 
46   //method that randomizes the lights on and off
47   public void mixUp()
48   {
49     for(int r=0; r<5; r++)
50     {
51       for(int c=0; c<5; c++)
52       {
53         if(rand(106)
54           circles[r][c].setVisible(false);
55         else
56           circles[r][c].setVisible(true);
57       }
58     }
59   }
60 
61   private int rand(int high)
62   {
63     return (int)Math.round(Math.random() * high);
64   }
65 
66   //controls all the action that happins in this game
67   public void advanceFrame(double timePassed)
68   {
69     Point2D.Double click = getPlayer().getMouse().getClickLocation();
70     //i used my lights out model to help set this up
71     for(int = 0; r < 5; r++)
72     {
73       for(int = 0; c < 5; c++)
74       {
75         if(click != null && boxs[r][c].intersects(click))
76         {
77           circles[r][c].setVisible(!circles[r][c].isVisible());
78           circles[Math.min(+ 14)][c].setVisible(!circles[Math.min(+ 14)][c].isVisible());
79           circles[Math.max(r - 10)][c].setVisible(!circles[Math.max(r - 10)][c].isVisible());
80           circles[r][Math.min(+ 14)].setVisible(!circles[r][Math.min(+ 14)].isVisible());
81           circles[r][Math.max(c - 10)].setVisible(!circles[r][Math.max(c - 10)].isVisible());
82 
83           if((== || r == 4&& (== || c == 4))
84           {}
85           else if(== || r == || c == || c == 4)
86             circles[r][c].setVisible(!circles[r][c].isVisible());
87         }
88       }
89     }
90 
91     //resets the game
92     if(getPlayer().getKeyboard().getLastKey() == 'r')
93       mixUp();
94   }
95 }


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