Пример #1
0
        /// <summary>
        /// Event that occurs when the user double clicks the mouse on the form
        /// checks if it is valid card or not first
        /// If valid add to Pot
        /// updates card position
        /// updates turn
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int activePlayerId = gameData.ActivePlayerId;

            if (gameData.CurrentPlayerList[boardBelongsTo].IsActivePlayer == false)
            {
                return;
            }

            // look for the card index from the mouse click
            int mouseX = e.X;
            int mouseY = e.Y;

            // now calculate the card position form player initial position of refrence
            // count how many cards are there in the pile
            int cardCount = gameData.CurrentPlayerList[activePlayerId].Hand.CardPile.Count;

            // check for valid click
            // 71 is card width 97 is height
            if (cardCount > 0 && IsAnimating == false)
            {
                if (mouseX >= playerPositions[activePlayerId].x && mouseX <= ((playerPositions[activePlayerId].x + 56) + (15 * cardCount)))
                {
                    // check for y coordinate
                    if (mouseY >= playerPositions[activePlayerId].y && mouseY <= (playerPositions[activePlayerId].y + 97))
                    {
                        //valid coordinate
                        // calculate card index clicked
                        int index = (int)(mouseX - playerPositions[activePlayerId].x) / 15;

                        // if index is more than last index then make it last index
                        if (index > (gameData.CurrentPlayerList[activePlayerId].Hand.CardPile.Count - 1))
                        {
                            index = gameData.CurrentPlayerList[activePlayerId].Hand.CardPile.Count - 1;
                        }



                        if (GameRule.isValidCard(gameData.CurrentPlayerList[activePlayerId], (SpadesCard)gameData.CurrentPlayerList[activePlayerId].Hand.CardPile[index], gameData.CurrentPot))
                        {
                            // check if its a  valid card
                            // place the card in pot card
                            SpadesCard potCard = (SpadesCard)gameData.CurrentPlayerList[activePlayerId].Hand.CardPile[index];
                            // remove from hand
                            gameData.CurrentPlayerList[activePlayerId].Hand.CardPile.RemoveAt(index);

                            potCard.CardPositionX = playerPositions[activePlayerId].x + 80;
                            potCard.CardPositionY = playerPositions[activePlayerId].y - 120;

                            gameData.CurrentPot.AddPot(potCard, gameData.CurrentPlayerList[activePlayerId]);



                            this.updateTurn(activePlayerId);
                        }
                    }
                }
            }
        }
Пример #2
0
        public SpadesCard makeMove(GameData gameData)
        {
            Pot pot = gameData.CurrentPot;
            List <SpadesCard> validCardList = new List <SpadesCard>();
            player            currentPlayer = gameData.CurrentPlayerList[gameData.ActivePlayerId];

            // make some move
            // get all valid card move to narrow down the search scope first

            if (pot.Count() == 0)
            {
                foreach (SpadesCard card in currentPlayer.Hand.CardPile)
                {
                    validCardList.Add(card);
                }// any hand card is valid to play ..
            }
            else
            {
                foreach (SpadesCard card in currentPlayer.Hand.CardPile)
                {
                    if (GameRule.isValidCard(currentPlayer, card, pot))
                    {
                        validCardList.Add(card);
                    }
                }
            }

            int count = validCardList.Count;


            // throw some random card now
            if (count > 0)
            {
                DateTime x    = DateTime.Now;
                float    mins = x.Minute;
                float    secs = x.Second;
                float    hour = x.Hour;
                if (gameData.ActivePlayerId != 0)
                {
                    rand = new Random(Convert.ToInt32(((secs * mins) + hour) / gameData.ActivePlayerId));
                }
                else
                {
                    rand = new Random(Convert.ToInt32(((secs * mins) + hour)));
                }

                SpadesCard c;

                int index = rand.Next(0, validCardList.Count - 1);
                c = (SpadesCard)validCardList[index];
                return(c);
            }
            else
            {
                return(null);
            }
        }