Question: I need help debugging this code public void actionPerformed ( ActionEvent e ) { if ( e . getSource ( ) = = buttonStart )

I need help debugging this code public void actionPerformed (ActionEvent e)
{
if(e.getSource()== buttonStart)
{
level =1;
score =0;
robotCount =4;
moveFactor =0.9;
robotsKilled =0;
alive = true;
nextLevel = false;
scoreString = "Level "+ level +""+ "score ="+ score;
currentScoreField.setText(scoreString);
resultsString = "Starting a game";
resultsArea.setText(resultsString);
initializeBoard (board);
placeHuman (board);
robotsX = new int[robotCount];
robotsY = new int[robotCount];
robotsAlive = new boolean[robotCount];
//set robots alive
for (int i =0; i < robotCount; i++)
{
robotsAlive[i]= true;
}
//place robots
placeRobots(robotCount, robotsX,robotsY, board);
//dislplay board
displayBoard(board);
}
//if its not the start button
else if (e.getSource()!= buttonStart && (robotsAlive == true && nextLevel == false))
{
if (e.getSource()== buttonUp)
{
moveHuman(1,board);
moveRobots(humanX, humanY, robotCount, robotsX, robotsY, robotsAlive, board, moveFactor);
}
if (e.getSource()== buttonRight)
{
moveHuman(3,board);
moveRobots(humanX, humanY, robotCount, robotsX, robotsY, robotsAlive, board, moveFactor);
}
if (e.getSource ()== buttonDown)
{
moveHuman(2,board);
moveRobots(humanX, humanY, robotCount, robotsX, robotsY, robotsAlive, board, moveFactor);
}
if (e.getSource()== buttonLeft)
{
moveHuman(4,board);
moveRobots(humanX, humanY, robotCount, robotsX, robotsY, robotsAlive, board, moveFactor);
}
nextLevel = winLevel();
}
if (nextLevel == true)
{
//update the results string
resultsString = "you win level "+ level;
resultsArea.setText(resultsString);
level++;
//update the score string
robotsKilled = deadRobots(robotCount, robotsAlive);
score += robotsKilled +100;
//update the score field
scoreString = "Level "+ level +" Score =";
currentScoreField.setText(scoreString);
//reset the robotsKilled value
robotsKilled =0;
robotCount++;
moveFactor -=0.02;
initializeBoard(board);
placeHuman(board);
alive = true;
nextLevel = false;
//creat new robot team
robotsX = new int [robotCount];
robotsY = new int [robotCount];
robotsAlive = new boolean [robotCount];
for (int i =0; i < robotCount; i++)
{
robotsAlive[i]= true;
}
placeRobots(robotCount, robotsX, robotsY, board);
alive = analyze(humanX, humanY, robotsX, robotsY, board);
if (!alive)//game over
{
robotsKilled = deadRobots (robotCount, robotsAlive);
score += robotsKilled;
scoreString = "Level" + level + "Score ="+ score;
currentScoreField.setText(scoreString);
if (((humanX ==0|| humanX ==11)||(humanY ==0|| humanY ==11)) && (!(humanY ==5 && humanX ==0)))
{
resultsString = "You were zapped by the electric fence!" +"
If you want to play again click start.";
}
else
{
resultsArea.setText(resultsString);
}
}
displayBoard(board);
}
}//end of actionPerformed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!