示例#1
0
 public bool CompareTo(Card card)
 {
     if (card.TwinId == this.TwinId)
         return true;
     else
         return false;
 }
示例#2
0
文件: Card.cs 项目: mhvr/Pexeso
        public static List<Card> CreateCards()
        {
            List<Card> cards = new List<Card>();
            Random random = new Random(DateTime.Now.Millisecond);
            int[] array = new int[10];

            BitmapImage backSide = GetImage("Images/Cover.png");

            for (int i = 0; i < 10; i++)
            {
                int randomNumber = random.Next(1, 46);

                if (!array.Contains(randomNumber))
                {
                    array[i] = randomNumber;

                    BitmapImage frontSide = GetImage(String.Format("Images/{0}.png", randomNumber));

                    Card a = new Card(i, frontSide, backSide);
                    Card b = new Card(i, frontSide, backSide);

                    cards.Add(a);
                    cards.Add(b);
                }
                else
                {
                    i--;
                }
            }

            return cards;
        }
示例#3
0
 public void MouseClick(int xForm, int yForm)
 {
     if (waiting || hasWon)
         return;
     int xGrid = (xForm - xBegin) / colWidth;
     int yGrid = (yForm - yBegin) / colHeight;
     if (xGrid >= 0 && xGrid < cards.GetLength(0) && yGrid >= 0 && yGrid < cards.GetLength(1) && numberOfShownCards < 2)
     {
         ++numberOfShownCards;
         if (numberOfShownCards == 1)
             currentCard1 = cards[xGrid, yGrid];
         else if (numberOfShownCards == 2)
         {
             currentCard2 = cards[xGrid, yGrid];
             if (currentCard1.CompareTo(currentCard2))
             {
                 currentCard1.Win();
                 currentCard2.Win();
                 counter.SuccessfulTurn(currentCard1.Uid, currentCard2.Uid);
                 hasWon = HasWon();
                 HideNotWonCards();
             }
             else
             {
                 counter.Turn(currentCard1.Uid, currentCard2.Uid);
                 form.EnableTimerHideNotWonCards();
             }
         }
         cards[xGrid, yGrid].TurnUp();
         form.Invalidate();
         if (hasWon)
             form.ShowWonDialog(counter);
     }
 }