问题描述
我对C#和团结有些陌生,对我而言却是空虚的。我正在制作一个纸牌游戏,该游戏使用镜像连接两个玩家,目前在抽奖牌部分。我已经上传了所有卡,当卡库用完时,它到达了那里,它会随机播放然后重新分发卡。我可能应该更深入。我的意图是将一个列表洗牌,然后分成两个列表,每个玩家分别从中提取。但是,我的问题是,代码使两个客户端都执行了原始列表的创建,改组和重新分配。他们俩都随机抽牌,但问题是他们仍然有机会与对手玩相同的牌。
[Command]
public void CmdDealCards()
{
if ((CardsLeftInLibrary == 0) || (OpponentLibraryCount == 0))
{
Shuffler(cards,PlayerDeck,OpponentDeck); // Shuffles the deck,creates two smaller deck lists,each should have what the other does not.
CardsLeftInLibrary = PlayerDeck.Count;
OpponentLibraryCount = OpponentDeck.Count;
Debug.Log("finishing this if statemnt by changing cards left in library value.");
}
if (hasAuthority)
{
CardsLeftInLibrary = CardsLeftInLibrary - 1;
GameObject Card = Instantiate(PlayerDeck[CardsLeftInLibrary],new Vector2(0,0),Quaternion.identity);
NetworkServer.Spawn(Card,connectionToClient);
RpcShowCard(Card,"Dealt Hand");
}
else if (!hasAuthority)
{
OpponentLibraryCount = OpponentLibraryCount - 1;
GameObject Card = Instantiate(OpponentDeck[OpponentLibraryCount],"Dealt Hand");
}
UIManager.UpdatePlayerText(CardsLeftInLibrary,OpponentLibraryCount);
}
public void Shuffler<T>(List<T> list,List<T> playerList,List<T> OpponentList)
{
System.Random random = new System.Random();
int n = list.Count;
while (n>1)
{
int k = random.Next(n);
n--;
T temp = list[k];
list[k] = list[n];
list[n] = temp;
Debug.Log(list[n]);
}
for (int i = 0; i < list.Count; i++)
{
if (i < 27)
{
playerList[i] = list[i];
//Debug.Log("PLAYERLIST: ");
//Debug.Log(playerList[i]);
}
else
{
OpponentList[i - 27] = list[i];
//Debug.Log("ENEMYLIST: ");
//Debug.Log(OpponentList[i-27]);
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)