Hey guys so I have a uni homework thing, and I need help. Our goal in GreenFoot is to make the user enter a number of the height and width of a basket then clara which is a lady beattle, must move and create the dimensions we gave it. I have done that already, but inside we must put leafs inside the basket, but it must be the same as the height and width of the basket given. I tried to make a seperate Integer by adding both the basket height and basket width together but didn't work. This is what it should look like and my code: Also this is also what we are allowed to use in code, I'm a beginner so please don't give any complicated code.
This is what we can use:
* PERMITTED COMMANDS
* Actions: move(), turnLeft(), turnRight(), putLeaf(), removeLeaf(), showWarning(), intInput()
* Sensors: onLeaf(), treeFront()
* JAVA: if, else, while, for, !, &&, ||
*/
This is my code:
public void run()
{
// TODO: Write your code below
//basketHeight integer will make the user enter the height for the basket
int basketWidth = readInt("Enter basket width");
//basketWidth integer will make the user enter the width for the basket
int basketHeight = readInt("Enter basket Height");
int putCake = basketHeight * basketWidth;
//if clara is facing east then east is true otherwise false
boolean east = true;
//this will increase the number of leaves entered by the user and place them
putLeaves(basketWidth);
putLeaves(basketHeight -1);
for(int i = 0; i < basketHeight -2; i++)
{
move();
}
turnLeft();
//this is used to make sure Clara doesn't put a extra leaf when number is entered by user
putLeaves(basketHeight -1);
for(int a = 0; a < putCake; a++)
{
putLeaf();
move();
move();
if(onLeaf() && east == true)
{
turnLeft();
move();
turnLeft();
move();
east = false;
}
if(onLeaf() && east == false)
{
turnRight();
move();
turnRight();
move();
east = true;
}
}
}
//This method putLeaves is used to put down leaves to create a basket
public void putLeaves(int numberLeaves)
{
for(int i = 0; i < numberLeaves; i++)
{
putLeaf();
if(i == numberLeaves -1)
{
turnLeft();
}
move();
}
}
}
And this is the result: Keep in mind, that I have made the outer basket, and the leafs that you see inside the basket I don't know how to make it so its at the height and width of the basket it self.
http://tinypic.com/view.php?pic=29djlar&s=8#.VUSxp_mqpBe
