Exemplo n.º 1
0
        /// <summary>
        /// Gathers the cards in the specified rectangle.
        /// </summary>
        /// <param name="gatheringRectangle">The gathering rectangle.</param>
        public void GatherCards(Rectangle gatheringRectangle)
        {
            SharedObject gatheringStackSharedObject = null;

            for (int i = ZOrderListOfSharedObjects.Count - 1; i >= 0; i--)
            {
                SharedObject sharedObject = ZOrderListOfSharedObjects[i];
                if (gatheringRectangle.Contains(sharedObject.Rectangle) && sharedObject.GrabberName == null &&
                    sharedObject.GameElements.First() is Card)
                {
                    gatheringStackSharedObject = sharedObject;
                    break;
                }
            }
            if (gatheringStackSharedObject != null)
            {
                gatheringStackSharedObject.SetAllCardsSameFace(false);
                List <SharedObject> listSharedObjectsToGather = new List <SharedObject>();
                for (int i = ZOrderListOfSharedObjects.Count - 1; i >= 0; i--)
                {
                    SharedObject sharedObject = ZOrderListOfSharedObjects[i];
                    if (gatheringRectangle.Contains(sharedObject.Rectangle) && sharedObject.GrabberName == null &&
                        sharedObject.GameElements.First() is Card && sharedObject != gatheringStackSharedObject)
                    {
                        sharedObject.SetAllCardsSameFace(false);
                        listSharedObjectsToGather.Add(sharedObject);
                    }
                }
                foreach (SharedObject sharedObject in listSharedObjectsToGather)
                {
                    GatherCards(sharedObject, gatheringStackSharedObject);
                }

                // gatheringStackSharedObject.Shuffle();

                // Broadcast the gathering shared object move event:
                StateChangeEventDataType stateChangeEventDataType = new StateChangeEventDataType();
                stateChangeEventDataType.StateChangeEventType    = StateChangeEventType.SharedObjectMove;
                stateChangeEventDataType.SharedObjectId          = gatheringStackSharedObject.Id;
                stateChangeEventDataType.NewSharedObjectLocation = gatheringStackSharedObject.Location;
                stateChangeEventDataType.SharedObjectSize        = gatheringStackSharedObject.Rectangle.Size;
                stateChangeEventDataType.NewSharedObjectPicture  = gatheringStackSharedObject.Picture;
                ScgBroadcastorService.BroadcastStateChange(stateChangeEventDataType, null, null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gathers the cards of sharedObject in the GameElments of gatheringObject.
        /// </summary>
        /// <param name="sharedObject">The shared object.</param>
        /// <param name="gatheringObject">The gathering object.</param>
        public void GatherCards(SharedObject sharedObject, SharedObject gatheringObject)
        {
            if (sharedObject.GameElements.First() is Card && gatheringObject.GameElements.First() is Card)
            {
                if (gatheringObject.GameElements.Count == 1)
                {
                    // The gathering object was a single card. Change its size for a stack of cards:
                    gatheringObject.Rectangle = new Rectangle(gatheringObject.Rectangle.X, gatheringObject.Rectangle.Y, DimXStackOfCards, DimYStackOfCards);
                    // and apply again magnetic grid:
                    gatheringObject.Rectangle = new Rectangle(GetMagneticLocation(gatheringObject.Rectangle), gatheringObject.Rectangle.Size);
                }
                // Transfer the cards:
                try
                {
                    foreach (Card card in sharedObject.GameElements)
                    {
                        gatheringObject.GameElements.Insert(0, card);
                    }
                }
                catch (Exception ex)
                {
                    ScgBroadcastorService.LogError(string.Format("Unexpected exception '{0}' in GameState.GatherCards in foreach loop doing gatheringObject.GameElements.Add(card);", ex.Message), 97);
                    throw;
                }

                // Broadcast the gathering shared object move event:
                StateChangeEventDataType stateChangeEventDataType = new StateChangeEventDataType();
                stateChangeEventDataType.StateChangeEventType    = StateChangeEventType.SharedObjectMove;
                stateChangeEventDataType.SharedObjectId          = gatheringObject.Id;
                stateChangeEventDataType.NewSharedObjectLocation = gatheringObject.Location;
                stateChangeEventDataType.SharedObjectSize        = gatheringObject.Rectangle.Size;
                stateChangeEventDataType.NewSharedObjectPicture  = gatheringObject.Picture;
                ScgBroadcastorService.BroadcastStateChange(stateChangeEventDataType, null, null);

                // Remove the source shared object and broadcast the dispose event:
                ZOrderListOfSharedObjects.Remove(sharedObject);
                stateChangeEventDataType.StateChangeEventType = StateChangeEventType.DisposeSharedObject;
                stateChangeEventDataType.SharedObjectId       = sharedObject.Id;
                ScgBroadcastorService.BroadcastStateChange(stateChangeEventDataType, null, null);
            }
        }
Exemplo n.º 3
0
        public ScgGameState(ScgBroadcastorService scgBroadcastorService)
        {
            ScgBroadcastorService     = scgBroadcastorService;
            ZOrderListOfSharedObjects = new List <SharedObject>();

            char[] suitChars =
            {
                'S',
                'H',
                'D',
                'C'
            };
            char[] heightChars =
            {
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8',
                '9',
                'T',
                'J',
                'Q',
                'K',
                'A'
            };
            var intTable = new List <int>();

            for (var i = 0; i < 52; i++)
            {
                intTable.Add(i);
            }

            /*
             * //To shuffle up the initial positions of cards
             * var shuffelingTable = new int[52];
             * var rnd = new Random();
             * for (var i = 0; i < 52; i++)
             * {
             *  var index = rnd.Next(intTable.Count);
             *  shuffelingTable[i] = intTable[index];
             *  intTable.RemoveAt(index);
             * }
             */

            var id = 0;

            //int iSuitShuffeled;
            //int iHeightShuffeled;
            for (var iSuit = 0; iSuit < 4; iSuit++)
            {
                for (var iHeight = 0; iHeight < 13; iHeight++)
                {
                    var picture = "Crd" + heightChars[iHeight] + suitChars[iSuit];

                    /*
                     * //To shuffle up the initial positions of cards
                     * var cardIndex = shuffelingTable[iSuit*13 + iHeight];
                     * iHeightShuffeled = cardIndex/4;
                     * iSuitShuffeled = cardIndex%4;
                     *
                     * // Expose the cards face down and shuffled up
                     * ZOrderListOfSharedObjects.Insert(0,
                     *  new SharedObject(ZOrderListOfSharedObjects, id,
                     *      new Rectangle(220 + iHeightShuffeled * MagneticGridStep * 5, 180 + iSuitShuffeled * MagneticGridStep * 7, DimXCard, DimYCard), null,
                     *      new List<GameElement>(new[] {new Card(picture, "CrdBackB", "Stk", false)})));
                     */

                    // Expose the cards face up and not shuffled up
                    ZOrderListOfSharedObjects.Insert(0,
                                                     new SharedObject(ZOrderListOfSharedObjects, id,
                                                                      new Rectangle(220 + iHeight * MagneticGridStep * 5, 180 + iSuit * MagneticGridStep * 7, DimXCard, DimYCard), null,
                                                                      new List <GameElement>(new[] { new Card(picture, "CrdBackB", "Stk", true) })));
                    id++;
                }
            }
        }