Example #1
0
        private void GetNewCard(CardClass item)
        {
            if ((turn == Players.First && item.PlayerOwner == CardOwner.First) ||
                (turn == Players.Second && item.PlayerOwner == CardOwner.Second))
            {
                if ((item.PlayerOwner == CardOwner.First && !firstPlayerBlocked) ||
                    (item.PlayerOwner == CardOwner.Second &&
                     ((!secondPlayerBlocked && opponent == Opponents.Player) ||
                      (secondPlayerBlocked && opponent == Opponents.Bot))))
                {
                    var index = item.PlayerOwner == CardOwner.First
                        ? firstPlayerGameCards.IndexOf(item)
                        : secondPlayerGameCards.IndexOf(item);

                    if (item.PlayerOwner == CardOwner.Second)
                    {
                        cards[indexArray[counter]].SetImagePosition(182 + index * 128, 32);
                        cards[indexArray[counter]].PlayerOwner = CardOwner.Second;
                        secondPlayerGameCards[index]           = cards[indexArray[counter]];
                        cards[indexArray[counter]].SetVisible(opponent == Opponents.Player);
                    }
                    else
                    {
                        cards[indexArray[counter]].SetImagePosition(182 + index * 128, 504);
                        cards[indexArray[counter]].PlayerOwner = CardOwner.First;
                        firstPlayerGameCards[index]            = cards[indexArray[counter]];
                        cards[indexArray[counter]].SetVisible(true);
                    }

                    cards[indexArray[counter]].ImageBox.BringToFront();
                    cards[indexArray[counter]].Status = CardStatus.Player;
                    ++counter;
                }
            }
        }
 private void MainForm_Load(object sender, EventArgs e)
 {
     var str = new StreamReader(CardClass.LocalPath + "info.txt");
     for (var i = 0; i < 150; i++)
     {
         var line = str.ReadLine();
         Debug.Assert(line != null, "line != null");
         var data = line.Split(';');
         var value = 0;
         var name = data[0];
         try
         {
             value = int.Parse(data[1]);
         }
         catch
         {
             MessageBox.Show("Error parse");
         }
         var nation = data[2];
         cards[i] = new CardClass(name, nation, i + 1, value);
         cards[i].OnCardClick += GetNewCard;
         cards[i].OnCardClick += MoveCurrentCard;
         cards[i].OnCardClick += ActivateBot;
         Controls.Add(cards[i].ImageBox);
     }
     skip1.Enabled = false;
     skip2.Enabled = false;
     skip1.Visible = false;
     skip2.Visible = false;
     RoundLabel.Visible = false;
     TimeLabel.Visible = false;
     NumberOutCards1Label.Visible = false;
     NumberOutCards2Label.Visible = false;
 }
Example #3
0
 private void ActivateBot(CardClass cardClass)
 {
     if (turn == Players.Second && opponent == Opponents.Bot && round < NumberOfRounds)
     {
         Bot();
     }
 }
        private void GetNewCard(CardClass item)
        {
            if ((turn == Players.First && item.PlayerOwner == CardOwner.First) ||
                (turn == Players.Second && item.PlayerOwner == CardOwner.Second))
            {
                if ((item.PlayerOwner == CardOwner.First && !firstPlayerBlocked) ||
                    (item.PlayerOwner == CardOwner.Second && 
                    ((!secondPlayerBlocked && opponent == Opponents.Player) ||
                    (secondPlayerBlocked && opponent == Opponents.Bot))))
                {
                    var index = item.PlayerOwner == CardOwner.First
                        ? firstPlayerGameCards.IndexOf(item)
                        : secondPlayerGameCards.IndexOf(item);

                    if (item.PlayerOwner == CardOwner.Second)
                    {
                        cards[indexArray[counter]].SetImagePosition(182 + index*128, 32);
                        cards[indexArray[counter]].PlayerOwner = CardOwner.Second;
                        secondPlayerGameCards[index] = cards[indexArray[counter]];
                        cards[indexArray[counter]].SetVisible(opponent == Opponents.Player);
                    }
                    else
                    {
                        cards[indexArray[counter]].SetImagePosition(182 + index*128, 504);
                        cards[indexArray[counter]].PlayerOwner = CardOwner.First;
                        firstPlayerGameCards[index] = cards[indexArray[counter]];
                        cards[indexArray[counter]].SetVisible(true);
                    }

                    cards[indexArray[counter]].ImageBox.BringToFront();
                    cards[indexArray[counter]].Status = CardStatus.Player;
                    ++counter;
                }
            }
        }
Example #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            var str = new StreamReader(CardClass.LocalPath + "info.txt");

            for (var i = 0; i < 150; i++)
            {
                var line = str.ReadLine();
                Debug.Assert(line != null, "line != null");
                var data  = line.Split(';');
                var value = 0;
                var name  = data[0];
                try
                {
                    value = int.Parse(data[1]);
                }
                catch
                {
                    MessageBox.Show("Error parse");
                }
                var nation = data[2];
                cards[i]              = new CardClass(name, nation, i + 1, value);
                cards[i].OnCardClick += GetNewCard;
                cards[i].OnCardClick += MoveCurrentCard;
                cards[i].OnCardClick += ActivateBot;
                Controls.Add(cards[i].ImageBox);
            }
            skip1.Enabled                = false;
            skip2.Enabled                = false;
            skip1.Visible                = false;
            skip2.Visible                = false;
            RoundLabel.Visible           = false;
            TimeLabel.Visible            = false;
            NumberOutCards1Label.Visible = false;
            NumberOutCards2Label.Visible = false;
        }
