Handling Good Shots

If the shot is successful, the next step depends on what the user was aiming at. A successful shot on the goal means that the user has scored. If the user was aiming anywhere else, the ball should be passed to that player.

public void goodShot(){
  //if the shot succeeded

  //check to see if it's a shot on goal
  if (nextPlayer == SHOT){ 
    playerScore++;
    updateScore();
    MessageBox.Show("Goooooaaaaalllll!!!!");
    setPlayer(HALFBACK);
  } else {
    lblAnnounce.Text = playerName[nextPlayer] + " now has ball";
    setPlayer(nextPlayer);
}   // end 'scored a goal' if
} // end goodShot

The if statement checks whether the user is shooting at the goal. If so, nextPlayer is set to the same value as SHOT. The user’s score increases by 1, and the updateScore() method is employed to send a report to the scoreboard. I added a message box to enhance the mood. Finally, I gave the ball to the halfback, using the setPlayer() method.

If the user is not shooting at the goal, another player is now the current player. I copied the value of nextPlayer over to currentPlayer and set the current player visually with the setPlayer() method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.170