mercredi 22 avril 2015

Is is possible (or advisable) for a method to recognize it's caller?

I'm developing a simple game where a player needs to roll a die and then "the computer" needs to do it.

I would like a roll method that performs slightly differently for each type of player.

It's currently set up with a BOOL parameter called isPlayer (vs. isComputer). Players pass a TRUE value, computer a FALSE. There's some if statements in the method that act accordingly.

This seems clunky to me. Is there a better way?

I was thinking of creating a PlayerType enum and each player would have a type but they would still need to pass the type to the method. That or they could change a game variable to that type and the method could recognize that.

Any thoughts would be helpful. Thanks.

Aucun commentaire:

Enregistrer un commentaire