我无法分配图片,名称和矩形。它们作为公共变量存在于其类型的列表中(Texture2D,字符串和矩形(XNA特征,但不应该与问题相关))在具有相同名称的主类Game1中。这些是在构造函数的调用中使用的,看起来像这样......
for (int i = 0; i < names.Count - 1; i++)
{
Cards[i] = new Card(names[i], images[i], getShuffledRectangleList()[i]);
}
这个构造函数调用看起来工作得很好但我需要知道如何让Card类中的私有变量被赋予传递给构造函数的值。我可能只是把整个事情弄错了。请帮忙!感谢。
enum CardState { FaceUp, FaceDown, Matched };
class Card
{
static Texture2D CardBack;
static Texture2D MatchedCard;
private string name;
private Texture2D image;
public Rectangle rect;
private CardState cs;
static Card()
{
CardBack = Game1.CardBack;
MatchedCard = Game1.MatchedCard;
}
//constructor
public Card (string name, Texture2D image, Rectangle rect)
{
cs = CardState.FaceDown;
name = name;
}