18. Keeping score

Every game has a way to put a value to the player's effort. In racing games that's done with time (in most cases). In tycoon games, that would be done with money. In our game, we'll just use numbers. So how should we evaluate our players effort? First of all, we have to give him points for every block he destroys. We could make our game give him more points with every new level, and some extra points for the number of different block colors for that level. And some extra scoring math: We could make every block color more valuable... So, let's start with adding a new label to our form, so we could display the score to the player.

The score label properties:

Label

  • (name): lblScore
  • BackgroundColor: Web > Transparent
  • Location: 555;65
  • Font: Microsoft Sans Serif; 9,75pt; style=Bold
  • Text: 0

Then, add this code to your project:
(put it in the DoTheScoreMath() method.)

// We'll process the score only
// if there's multiple blocks
// in the 'Connected List'.

if (ConnectedList.Count > 1)

  // I've declared some
  // variables to hold
  // some values I intend
  // on using to calculate
  // the score.

  int a = ConnectedList.Count;
  int b = iLevel;
  int c = iColor;
  int d = ConnectedList0.iFieldColor;

  // Scoring formula...
  // You can play with it
  // as you like :)

  int e = a * (b + c) * d;
  
  // Just don't forget to
  // add it to the total
  // score:

  iScore += e;

// Oh, and to be a little
// naughty, we'll substract
// a point for every click
// the user makes...
// BUAHAAHAAHHAAAAA!

iScore--;

// Display the total score:
lblScore.Text = iScore.ToString();

Now, add the call in the 'picGF_MouseClick' method, after the existing code:

DoTheScoreMath()

Done? Cool! Ok, what now? Levels would be cool... Right, then! Next chapter: Levels!

source:here