Ok so basically I have a sheep and a snake. Whenever the sheep comes in contact with the snake the sheep is supposed to slow down for 1 minute. I literally have no clue on how to do this and I also don't know which actors code to put the code for this in... please help. I can attach my sheep code and snake code below. (ignore anything about flowers or spiders)
HERE IS MY SNAKE CODE:
HERE IS MY SHEEP CODE.
If you can help I would be so happy thank you!!!
import greenfoot.*;
/**
* Snake. A Snake moves forward until it hits the edge of the world, at
* which point it turns. If a Snake finds a sheep it takes away the food from the
* sheep.
* If a Snake finds Food it eats it
* If a Snake is touching a Spider, it turns away.
* @author ()
* @version (a version number or a date)
*/
public class Snake extends Actor
{
private int foodsEaten;
public Snake()
{
foodsEaten = 0;
}
/**
* Act - do whatever the Snake wants to do.
*/
public void act()
{
if (isTouching())
{
eatFood();
}
if (isTouchingSpider())
{
turn(Greenfoot.getRandomNumber(360));
move (2);
}
if (isAtEdge())
{
turn(Greenfoot.getRandomNumber(360));
}
move(1);
}
public boolean isTouching()
{
Actor foody = getOneObjectAtOffset(0, 0, Food.class);
if (foody == null)
{
return false;
}
return true;
}
public boolean isTouchingSpider()
{ Actor Spider = getOneObjectAtOffset(0, 0, Spider.class);
if (Spider == null)
{
return false;
}
return true;
}
public void eatFood()
{
Actor foody = getOneObjectAtOffset(0, 0, Food.class);
if (foody != null)
{
getWorld().removeObject(foody);
foodsEaten = foodsEaten + 1;
}
}
/**
* tell how many foods we have eaten.
*/
public int getfoodseaten()
{
return foodsEaten;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Sheep here.
*
* @author (
* @version (a version number or a date)
*/
public class Sheep extends Actor
{
public int FoodsEaten;
/**
* Act - do whatever the Sheep wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (isTouching())
{
eatFood();
}
if (Greenfoot.isKeyDown ("right"))
{
setRotation(0);move(2);
}
else if (Greenfoot.isKeyDown ("left"))
{
setRotation(180);
move(2);
}
else if (Greenfoot.isKeyDown("down"))
{
setRotation(90);
move(2);
}
else if (Greenfoot.isKeyDown("up"))
{
setRotation(270);
move(2);
}
}
public boolean isTouching()
{
Actor foody = getOneObjectAtOffset(0, 0, Food.class);
if (foody == null)
{
return false;
}
return true;
}
public void eatFood()
{
Actor foody = getOneObjectAtOffset(0, 0, Food.class);
if (foody != null)
{
getWorld().removeObject(foody);
FoodsEaten = FoodsEaten + 1;
}
}
/**
* tell how many foods we have eaten.
*/
public int getFoodsEaten()
{
return FoodsEaten;
}
}

