Ejemplo n.º 1
0
 public override PlayerAction HandleInput(GameTime gameTime, GameState state)
 {
     // Local input
     if (GameCursor.LeftMouseState(gameTime) == MouseAction.CLICK)
     {
         // Check if you can't play
         if (state.GetDeck().Contains(GameCursor.MousePosition()) && state.GetDeck().CanDrawCard() && GameCursor.SelectedCards.Count == 0)
         {
             return(new PlayerAction(PlayerActionType.TRY_CARD));
         }
         else if (state.GetPile().Contains(GameCursor.MousePosition()) && GameCursor.SelectedCards.Count == 0 && state.GetPile().Pile.Count > 0)
         {
             return(new PlayerAction(PlayerActionType.PICK_UP_CARDS));
         }
         else
         {
             Card card = SelectedCard(GameCursor.MousePosition());
             if (card != null && GameCursor.SelectedCards.Count == 0 && (selectedCards.Count == 0 || selectedCards.ElementAt(0).CompareTo(card) == 0))
             {
                 List <Card> tempCards = new List <Card>();
                 tempCards.AddRange(selectedCards);
                 if (!selectedCards.Contains(card))
                 {
                     tempCards.Add(card);
                 }
                 selectedCards.Clear();
                 GameCursor.SelectedCards.AddRange(tempCards);
             }
         }
     }
     else if (GameCursor.RightMouseState(gameTime) == MouseAction.CLICK)
     {
         Card card = SelectedCard(GameCursor.MousePosition());
         if (card != null && !GameCursor.SelectedCards.Contains(card))
         {
             if (selectedCards.Contains(card))
             {
                 selectedCards.Remove(card);
             }
             else if (selectedCards.Count == 0)
             {
                 selectedCards.Add(card);
             }
             else if (selectedCards.ElementAt(0).CompareTo(card) == 0)
             {
                 selectedCards.Add(card);
             }
         }
     }
     else if (GameCursor.LeftMouseState(gameTime) == MouseAction.RELEASE)
     {
         if (state.GetPile().Contains(GameCursor.MousePosition()) && GameCursor.SelectedCards.Count > 0)
         {
             Card[] cards = GameCursor.SelectedCards.ToArray();
             foreach (Card card in cards)
             {
                 card.ResetPosition();
             }
             GameCursor.SelectedCards.Clear();
             return(new PlayerAction(PlayerActionType.PLAY_CARD, cards));
         }
         else
         {
             PlayerAction action = null;
             foreach (Card tableCard in tableCards)
             {
                 if (tableCard.Contains(GameCursor.MousePosition()) && GameCursor.SelectedCards.Count > 0)
                 {
                     action = new PlayerAction(PlayerActionType.SWAP_CARD, GameCursor.SelectedCards[0], tableCard);
                 }
             }
             foreach (Card card in GameCursor.SelectedCards)
             {
                 card.ResetPosition();
             }
             GameCursor.SelectedCards.Clear();
             return(action);
         }
     }
     return(null);
 }