Gerdes/Wackadot

From ggc

Jump to: navigation, search

001 package Gerdes;
002 
003 import wiki.*;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 /**
009  
010  @author Jam Jenkins/Michael Gerdes
011  */
012 public class Wackadot
013 {
014   /**Field declaration variables*/
015   private Sprite dot;
016   private Sprite redDot;
017   private Sprite blueDot;
018   private StringSprite scoreSprite;
019 
020   private int score;
021   private int timeLeft;
022   private StringSprite timerSprite;
023 
024   /**Main method declaration and definitions*/
025   public void startGame() /**main method declaring initial values*/
026   {
027     score = 0;
028     /**Sets the initial score to zero*/
029     timeLeft = 20;
030     /**Sets the initial time to ten*/
031     makeSprites();
032     /**Makes sprite objects*/
033     addSprites();
034     /**Adds the sprite object to the screen*/
035     scheduleRelative(new TimeUpdater(),1);
036     /**Schedules the alarm method of the TimeUpdater class to be called one second from the start of the game*/
037     setHelpText("Lots of help text here later");
038   }
039   class TimeUpdater implements Alarm
040   {
041     public void alarm()
042     {
043       timeLeft--;
044       updateTimer();
045       if(timeLeft > 0)
046       {
047         scheduleRelative(this1);
048       }
049     }
050   }
051 
052   /**Method declaration and definitions for making the Sprite objects*/
053   private void makeSprites()
054   /**method delcaration*/
055   {
056     dot = new OvalSprite(11);
057     /**constructing the field variable dot*/
058     dot.setScale(0.1);
059     /**sizing the dot one tenth of the screen*/
060     dot.setLocation(0.50.5)/**placing the dot in the middle of the screen*/
061     dot.setColor(Color.RED)/**setting the color of the dot*/
062 
063     redDot = new OvalSprite(1,1)/**constructing a new local variable redDot*/
064     redDot.setScale(0.1);
065     /**sizing the dot on the screen*/
066     redDot.setLocation(random.nextDouble(),random.nextDouble());
067     redDot.setColor(Color.RED);
068 
069     blueDot = new OvalSprite(1,1);
070     /**constructs the variable blueDot parameters*/
071     blueDot.setScale(0.1);
072     blueDot.setLocation(random.nextDouble(),random.nextDouble());
073     blueDot.setColor(Color.BLUE);
074 
075     scoreSprite = new StringSprite("Score: " + score);
076     /**constructs the local variable scoreSprite*/
077     scoreSprite.setHeight(0.1);
078     /**the text will be 1/10 of the screen high.*/
079     scoreSprite.rightJustify();
080     /**the text will be the rightmost location*/
081     scoreSprite.topJustify();
082     /**the text will be the topmost location*/
083     scoreSprite.setLocation(1,0);
084     /**top right where the score will be*/
085 
086     timerSprite = new StringSprite("Timer: " + timeLeft);
087     timerSprite.leftJustify();
088     timerSprite.topJustify();
089     timerSprite.setHeight(0.1);
090     timerSprite.setLocation(0,0);
091   }
092   /**Method declaration and definitions for adding the Sprite objects*/
093   private void addSprites()  /**method declaration*/
094   {
095     canvas.addSprite(dot)/**method calls/definitions*/
096     canvas.addSprite(redDot);
097     canvas.addSprite(blueDot);
098     canvas.addSprite(scoreSprite);
099     canvas.addSprite(timerSprite);
100   }
101 
102   /**Method declaration and definition for the time clock*/
103   private void updateTimer()
104   {
105     timerSprite.setText("Timer: " + timeLeft);
106   }
107 
108   /**Method declaration and definition for randomly positioning the dot*/
109   private void repositionRandomly(Sprite sprite)
110   {
111     sprite.setLocation(random.nextDouble(),random.nextDouble());
112   }
113 
114   /**Method declaration and definition for updating the score*/
115   private void updateScore()
116   {
117     scoreSprite.setText("Score: " + score);
118   }
119 
120   /**Method declaration and definitions for dot collisions*/
121   private void handleCollisions()
122   {
123     if(dot.intersects(blueDot)) /**If the dot intersects the blue dot*/
124     {
125       repositionRandomly(blueDot)/**then randomly reposition the blue dot*/
126       if(dot.getColor().equals(Color.BLUE)) /**Also if they are the same color*/
127       {
128         dot.setColor(Color.RED)/**then turn the blue dot into a red dot*/
129         score++;
130         /**and increase the score by one*/
131       }
132       else
133         /**Else the dots do not change color*/
134       {
135         score--;
136         /**and decrease the score by one*/
137       }
138       updateScore();
139       /**Update the current score*/
140     }
141     if(dot.intersects(redDot)) /**if the dot intersects the red dot*/
142     {
143       repositionRandomly(redDot);
144       /**then randomly reposition the red dot*/
145       if(dot.getColor().equals(Color.RED)) /**also if they are the same color*/
146       {
147         dot.setColor(Color.BLUE)/**then turn the red dot into a blue dot*/
148         score++;
149         /**and increase the score by one*/
150       }
151       else
152         /**or else the dots change color*/
153       {
154         score--;
155         /**decrease the score by one*/
156       }
157       updateScore();
158       /**and keep the current score*/
159     }
160   }
161 
162   /**Method declaration and definitions for moving the dot object*/
163   public void advanceFrame(double timePassed/**method declaration*/
164   {
165     if(timeLeft > 0)
166     {
167       Point2D.Double mouse = getPlayer().getMouse().getLocation();
168       /** give the object mouse a value*/
169       dot.setLocation(mouse);
170       /**calls the helper method to move the dot where ever the mouse moves*/
171       handleCollisions();
172       /**calls the helper method for handling collisions*/
173     }
174   }
175 }

Compiler Errors:
----------
1. ERROR in Gerdes/Wackadot.java (at line 35)
	scheduleRelative(new TimeUpdater(),1);
	^^^^^^^^^^^^^^^^
The method scheduleRelative(Wackadot.TimeUpdater, int) is undefined for the type Wackadot
----------
2. ERROR in Gerdes/Wackadot.java (at line 37)
	setHelpText("Lots of help text here later");
	^^^^^^^^^^^
The method getPlayer() is undefined for the type Wackadot
----------
15 problems (15 errors)

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