Hello, so my group partner and i cannot figure out for the life of us what is going on with our code. We have stared at it over and over so i will attach all the code we have so far. and explain as i go
This is our backGround where is says counter.setValue(0); st.mark(); and st.millisElapsed is where we are getting our errors at in this class.
currently this code for counter appears to be working including it for an as a whole purpose
same thing with our scoreboard
again same is working
also working
the errors in the Jerry Class appear where is says (Basketball.class); and backGround.counter.add(1);
any help that you may be able to give would be greatly appreciated and thank you in advance
public class backGround extends World
{
static Counter counter = new Counter();
Counter counter2 = new Counter();
SimpleTimer st = new SimpleTimer();
/**
* Constructor for objects of class backGround.
*
*/
public backGround()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 550, 1);
Jerry j1 = new Jerry();
addObject(j1,100,300);
counter.setValue(0);
st.mark();
prepare();
}
public void act()
{
if(Greenfoot.getRandomNumber(200)<3)
{
addObject(new Basketball(),Greenfoot.getRandomNumber(601),0);
counter2.setValue(st.millisElapsed()/1000);
if(counter.getValue()>=40)
{
showText("Time is Up", 300,200);
Greenfoot.stop();
}
}
}
private void prepare()
{
Jeffy jeffy = new Jeffy();
addObject(jeffy, 550, 46);
showText("score", 63, 16);
addObject(counter, 63, 36);
showText("Timer", 548, 362);
addObject(counter2, 548, 382);
}
}public class Counter extends Actor
{
public static final float FONT_SIZE = 18.0f;
private int value;
private String text;
private int stringLength;
private Font font;
/**
* Create a counter without text.
*/
public Counter()
{
this("");
}
/**
* Create a counter with prefix text, and 0 value.
*/
public Counter(String prefix)
{
this(prefix, 0);
}
/**
* Create a counter with prefix text and value.
*/
public Counter(String prefix, int value)
{
this.value = value;
text = prefix;
stringLength = (text.length() + 4) * 10;
GreenfootImage image = new GreenfootImage(stringLength, 22);
setImage(image);
font = image.getFont();
font = font.deriveFont(FONT_SIZE);
updateImage();
}
/**
* Increment the counter by one.
*/
public void increment()
{
value++;
updateImage();
}
/**
* Return the current counter value.
*/
public int getValue()
{
return value;
}
public int setValue()
{
this.value = value;
}
/**
* Make the image
*/
private void updateImage()
{
GreenfootImage image = getImage();
image.clear();
image.setFont(font);
image.setColor(Color.BLACK);
image.drawString(text + value, 6, (int)FONT_SIZE);
}
}public class Scoreboard extends Actor
{
public static final float FONT_SIZE = 48.0f;
public static final int WIDTH = 600;
public static final int HEIGHT = 400;
public Scoreboard()
{
makeImage("Scores", "Score: ", "nobody", 100);
}
/**
* Create a score board for an interim result.
*/
public Scoreboard(String title, String text, String prefix, int map, int[] scores)
{
makeImage(title, text, prefix, scores[map]);
}
/**
* Create a score board for the final result.
*/
public Scoreboard(String title, String text, String prefix, int[] scores)
{
int total = 0;
for (int val : scores) {
total += val;
}
makeImage(title, text, prefix, total);
}
/**
* Make the score board image.
*/
private void makeImage(String title, String text, String prefix, int score)
{
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
image.setColor(new Color(0, 0, 0, 128));
image.fillRect(0, 0, WIDTH, HEIGHT);
image.setColor(new Color(0, 0, 0, 128));
image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
Font font = image.getFont();
font = font.deriveFont(FONT_SIZE);
image.setFont(font);
image.setColor(Color.WHITE);
image.drawString(title, 60, 100);
image.drawString(text, 60, 220);
image.drawString(prefix + score, 60, 320);
setImage(image);
}
}
public class Basketball extends Actor
{
/**
* Act - do whatever the Basketball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY()+2);
if(getWorld().getHeight()-getY()<20)
{
getWorld().removeObject(this);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import static greenfoot.Greenfoot.*;
/**
* Write a description of class Jeffy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Jeffy extends Actor
{
/**
* Act - do whatever the Jeffy wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(getRandomNumber(10));
if(atWorldEdge())
{
turn(getRandomNumber(10));
}
if(isTouching(Jerry.class))
{
removeTouching(Jerry.class);
GreenfootImage g1 = new GreenfootImage("You lose", 50, Color.WHITE, Color.BLACK);
setImage(g1);
setLocation(300, 200);
setRotation(0);
stop();
}
}
public boolean atWorldEdge()
{
if(getY()<20 || getWorld().getHeight()-getY()<20)
{
return true;
}
if(getX()<20 || getWorld().getWidth() - getX()<20)
{
return true;
}
else
{
return false;
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.Greenfoot.*;
/**
* Write a description of class Jerry here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Jerry extends Actor
{
/**
* Act - do whatever the Jerry wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if(Greenfoot.isKeyDown("right"))
{
setLocation(getX()+2, getY());
}
if(Greenfoot.isKeyDown("left"))
{
setLocation(getX()-2, getY());
}
if(Greenfoot.isKeyDown("down"));
{
setLocation(getX(), getY()+2);
}
if(Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY()-2);
}
Actor a = getIntersectingObjects(Basketball.class);
if(a!=null)
{
backGround.counter.add(1);
getWorld().removeObject(a);
}
if(backGround.counter.getValue()>=5)
{
GreenfootImage g1 = new GreenfootImage("You Win", 50, Color.RED, Color.BLACK);
setImage(g1);
setLocation(300, 200);
setRotation(0);
Greenfoot.stop();
}
}
}
