我有一个与下面类似的对象列表。我需要能够将这些对象添加到两个不同的列表中,然后才能通过添加和删除在这些列表之间传递对象。背景信息:我正在制作纸牌游戏(如Top Trumps)所以在游戏开始时,两位玩家都会获得随机牌。在比赛期间,如果我赢了一轮,我击败的牌应该被添加到我的牌组中并从对手中移除。
public void CardComp()
int i;
CardsComp nextCardComp;
var randomEnemyFighter=new Random();
for(i = 0; i < 3; ++i)
{
int ranEnemyF = randomEnemyFighter.Next(0, 3);
switch (ranEnemyF)
{
case 1:
nextCardComp = new CardsComp();
nextCardComp.cardNameComp = "Tyson";
nextCardComp.cardPictureComp = "Assets/tyson.png";
nextCardComp.powerComp = 96;
tysNum.Text = nextCardComp.powerComp.ToString();
nextCardComp.speedComp = 83;
tysSpeed.Text = nextCardComp.speedComp.ToString();
myListofCardsComp.Add(nextCardComp);
listOfCardsComp.ItemsSource = myListofCardsComp;
break;
case 2:
nextCardComp = new CardsComp();
nextCardComp.cardNameComp = "Groves";
nextCardComp.cardPictureComp = "Assets/groves.png";
nextCardComp.powerComp = 84;
tysNum.Text = nextCardComp.powerComp.ToString();
nextCardComp.speedComp = 88;
tysSpeed.Text = nextCardComp.speedComp.ToString();
myListofCardsComp.Add(nextCardComp);
listOfCardsComp.ItemsSource = myListofCardsComp;
break;
default:
nextCardComp = new CardsComp();
nextCardComp.cardNameComp = "Ali";
nextCardComp.cardPictureComp = "Assets/ali.png";
nextCardComp.powerComp = 86;
tysNum.Text = nextCardComp.powerComp.ToString();
nextCardComp.speedComp = 91;
tysSpeed.Text = nextCardComp.speedComp.ToString();
myListofCardsComp.Add(nextCardComp);
listOfCardsComp.ItemsSource = myListofCardsComp;
break;
}
}
myListofCardsComp = new List<CardsComp>();