0

我一直在写纸牌游戏战争,Unity在战争功能中,我失去了 2 张牌。有没有更简单的方法可以做到这一点,或者任何人都可以让我知道我做错了什么?

while(Flipped1[Flipped1.length-1].CardValue == Flipped2[Flipped2.length-1].CardValue)
{
    for(var i= 0; i < 3; i++)
    {
        //adds a card from the players hand to the flipped pile
        Flipped1.Add(playerOneCards[0]);
        Flipped2.Add(playerTwoCards[0]);

        //removes card from the array.
        playerOneCards.RemoveAt(0);
        playerTwoCards.RemoveAt(0);
    }

    p1War = Flipped1[Flipped1.length-1].img;
    p2War = Flipped2[Flipped2.length-1].img;

    Debug.Log(Flipped1[i].CardValue);
    Debug.Log(Flipped2[i].CardValue);

    Debug.Log(Flipped1[0].CardValue);
    Debug.Log(Flipped2[0].CardValue);

    if(Flipped1[i].CardValue < Flipped2[i].CardValue)
    {                                                           
        for(var j =0; j < Flipped1.length +2 || j < Flipped2.length+2; j++)
        {
            playerTwoCards.Add(Flipped1[0]);
            playerTwoCards.Add(Flipped2[0]);

            //removes card from the array.
            Flipped1.RemoveAt(0);
            Flipped2.RemoveAt(0);
        }
    }

    else
    {
        for(var q =0; q < Flipped1.length+2|| q < Flipped2.length+2; q++)
        {
            playerOneCards.Add(Flipped2[0]);
            playerOneCards.Add(Flipped1[0]);

            //removes card from the array.
            Flipped1.RemoveAt(0);
            Flipped2.RemoveAt(0);
        }
    }
}
4

1 回答 1

0

您的问题出在 for 循环中的逻辑中(在 if/else 内)。你实际上想要做类似的东西while (Flipped1.length > 0),因为你想要做的是清空翻转数组,而不是有效地将它与一个递增的 var 减去一个常量进行比较。

于 2013-03-13T19:59:07.477 回答