/**
* This class implements different behaviors of frog racers.
*
* @author Your Shadow
* @version 1.0.0
*/
public class FrogBehaviors {
/**
* Models a frog that allways jumps forward one cell.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void forwardRacer(Frog frogRacer) {
frogRacer.jumpForward(1);
}
/**
* Models a frog that:
* 50 percent of the time jumps forward two cells and
* 50 percent of the time stays in the same cell.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void stayOrJumpRacerOne(Frog frogRacer) {
int value = Frog.randomValue(0, 1);
if (value == 0) {
frogRacer.jumpForward(2);
} else {
// do nothing
}
}
/**
* Models a frog that:
* 33 percent of the time jumps forward two cells,
* 33 percent of the time jumps forward one cell, and
* 33 percent of the time stays in the same cell.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void stayOrJumpRacerTwo(Frog frogRacer) {
int value = Frog.randomValue(0,2);
if(value == 0)
{
frogRacer.jumpForward(2);
}
else if(value == 1)
{
frogRacer.jumpForward(1);
}
else if(value==2)
{
frogRacer.jumpForward(0);
}
}
/**
* Models a frog that:
* 50 percent of the time jumps forward three cells, and
* 50 percent of the time jumps backward two cells.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void backwardOrForwardRacerOne(Frog frogRacer) {
int value = Frog.randomValue(0, 1);
if (value == 0) {
frogRacer.jumpForward(3);
} else if(value ==1) {
frogRacer.jumpBackward(2);
}
}
/**
* Models a frog that:
* 25 percent of the time jumps forward four cells,
* 25 percent of the time jumps forward one cells
* 25 percent of the time jumps backward one cells, and
* 25 percent of the time jumps backward two cells.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void backwardOrForwardRacerTwo(Frog frogRacer) {
int value = Frog.randomValue(0,4);
if(value == 0)
{
frogRacer.jumpForward(4);
}
else if(value == 1)
{
frogRacer.jumpForward(1);
}
else if(value==2)
{
frogRacer.jumpBackward(1);
}
else if(value==3)
{
frogRacer.jumpBackward(2);
}
}
}
* This class implements different behaviors of frog racers.
*
* @author Your Shadow
* @version 1.0.0
*/
public class FrogBehaviors {
/**
* Models a frog that allways jumps forward one cell.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void forwardRacer(Frog frogRacer) {
frogRacer.jumpForward(1);
}
/**
* Models a frog that:
* 50 percent of the time jumps forward two cells and
* 50 percent of the time stays in the same cell.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void stayOrJumpRacerOne(Frog frogRacer) {
int value = Frog.randomValue(0, 1);
if (value == 0) {
frogRacer.jumpForward(2);
} else {
// do nothing
}
}
/**
* Models a frog that:
* 33 percent of the time jumps forward two cells,
* 33 percent of the time jumps forward one cell, and
* 33 percent of the time stays in the same cell.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void stayOrJumpRacerTwo(Frog frogRacer) {
int value = Frog.randomValue(0,2);
if(value == 0)
{
frogRacer.jumpForward(2);
}
else if(value == 1)
{
frogRacer.jumpForward(1);
}
else if(value==2)
{
frogRacer.jumpForward(0);
}
}
/**
* Models a frog that:
* 50 percent of the time jumps forward three cells, and
* 50 percent of the time jumps backward two cells.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void backwardOrForwardRacerOne(Frog frogRacer) {
int value = Frog.randomValue(0, 1);
if (value == 0) {
frogRacer.jumpForward(3);
} else if(value ==1) {
frogRacer.jumpBackward(2);
}
}
/**
* Models a frog that:
* 25 percent of the time jumps forward four cells,
* 25 percent of the time jumps forward one cells
* 25 percent of the time jumps backward one cells, and
* 25 percent of the time jumps backward two cells.
*
* @param frogRacer the frog that performs this behavior.
*/
static public void backwardOrForwardRacerTwo(Frog frogRacer) {
int value = Frog.randomValue(0,4);
if(value == 0)
{
frogRacer.jumpForward(4);
}
else if(value == 1)
{
frogRacer.jumpForward(1);
}
else if(value==2)
{
frogRacer.jumpBackward(1);
}
else if(value==3)
{
frogRacer.jumpBackward(2);
}
}
}
No comments:
Post a Comment