示例#1
0
 /// <summary>
 /// This method is used when the user trhrows a card in the table
 /// </summary>
 /// <param name="clickedPoint">where the user clicked on the table</param>
 /// <param name="thisPlayer">who is playing</param>
 /// <param name="tableLimits">limits of the playing table</param>
 /// <param name="selectedCard">which card is been trown</param>
 /// <param name="cardSlots">spaces allowed to place cards</param>
 /// <returns>returns true if a valid place on the playing table was clicked</returns>
 public bool ProcessMesaClicked(
     Point clickedPoint,
     int thisPlayer,
     Rectangle tableLimits,
     Naipe selectedCard,
     CardSlots cardSlots)
 {
     if (tableLimits.Contains(clickedPoint.X, clickedPoint.Y))
     {
         NaipesEnMesa.NaipesEnGrupo.Add(selectedCard);
         Manos[thisPlayer].NaipesEnGrupo.Remove(selectedCard);
         selectedCard.Selected = false;
         oneInHandSelected     = false;
         for (int i = 0; i < 10; i++)
         {
             if (!cardSlots.UsedTableCardPosition[i])
             {
                 selectedCard.SetCenter(cardSlots.TableCardPosition[i]);
                 cardSlots.UsedTableCardPosition[i] = true;
                 selectedCard.SlotAssigned          = CardSlots.getGroupIndexCardsInTable(i);
                 break;
             }
         }
         return(true);
     }
     return(false);
 }
示例#2
0
        /// <summary>
        /// Make a movement once the player has clicked the button Make Move
        /// </summary>
        /// <param name="thisPlayer">Which player is this</param>
        /// <param name="thisTeam">Which team the player belongs to</param>
        /// <param name="cardSlots">Slots or places to lay down cards in the game</param>
        /// <returns>Returns True if a valid move was completed</returns>
        public bool MakeMove(int thisPlayer, int thisTeam, CardSlots cardSlots)
        {
            List <Naipe> touchedCardsOnTable = new List <Naipe>();
            Naipe        selectedCardOnHand  = new Naipe();

            //Get a list of touched cards on table
            foreach (Naipe card in NaipesEnMesa.NaipesEnGrupo)
            {
                if (card.Touched)
                {
                    touchedCardsOnTable.Add(card);
                }
            }

            //Get a list of the selected card on hand
            foreach (Naipe card in Manos[thisPlayer].NaipesEnGrupo)
            {
                if (card.Selected)
                {
                    selectedCardOnHand = card;
                    break;
                }
            }

            //No matter if the move is complited, the selected card on hand will be unselected
            foreach (Naipe card in Manos[thisPlayer].NaipesEnGrupo)
            {
                card.Selected = false;
                card.MoveToOriginalPosition();
            }
            oneInHandSelected = false;

            //No matter if the move is complited, the selected cards on the table will be unselected
            foreach (Naipe card in NaipesEnMesa.NaipesEnGrupo)
            {
                card.Touched = false;
            }
            oneInMesaTouched = false;

            //Sort the list of touched Table Cards
            touchedCardsOnTable.Sort(new NaipesComparer());
            //Execute this if the move is valid
            if (ProcessMove(selectedCardOnHand, touchedCardsOnTable))
            {
                //Remove the selected card on hand and selected cards on table
                Manos[thisPlayer].NaipesEnGrupo.Remove(selectedCardOnHand);
                foreach (Naipe card in touchedCardsOnTable)
                {
                    Pair <CardGroup, int> slot = card.SlotAssigned;
                    cardSlots.UsedTableCardPosition[slot.Second] = false;
                    NaipesEnMesa.NaipesEnGrupo.Remove(card);
                }

                //Move the cards to their new position (Carton)
                selectedCardOnHand.SetCenter(cardSlots.CartonCardPosition[thisTeam, 0]);
                selectedCardOnHand.SlotAssigned = CardSlots.getGroupIndexCartonCards(thisTeam, 0);
                Carton[thisTeam].AnadirArriba(selectedCardOnHand);
                foreach (Naipe card in touchedCardsOnTable)
                {
                    card.SetCenter(cardSlots.CartonCardPosition[thisTeam, 0]);
                    card.SlotAssigned = CardSlots.getGroupIndexCartonCards(thisTeam, 0);
                    Carton[thisTeam].AnadirArriba(card);
                }

                return(true);
            }
            //Execute this if it was not a valid move
            else
            {
                return(false);
            }
        }