Example #6
0
 private void MoveCurrentCard(CardClass item)
 {
     if ((turn == Players.First && item.PlayerOwner == CardOwner.First) ||
         (turn == Players.Second && item.PlayerOwner == CardOwner.Second))
     {
         if ((item.PlayerOwner == CardOwner.First && !firstPlayerBlocked) ||
             (item.PlayerOwner == CardOwner.Second &&
              ((!secondPlayerBlocked && opponent == Opponents.Player) ||
               (secondPlayerBlocked && opponent == Opponents.Bot))))
         {
             int tableIndex;
             if (item.PlayerOwner == CardOwner.First)
             {
                 if (cardsOnTable[1] == null)
                 {
                     tableIndex = 1;
                 }
                 else
                 {
                     tableIndex         = 0;
                     firstPlayerBlocked = true;
                 }
             }
             else
             if (cardsOnTable[2] == null)
             {
                 tableIndex = 2;
             }
             else
             {
                 tableIndex          = 3;
                 secondPlayerBlocked = true;
             }
             ++cardsChosen;
             cardsOnTable[tableIndex] = item;
             item.SetImagePosition(244 + tableIndex * 128, 268);
             item.ImageBox.BringToFront();
             item.Status = CardStatus.Table;
             turn        = ChangeTurn(turn);
             if (cardsChosen > 1)
             {
                 CompareCards();
             }
         }
     }
 }
 private void MoveCurrentCard(CardClass item)
 {
     if ((turn == Players.First && item.PlayerOwner == CardOwner.First) ||
         (turn == Players.Second && item.PlayerOwner == CardOwner.Second))
     {
         if ((item.PlayerOwner == CardOwner.First && !firstPlayerBlocked) ||
             (item.PlayerOwner == CardOwner.Second && 
             ((!secondPlayerBlocked && opponent == Opponents.Player) ||
             (secondPlayerBlocked && opponent == Opponents.Bot))))
         {
             int tableIndex;
             if (item.PlayerOwner == CardOwner.First)
                 if (cardsOnTable[1] == null)
                     tableIndex = 1;
                 else
                 {
                     tableIndex = 0;
                     firstPlayerBlocked = true;
                 }
             else
                 if (cardsOnTable[2] == null)
                     tableIndex = 2;
                 else
                 {
                     tableIndex = 3;
                     secondPlayerBlocked = true;
                 }
             ++cardsChosen;
             cardsOnTable[tableIndex] = item;
             item.SetImagePosition(244 + tableIndex * 128, 268);
             item.ImageBox.BringToFront();
             item.Status = CardStatus.Table;
             turn = ChangeTurn(turn);
             if (cardsChosen > 1)
                 CompareCards();
         }
     }
 }
Example #8
0
        private void Bot()
        {
            CardClass item = secondPlayerGameCards[0];

            if (cardsChosen == 0)
            {
                item = secondPlayerGameCards[rand.Next(5)];
            }
            else if (cardsChosen == 1)
            {
                int value = 0;
                int index = -1;
                foreach (var card in secondPlayerGameCards)
                {
                    if (value < card.Value)
                    {
                        value = card.Value;
                        index = secondPlayerGameCards.IndexOf(card);
                    }
                }
                if (index != -1)
                {
                    item = secondPlayerGameCards[index];
                }
                else
                {
                    value = 100;
                    index = -1;
                    foreach (var card in secondPlayerGameCards)
                    {
                        if (cardsOnTable[1].Nation == card.Nation)
                        {
                            if (card.Value < value)
                            {
                                index = secondPlayerGameCards.IndexOf(card);
                            }
                        }
                    }
                    if (index != -1)
                    {
                        item = secondPlayerGameCards[index];
                    }
                    else
                    {
                        value = 100;
                        index = -1;
                        foreach (var card in secondPlayerGameCards)
                        {
                            if (card.Value < value)
                            {
                                value = card.Value;
                                index = secondPlayerGameCards.IndexOf(card);
                            }
                        }
                        item = secondPlayerGameCards[index];
                    }
                }
            }
            else if (cardsChosen == 2)
            {
                int value = 0;
                int index = -1;
                foreach (var card in secondPlayerGameCards)
                {
                    if (card.Nation == cardsOnTable[2].Nation)
                    {
                        if (card.Value > value)
                        {
                            value = card.Value;
                            index = secondPlayerGameCards.IndexOf(card);
                        }
                    }
                }
                if (index != -1)
                {
                    item = secondPlayerGameCards[index];
                }
            }
            else if (cardsChosen == 3)
            {
                int value = 0;
                int index = -1;
                foreach (var card in secondPlayerGameCards)
                {
                    if (card.Nation == cardsOnTable[2].Nation)
                    {
                        if (card.Value > value)
                        {
                            value = card.Value;
                            index = secondPlayerGameCards.IndexOf(card);
                        }
                    }
                }
                if (index != -1)
                {
                    item = secondPlayerGameCards[index];
                }
            }


            item.SetVisible(true);
            item.CardClicked();
        }
Example #9
0
 private int Compare(CardClass x, CardClass y)
 {
     return(y.Value.CompareTo(x.Value));
 }
 private void ActivateBot(CardClass cardClass)
 {
     if (turn == Players.Second && opponent == Opponents.Bot && round < NumberOfRounds)
         Bot();
 }
 private int Compare(CardClass x, CardClass y)
 {
     return y.Value.CompareTo(x.Value);
 }
Example #12
0
 public MainForm()
 {
     InitializeComponent();
     CardClass.SetLocalPath(Path.GetDirectoryName(Application.ExecutablePath));
 }