Beispiel #1
0
 public void Split(int playerId, int handId)
 {
     SplitMessageToServer msg = new SplitMessageToServer();
     msg.nickname = ServiceLocator.Get<LoginViewModel>().Nickname;
     msg.playerId = playerId;
     msg.handId = handId;
     gameReceiver.SendToServiceAsync(msg);
 }
Beispiel #2
0
        public void PlayerSplit(SplitMessageToServer msg, Deck deck)
        {
            rwl.AcquireWriterLock(10000);
            string filename = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"/Table1.xml";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(filename);
            XmlNode hands = xmlDoc.SelectSingleNode("/Table/Players/Player[@PlayerId='" + msg.playerId + "']/Hands");
            XmlElement newHand = xmlDoc.CreateElement("Hand");
            XmlElement newCards = xmlDoc.CreateElement("Cards");
            XmlElement newChips = xmlDoc.CreateElement("Chips");
            newHand.SetAttribute("HandId", (msg.handId + 1).ToString());

            XmlNode card = null;
            XmlNodeList cards = xmlDoc.SelectNodes("/Table/Players/Player[@PlayerId='" + msg.playerId + "']/Hands/Hand[@HandId='" + msg.handId + "']/Cards/Card");
            for (int i = 0; i < cards.Count; i++)
            {
                if (i == 1)
                    card = cards[i];
            }
            newCards.AppendChild(card);

            XmlNode hand = xmlDoc.SelectSingleNode("/Table/Players/Player[@PlayerId='" + msg.playerId + "']/Hands/Hand[@HandId='" + msg.handId + "']");
            XmlElement firstCard = xmlDoc.CreateElement("Card");
            firstCard.SetAttribute("CardRank", deck[0].Rank);
            firstCard.SetAttribute("CardSuit", deck[0].Suit);
            firstCard.SetAttribute("CardValue", deck[0].CardValue.ToString());
            hand.FirstChild.AppendChild(firstCard);
            deck.RemoveAt(0);

            XmlElement secondCard = xmlDoc.CreateElement("Card");
            secondCard.SetAttribute("CardRank", deck[0].Rank);
            secondCard.SetAttribute("CardSuit", deck[0].Suit);
            secondCard.SetAttribute("CardValue", deck[0].CardValue.ToString());
            newCards.AppendChild(secondCard);
            deck.RemoveAt(0);

            newHand.AppendChild(newCards);

            XmlNode chips = xmlDoc.SelectSingleNode("/Table/Players/Player[@PlayerId='" + msg.playerId + "']/Hands/Hand[@HandId='" + msg.handId+1 + "']/Chips");
            XmlNodeList currentChips = xmlDoc.SelectNodes("/Table/Players/Player[@PlayerId='" + msg.playerId + "']/Hands/Hand[@HandId='" + msg.handId + "']/Chips/Chip");
            for (int i = 0; i < currentChips.Count; i++)
            {
                XmlElement newChip = xmlDoc.CreateElement("Chip");
                newChip.SetAttribute("ChipAmount", currentChips[i].Attributes["ChipAmount"].Value);
                newChips.AppendChild(newChip);
            }
            newHand.AppendChild(newChips);

            hands.AppendChild(newHand);
            xmlDoc.Save(filename);
            rwl.ReleaseWriterLock();
        }