Argumedo/Assignment8

From ggc

Jump to: navigation, search

001 package Argumedo;
002 
003 import fang.*;
004 import java.awt.*;
005 import java.awt.geom.*;
006 
007 /**
008  * All about my game.
009  @author Joseph Argumedo
010  *  I looked at Frank Andersons and Min Kim's code in order to figure out how 
011  *  I can make my lights turn on and off simultaneously.
012  */
013 public class Assignment8 extends Game
014 {
015   /**Allows to create the background of where the lightbulbs will be on top of*/
016   private RectangleSprite board;
017   /**Allows to use an image of a lightbulb. It is in place of the dots*/
018   private ImageSprite shawneMerriman;
019   /**Allows to create a 2d-array for the images of th lightbulbs
020      which will be used  to play the game*/
021   private ImageSprite[][] chargers  = new ImageSprite[5][5];
022   /**Set the integer row(Across) to zero*/
023   private int row=0;
024   /**Set the integer column(Down) to zero*/
025   private int col=0;
026   /**Imported a sound to the game that will be used in the start of the game*/
027   private Sound electricCurrent= new Sound ("Electric_current.wav");
028 
029   /**sets up the game*/
030   public void setup()
031   {
032     gameBoard();
033     ShawneMerriman();
034     lightsOnOff();
035     electricCurrent();
036     playSoundImmediately();
037   }
038   /**Plays the sound clip at the start of the game*/
039   public void electricCurrent()
040   {
041     electricCurrent.play(0.0);
042   }
043   /**Creates a for loop for the silver gameBoard(5 X 5) that
044      is made up of Rectangle Sprites*/
045   private void gameBoard()
046   {
047     for(int a=1; a<=6;a++)
048     {
049       for (int b=1;b<=6;b++)
050       {
051         board=new RectangleSprite(1,1);
052         board.setSize(0.19);
053         board.setLocation(-0.1+(a-1)*0.2, -0.1+(b-1)*0.2);
054         board.setColor(getColor("Silver"));
055         addSprite(board);
056       }
057     }
058   }
059   /**Creates the images of lightbulbs from a for loop plus a two d-array
060       that will be used in place of the circles*/
061   private void ShawneMerriman()
062   {
063     int shawneMerrimanRow=5;
064     int shawneMerrimanCol=5;
065     for(int r=0; r<shawneMerrimanRow; r++)
066     {
067       for(int c=0; c<shawneMerrimanRow; c++)
068       {
069         shawneMerriman=new ImageSprite("LIGHTBULB.JPG");
070         shawneMerriman.setSize(0.18);
071         double x=.5/shawneMerrimanRow+1.0/shawneMerrimanRow*(r);
072         double y=.5/shawneMerrimanRow+(c+0.0)/shawneMerrimanRow;
073         shawneMerriman.setLocation(x, y);
074         shawneMerriman.setColor(getColor("Yellow"));
075         shawneMerriman.setVisible(false);
076         chargers[r][c] = shawneMerriman;
077         addSprite(shawneMerriman);
078       }
079     }
080   }
081   /**Creates the randomization of lightbulbs at the start of the game.
082      It also allows the lightbulbs to move a certian pattern which is the result of
083      lights turning on or off horizontal or verticaly when it is clicked on by the user*/
084   private void lightsOnOff()
085   {
086     for (int = 0;r<5;r++)
087     {
088       row=(int)Math.round(4*Math.random());
089       col=(int)Math.round(4*Math.random());
090       changeShawneMerriman(row, col);
091       changeShawneMerrimanPlusSign(row, col);
092     }
093   }
094   /**Turns lights on and off only when the user playing clicks on a lightbulb*/
095   private void changeShawneMerriman(int row, int col)
096   {
097     if(chargers[row][col].isVisible())
098       chargers[row][col].setVisible(false);
099     else
100       chargers[row][col].setVisible(true);
101   }
102   /**Allows the lightbulbs to turn off and off horizontally or vertically */
103   private void changeShawneMerrimanPlusSign(int row, int col)
104   {
105     if(row != 4)
106       chargers[row+1][col].setVisible(!chargers[row+1][col].isVisible());
107     if(row !=0)
108       chargers[row-1][col].setVisible(!chargers[row-1][col].isVisible());
109     if(col != 4)
110       chargers[row][col+1].setVisible(!chargers[row][col+1].isVisible());
111     if(col != 0)
112       chargers[row][col-1].setVisible(!chargers[row][col-1].isVisible());
113   }
114   /**Allows to click on the Lights which will turn on and off during the game*/
115   private void clickLights()
116   {
117     Point2D.Double click = getPlayer().getMouse().getClickLocation();
118     if(click !=null)
119     {
120       for(int = 0; r < chargers.length; r++)
121       {
122         for(int = 0; c<chargers.length; c++)
123         {
124           if (chargers[r][c].intersects(click))
125           {
126             row=(10*r+c)/10;
127             col=(10*r+c)%10;
128             changeShawneMerriman(row, col);
129             changeShawneMerrimanPlusSign(row, col);
130           }
131         }
132       }
133     }
134   }
135 
136   public void advance()
137   {
138     clickLights();
139   }
140 }


Download/View Argumedo/Assignment8.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