Anam/lightsoutgame

From ggc

Jump to: navigation, search

01 package Anam;
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 Anam Mughal with the enormous help from Derrick Dixon
13 and Michael and Frank and using the model provided by Dr. Jenkins.
14  */
15 public class lightsoutgame extends Game
16 {
17   //Declares the circles, the strings, and the model.
18   private OvalSprite [][] circles=new OvalSprite[7][7];
19   private StringSprite won;
20   private StringSprite won2;
21   private LightsOutModel model;
22   //This is Dr. Jenkin's model that I made some changes and used it
23 
24   /**sets up the game*/
25   public void setup()
26   {
27     allCircles();
28     youWon();
29     model=new LightsOutModel();
30   }
31   private void allCircles()
32   {
33     for (int i=0; i<circles.length; i++)
34     {
35       for (int j=0; j<circles.length; j++)
36       {
37         circles [i] [j]=new OvalSprite(22);
38 
39         circles [i] [j].setSize(.15);
40         double x=0.5/5+0.98/5*(i-1);
41         double y=0.5/5+0.98/5*(j-1);
42         circles [i] [j].setLocation(x, y);
43         circles [i] [j].setColor(Palette.getColor("Blue Violet"));
44         circles [i] [j].setVisible(false);
45         addSprite(circles [i] [j]);
46         //the above creates a board of 5 by 5 circles (but does not show yet)
47 
48 
49       }
50     }
51   }
52   private void youWon()
53   {
54     won= new StringSprite ("CONGRATS, You Won!!!");
55     won.setSize(0.85);
56     won.setLocation(0.500.50);
57     won.setColor(Palette.getColor("SILVER"));
58     won.setVisible(false);
59     addSprite(won);
60 
61     won2= new StringSprite ("Click Reload to Play Again!");
62     won2.setSize(0.50);
63     won2.setLocation(0.500.70);
64     won2.setColor(Palette.getColor("SILVER"));
65     won2.setVisible(false);
66     addSprite(won2);
67     //the above creates the messages to appear at the end of the game.
68   }
69 
70   /**handle input and game events*/
71   public void advance()
72   {
73     int col = 0;
74     int row = 0;
75 
76     Point2D.Double click=getPlayer().getMouse().getClickLocation();
77     if(click!=null)
78     {
79       col=(int)(click.y*5)+1;
80       row=(int)(click.x*5)+1;
81       // The two equations above were given by Dr. Jenkins
82       model.play(row,col);
83     }
84     for (int i=0; i<circles.length; i++)
85     {
86       for (int j=0; j<circles.length; j++)
87       {
88         circles[i][j].setVisible(model.isOn(i, j));
89         //randomly adds circles to the screen
90         won.setVisible(model.won());
91         won2.setVisible(model.won());
92         //goes back to the model; if the person wins the messages appear.
93         //Derrick helped me a lot with this assignment.
94 
95       }
96     }
97   }
98 }


Download/View Anam/lightsoutgame.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