May be this is a newbie question but here it is.
I am developing a card game and i hava a class named Player …
Player has a property called Partner ( another Player ) and another property called Points.
public class Player
{
public Player()
{
}
public Player Partner { get; set; }
private int points = 0;
public int Points
{
get { return points;}
set {
if (Partner != null) Partner.Points = value;
points = value;
} // -> Here is the problem cause p1.Partner = p2 and p2.Partner = p1
}
The question is : How is the most “elegant way” to set the Points property for a player and have its Partner points property set automatically ?
For instance:
Player p1 = new Player();
Player p2 = new Player();
p1.Partner = p2;
p2.Partner = p1;
p1.Points = 10;
int p = p2.Points
p should be equal to 10.
Thanks in advance ,
Marcelo
Brazil< .
Will fix the circular reference, but having a
Partnershipobject that they both refer to get the total points will be cleaner and allows each player to store the individual points they’ve scored too.