Esempio n. 1
0
        //activate when there is a war among/between the players
        public void War(List <Card>[] onGameCards, List <Player> winners)
        {
            int           size = gamePlayer.Length;
            List <Player> win  = new List <Player>();
            //initalize->the lowest number
            Card maxi = new Card();
            //as above
            Card prs = new Card();

            for (int i = 0; i < size; i++)
            {
                //determines if the player in the war
                if (winners.Contains(gamePlayer[i]) && !gamePlayer[i].Lose())
                {
                    prs = gamePlayer[i].PopCard();
                    onGameCards[i].Add(prs);
                }
                //if the player in the war but finished his cards
                //or he is not in the war
                else
                {
                    int number = onGameCards[i].Count;
                    //if the player is not total loser
                    if (number != 0)
                    {
                        prs = onGameCards[i][number - 1];
                    }
                    else
                    {
                        prs = null;
                    }
                }
                //prs isnt empty
                if (prs != null)
                {
                    //determines who is the winner right now
                    if (prs.CompareTo(maxi) > 0) //prs is bigger than maxi
                    {
                        win.Clear();             //clear all the prev winner
                        win.Add(gamePlayer[i]);  //keep the temperary winner
                        maxi = prs;              //keep presentor for the higher card
                    }
                    else if (prs.CompareTo(maxi) == 0)
                    {
                        win.Add(gamePlayer[i]);//keep the temperary additional winner
                    }
                }
            }
            //CHECK IF THERE IS A SINGLE WINNER,or the two winners had 13 wars=>both lose
            if (win.Count == 1 || win.TrueForAll(x => x.Lose()))
            {
                for (int i = 0; i < size; i++)
                {
                    win[0].AddCard(onGameCards[i].ToArray());//because it list...
                }
            }
            //IF THERE ARE WINNERS, REPEAT ON THAT PROCEDURE AGAIN TILL WE HAVE 1 WINNER
            else
            {
                War(onGameCards, win);  //send to a recursive method
            }
        }