ThomasJohanningmeier/wackadot/Wackadot

From ggc

Jump to: navigation, search

001 package ThomasJohanningmeier.wackadot;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  * This is based on the game Wackadot.
010  * Author: Thomas Johanningmeier 
011  */
012 public class Wackadot extends GameLoop
013 {
014 private ImageSprite dot;
015 private Sound sound;
016 private Sound sound2;
017 private ImageSprite sprite;
018 
019 public void startGame()
020 {
021    score=0;
022    timeLeft=30;
023   makeSprites();
024   addSprites();
025   scheduleRelative(new TimerUpdater()1);
026   setHelp("resources/WackadotHelp.html");
027         makeSounds();
028         toggleAudible();
029 }
030 class TimerUpdater implements Alarm
031 {
032   public void alarm()
033   {
034     timeLeft--;
035     updateTimer();
036     if(timeLeft>0)
037     {
038       scheduleRelative(this1);
039     } 
040   }
041 }
042 
043 private void makeSprites()  
044 {
045   Ellipse2D.Double circle= 
046   new Ellipse2D.Double(0011);
047   
048   dot=new ImageSprite(Wiki.getMedia("bomb.gif"));
049   dot.setScale(0.25);
050   dot.setLocation(0.50.5);
051   dot.setColor(Color.GREEN);
052   
053   greenDot=new ImageSprite(Wiki.getMedia("bomb.gif"));
054   greenDot.setScale(0.25);
055   greenDot.setLocation(
056          random.nextDouble(),
057           random.nextDouble());
058    greenDot.setColor(Color.GREEN);
059 
060   yellowDot=new ImageSprite(Wiki.getMedia("coin1.gif"));
061   yellowDot.setScale(0.25);
062   yellowDot.setLocation(
063           random.nextDouble()
064            random.nextDouble());
065    yellowDot.setColor(Color.YELLOW);
066 
067   scoreSprite=new StringSprite("Score: "+score);
068   scoreSprite.setHeight(0.1);
069   scoreSprite.rightJustify();
070   scoreSprite.topJustify();
071   scoreSprite.setLocation(10);
072   
073   timerSprite=new StringSprite("Timer: "+timeLeft);
074   timerSprite.setHeight(0.1);
075   timerSprite.leftJustify();
076   timerSprite.topJustify();
077   timerSprite.setLocation(00);     
078   
079 }
080 private void makeSounds()
081 {
082         sound=new Sound(Wiki.getMedia("cash_register.wav"));
083         sound2=new Sound(Wiki.getMedia("boo.wav"));
084 }
085 private void updateTimer()
086 {
087   timerSprite.setText("Timer: "+timeLeft);
088 }
089 private void updateScore()
090 {
091   scoreSprite.setText("Score: "+score);
092 }
093 
094 private void addSprites()
095 {
096   canvas.addSprite(dot);
097   canvas.addSprite(greenDot);
098   canvas.addSprite(yellowDot);
099   canvas.addSprite(scoreSprite);
100   canvas.addSprite(timerSprite);
101 }
102 
103 private void repositionRandomly(Sprite sprite)
104 {
105         
106   sprite.setLocation(
107       random.nextDouble(),
108       random.nextDouble());
109 }
110 
111 private void handleCollisions()
112 {
113   if(dot.intersects(yellowDot))
114   {
115                
116     repositionRandomly(yellowDot);
117     if (dot.getColor().equals(Color.YELLOW))
118         
119     {
120                         dot.setImage(Wiki.getMedia("bomb.gif"));
121       dot.setColor(Color.GREEN);
122       score++;
123       sound.play();
124 
125     }
126     else
127     {
128       score--;
129       sound2.play();
130     }
131     updateScore();
132   }
133   if(dot.intersects(greenDot))
134   {
135                 
136     repositionRandomly(greenDot);
137     if(dot.getColor().equals(Color.GREEN))
138        
139     {
140                         dot.setImage(Wiki.getMedia("coin1.gif"));
141       dot.setColor(Color.YELLOW);
142       score++;
143       sound.play();
144     }
145     else
146     {
147       score--;
148       sound2.play();
149     }
150     updateScore();
151   }
152 }
153 public void advanceFrame(double timePassed)
154 {
155 if(timeLeft>0)
156 {
157   Point2D.Double mouse=
158   getPlayer().getMouse().getLocation();
159   dot.setLocation(mouse);
160   handleCollisions();
161 }  
162 }
163 private Sprite greenDot;
164 private Sprite yellowDot;
165 private StringSprite scoreSprite;
166 private int score;
167 private int timeLeft;
168 private StringSprite timerSprite;
169 }

Compiler Errors:
----------
1. ERROR in ThomasJohanningmeier/wackadot/Wackadot.java (at line 48)
	dot=new ImageSprite(Wiki.getMedia("bomb.gif"));
	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The constructor ImageSprite(URL) is undefined
----------
2. ERROR in ThomasJohanningmeier/wackadot/Wackadot.java (at line 53)
	greenDot=new ImageSprite(Wiki.getMedia("bomb.gif"));
	         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method setImage(String) in the type ImageSprite is not applicable for the arguments (URL)
----------
5 problems (5 errors)

Download/View ThomasJohanningmeier/wackadot/Wackadot.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