Would someone assist me please. I want to include (upload) code along with my coding question, however, I can't find any reference on how to do this.
Thanks
import greenfoot.*;
/**
* Working Scenario. Pengu has nuts and broccoli to eat. Can move left or right.
*/
public class Pengu extends Actor
{
private int points =0;
private Counter counter;
/**
* Counter to count number of nuts and broccoli eaten. 5 points for each eaten.
*
*/public Pengu (Counter pointCounter)
{
counter = pointCounter;
}
public void act()
{
checkKeys();
tryToEatNut();
tryToEatBroccoli();
}
private void checkKeys()
{
if (Greenfoot.isKeyDown("left") )
{
setImage("pengu-left.png");
move(-4);
}
if (Greenfoot.isKeyDown("right") )
{
setImage("pengu-right.png");
move(4);
}
}
public void tryToEatNut()
{
if (canSee(Nut.class))
{
eat(Nut.class);
points++;
counter.add(5);
}
}
public void tryToEatBroccoli()
{
if (canSee(Broccoli.class))
{
eat(Broccoli.class);
points++;
counter.add(5);
}
}
/**
* Return true if we can see an object of class 'clss' right where we are.
* False if there is no such object here.
*/
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}
/**
* Try to eat an object of class 'clss'. This is only successful if there
* is such an object where we currently are. Otherwise this method does
* nothing.
*/
public void eat(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
}import greenfoot.*;
/**
* Non-working Scenario. Pengu has nuts and broccoli to eat. Can move left or right.
*/
public class Pengu extends Actor
{
private int points =0;
private Counter counter;
private Counter counter1;
/**
* Counter to count number of nuts and broccoli eaten. 5 points for each eaten.
*
*/public Pengu (Counter pointCounter)
{
counter = pointCounter;
}
/**
* Counter to count number of nuts and broccoli eaten. 5 points for each eaten.
*
*/public Pengu (Counter pointCounter1)
{
counter1 = pointCounter1;
}
public void act()
{
checkKeys();
tryToEatNut();
tryToEatBroccoli();
}
private void checkKeys()
{
if (Greenfoot.isKeyDown("left") )
{
setImage("pengu-left.png");
move(-4);
}
if (Greenfoot.isKeyDown("right") )
{
setImage("pengu-right.png");
move(4);
}
}
public void tryToEatNut()
{
if (canSee(Nut.class))
{
eat(Nut.class);
points++;
counter.add(5);
}
}
public void tryToEatBroccoli()
{
if (canSee(Broccoli.class))
{
eat(Broccoli.class);
points++;
counter1.add(5);
}
}
/**
* Return true if we can see an object of class 'clss' right where we are.
* False if there is no such object here.
*/
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}
/**
* Try to eat an object of class 'clss'. This is only successful if there
* is such an object where we currently are. Otherwise this method does
* nothing.
*/
public void eat(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
}public pengu(Counter)
/**
* Counter to count number of nuts and broccoli eaten. 5 points for each eaten.
*
*/
public Pengu (Counter pointCounter, Counter pointCounter1)
{
counter = pointCounter;
counter1 = pointCounter1;
}