Hit points - sort of.

Hi all,

I am building a type of design game for a community - and we need to be able to give everyone that plays the game a set amount of "points" or "dollars." Some options (say a HUGE community center) will cost all of their points when selected, other items may allow them to install four or five new elements within a community. The selection will be made through the GUI which will move a building, feature, or element into place, provide a quick tour w/ VO, and then take away points. If the player decides to "un-choose" something, i will need to give the points back. And finally, a "done" button that would report decisions.

So, i need a push in the right direction to equate this type of function to a character taking a number of hits in a game - i think? Subtracting, or giving back points as decisions are made similar to what you would do in a RTS or tower defense game.

I will post a separate question on reporting decisions after resolution of the "hit points."

THANKS!

Sounds like you have a pretty good idea of what you need to do. Here's how I'd go about structuring a system like that.

Two Ints:

int EarnedPoints
int CurrentPoints

public void PlayerEarnedPoints(int pointsEarned) {
  EarnedPoints += pointsEarned;
}

public bool SpendPlayerPoints(int pointsSpent) {

if(pointsSpent <= CurrentPoints) {
 CurrentPoints -= pointsSpent;
 return true;
} else {
 return false;
}

}

And to return points, you just create a reverse version of SpendPlayerPoints. You'll want to be careful you don't "create" points by always accounting for where your points are coming and going (using private variables to hold everything helps a lot.