Name: Anonymous 2008-10-09 17:45
I am taking a programming class outside of school in Java. Right now I am writing a program that has two feet that together are a "Zigzag" that extends a previous class I wrote called pacer. It works well except that while walking the feet seem to shuffle rather than taking steps, and upon the second turn, switch places. I was wondering if anyone could give me some tips. It would be much appreciated.
Thank You.
here is my code for reference.
import java.awt.Image;
public class ZigZag extends Pacer
{
private int stepLengths;
private int stepsCount;
// Constructor
public ZigZag(int x, int y, Image leftPic, Image rightPic)
{
super(x, y, leftPic, rightPic);
stepLengths = PIXELS_PER_INCH * 12;
}
public void firstStep()
{
if (stepsCount == 0)
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
lf.turn(45);
rf.turn(45);
stepsCount = 1;
lf.moveForward(stepLengths);
}
}
public void nextStep()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
if (stepsCount % 2 == 0)
{
rf.moveForward(stepLengths);
//rf.moveSideways(stepLengths);
}
else
{
lf.moveForward(stepLengths);
//lf.moveSideways(stepLengths);
}
stepsCount++;
}
public void turn()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
{
rf.turn(-90);
lf.turn(-90);
}
}
}
Thank You.
here is my code for reference.
import java.awt.Image;
public class ZigZag extends Pacer
{
private int stepLengths;
private int stepsCount;
// Constructor
public ZigZag(int x, int y, Image leftPic, Image rightPic)
{
super(x, y, leftPic, rightPic);
stepLengths = PIXELS_PER_INCH * 12;
}
public void firstStep()
{
if (stepsCount == 0)
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
lf.turn(45);
rf.turn(45);
stepsCount = 1;
lf.moveForward(stepLengths);
}
}
public void nextStep()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
if (stepsCount % 2 == 0)
{
rf.moveForward(stepLengths);
//rf.moveSideways(stepLengths);
}
else
{
lf.moveForward(stepLengths);
//lf.moveSideways(stepLengths);
}
stepsCount++;
}
public void turn()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
{
rf.turn(-90);
lf.turn(-90);
}
}
}