예제 #1
0
        public void StopRequestCard(int id)
        {
            //stopThreadWait = true;


            //stopThreadWait = false;
            var user = usersInGame.FirstOrDefault(i => i.ID == id);

            if (user != usersInGame.Last())
            {
                currentUserId = usersInGame[usersInGame.IndexOf(user) + 1].ID;
                user          = usersInGame.FirstOrDefault(i => i.ID == currentUserId);
                SendMessage(": Очередь игрока " + user.Name, 0);
                user.operationContext.GetCallbackChannel <IServerGameCallback>().NewCurrentUserCallback();
                RequestCard(currentUserId);
            }
            else
            {
                stopThreadWait  = true;
                startThreadWait = false;
                isGameStart     = false;
                foreach (var item in usersInGame)
                {
                    item.IsPrepare = false;
                }
                SendMessage(": Игра окончена ", 0);
                currentUserId = 0;
                foreach (User item in usersInGame)
                {
                    SendMessage(": " + item.Name + " имеет " + item.amountPoints() + " очков", 0);
                }
                int winPoints = usersInGame.Min(x => Math.Abs(x.amountPoints() - 21));

                List <User> winners = (from u in usersInGame
                                       where Math.Abs(u.amountPoints() - 21) == winPoints
                                       select u).ToList();
                foreach (User item in winners)
                {
                    SendMessage(": " + item.Name + " победил", 0);
                }


                foreach (User item in usersInGame)
                {
                    item.Coins = winners.Contains(item) ? item.Coins + 50 : item.Coins - 50;
                }

                CheckConnectClients();
                foreach (User item in usersInGame)
                {
                    item.operationContext.GetCallbackChannel <IServerGameCallback>().AmountCoinsCallback(item.Coins);

                    item.cards = new List <Card>();
                    item.operationContext.GetCallbackChannel <IServerGameCallback>().GameFinishCallback();
                }
                foreach (User item in usersInGame)
                {
                    item.operationContext.GetCallbackChannel <IServerGameCallback>().NewGameCallback();
                }
                cardDeck = new CardDeck(52);

                //threadWait.Join();
                //threadWait = null;
            }
        }