private void BtnPlayCard_Click(object sender, RoutedEventArgs e)
        {
            string message;

            if (selectedCards.Count != ableToSelectLimit)
            {
                MessageBox.Show("You must select " + ableToSelectLimit.ToString() + " card(s) to summon.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                GUIWindows.GUISelect       guiSelect;
                List <Models.CardGUIModel> validSelections;

                // if there is not enough unused mana or none of the mana is of card's element then we can't summon
                if (!checkCanSummon(selectedCards[0]))
                {
                    message = string.Format("You don't have the right mana to summon this {0}.", selectedCards[0].Card.Type);
                    MessageBox.Show(message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                validSelections = new List <Models.CardGUIModel>();

                // add all mana that's not engaged to the validSelections list (you can only use mana that's not engaged already)
                foreach (Models.CardGUIModel cardGUI in listOwnManaZone)
                {
                    if (!cardGUI.Card.isEngaged)
                    {
                        validSelections.Add(cardGUI);
                    }
                }

                int index;

                // create a GUI that will allow us to select the mana that we want to engage to pay the cost of the card we want to summon
                message   = string.Format("You must select a total of {0} mana, out of which at least one must be of {1} type.", selectedCards[0].Card.Cost, selectedCards[0].Card.Element);
                guiSelect = new GUIWindows.GUISelect(validSelections, message, selectedCards[0].Card.Cost, selectedCards[0].Card.Element);
                guiSelect.ShowDialog();

                if (!guiSelect.wasCanceled)
                {
                    List <int> selectedMana;

                    selectedMana = new List <int>();

                    // translate the selected indexes from the validSelections to indexes from the listOwnManaZone
                    foreach (int selectedIndex in guiSelect.selected)
                    {
                        selectedMana.Add(listOwnManaZone.IndexOf(validSelections[selectedIndex]));
                    }

                    index = listHand.IndexOf(selectedCards[0]);
                    ableToSelect.Remove(selectedCards[0]);
                    selectedCards[0].deselect();

                    // proceed to summon the card
                    summonOWN(selectedMana, index);
                }
            }
        }
        private void triggerOwnSendTo(SpecialEffect se)
        {
            GUIWindows.GUISelect gUISelect;
            List <CardGUIModel>  validSelections;
            string selectMessage, friendlyFrom;

            validSelections = new List <CardGUIModel>();

            validSelections.Clear();

            getValidSelections(se, out validSelections, out friendlyFrom);

            if (validSelections.Count > 0)
            {
                gUISelect = null;
                List <int> selectedTargetIndexes;

                // if you must select a number of cards from opponent's mana zone
                if (se.Arguments[0] != ALL)
                {
                    selectMessage = string.Format("You must select a total of {0} card(s) from your {1}.", Math.Min(se.Arguments[0], validSelections.Count), friendlyFrom);

                    gUISelect = new GUIWindows.GUISelect(validSelections, selectMessage, se.Arguments[0], null);
                    gUISelect.removeCancelButton();
                    gUISelect.ShowDialog();

                    selectedTargetIndexes = gUISelect.selected;
                }
                else
                {
                    selectedTargetIndexes = new List <int>();

                    for (int i = 0; i < validSelections.Count; i++)
                    {
                        selectedTargetIndexes.Add(i);
                    }
                }

                switch (se.TargetTo)
                {
                case "OppHand":
                    sendToOppHand(se, selectedTargetIndexes);
                    break;

                case "OwnHand":
                    sendToOwnHand(se, selectedTargetIndexes);
                    break;

                case "OppGrave":
                    sendToOppGrave(se, selectedTargetIndexes);
                    break;

                case "OwnGround":
                    sendToOwnGround(se, selectedTargetIndexes);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        // creature is under attack

        public void creatureUnderAttack(List <int> intArguments)
        {
            bool youBlocked;
            List <CardGUIModel> defenders = null;

            GUIWindows.GUISelect gUISelect = null;

            /*
             * intArguments[0] - the attacker
             * intArguments[1] - the creature that is being attacked
             */

            engageBattleOPP(intArguments[0]);

            youBlocked = false;
            if (canBlock(intArguments[0]))
            {
                string message;

                defenders = getOwnDefendersThatCanBlock();
                if (defenders.Count != 0)
                {
                    message = "Select one defender to block the attack with, or don't block at all.";

                    gUISelect = new GUIWindows.GUISelect(defenders, message, 1, null);
                    gUISelect.replaceCancelButtonMessage("Don't defend");
                    gUISelect.ShowDialog();

                    // you blocked the attack
                    if (!gUISelect.wasCanceled)
                    {
                        youBlocked = true;
                    }
                }
            }

            if (youBlocked)
            {
                int index;

                index = listOwnBattleGround.IndexOf(defenders[gUISelect.selected[0]]);

                engageBattleOWN(index);

                // you modify the target of the attacker to the index of the defender
                intArguments[1] = index;

                //notify the server that 2 creatures will battle
                sendBattle(intArguments);
                Battle(intArguments, false);
            }
            else
            {
                sendBattle(intArguments);
                Battle(intArguments, false);
            }
        }
Ejemplo n.º 4
0
        public void playerUnderAttack(List <int> intArguments)
        {
            bool youBlocked;
            List <CardGUIModel> defenders = null;

            GUIWindows.GUISelect gUISelect = null;

            /*
             * intArguments[0] - the attacker
             */

            engageBattleOPP(intArguments[0]);

            youBlocked = false;
            if (canBlock(intArguments[0]))
            {
                string message;

                defenders = getOwnDefendersThatCanBlock();
                message   = "Select one defender to block the attack with, or don't block at all.";

                gUISelect = new GUIWindows.GUISelect(defenders, message, 1, null);
                gUISelect.replaceCancelButtonMessage("Don't defend");
                gUISelect.ShowDialog();

                // you blocked the attack
                if (!gUISelect.wasCanceled)
                {
                    youBlocked = true;
                }
            }

            if (youBlocked)
            {
                int index;

                index = listOwnBattleGround.IndexOf(defenders[gUISelect.selected[0]]);

                engageBattleOWN(index);

                // you add the target of the attacker to the index of the defender
                intArguments.Add(index);
                sendBattle(intArguments);
                Battle(intArguments, false);
            }
            else
            {
                // you lost

                ctrl.send(new GameMessage(
                              "ISURRENDER",
                              ctrl.GameRoomID
                              ));

                loadEndGame(false);
            }
        }
        private void BtnAttackSafeguards_Click(object sender, RoutedEventArgs e)
        {
            string message;
            int    attackTargetCount;

            if (selectedCards.Count != ableToSelectLimit)
            {
                MessageBox.Show("You must select " + ableToSelectLimit.ToString() + " card(s) to attack with.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                GUIWindows.GUISelect guiSelect;

                // find out how many safeguards can selected creature attack
                attackTargetCount = getAttackTargetCount();

                if (attackTargetCount == 0)
                {
                    MessageBox.Show("This creature cannot attack safeguards.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    List <int> selectedSafeguards;
                    int        index;

                    // cannot break more safeguards than our opponent has
                    attackTargetCount = Math.Min(attackTargetCount, listOppSafeGuardZone.Count());

                    // create the gui that allows us to select the safeguards that we want to attack
                    message   = string.Format("You must select a total of {0} safeguard(s).", attackTargetCount);
                    guiSelect = new GUIWindows.GUISelect(
                        new List <CardGUIModel>(),
                        listOppSafeGuardZone,
                        message,
                        "shield zone",
                        0,
                        attackTargetCount
                        );
                    guiSelect.ShowDialog();

                    if (!guiSelect.wasCanceled)
                    {
                        selectedSafeguards = guiSelect.oppSelected;

                        // notify server of our attack so it can notify our opponent
                        sendAttack(selectedSafeguards, true);

                        index = listOwnBattleGround.IndexOf(selectedCards[0]);
                        ableToSelect.Remove(selectedCards[0]);
                        selectedCards[0].deselect();
                        engageBattleOWN(index);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void BtnAttackCreatures_Click(object sender, RoutedEventArgs e)
        {
            string message;

            if (selectedCards.Count != ableToSelectLimit)
            {
                MessageBox.Show("You must select " + ableToSelectLimit.ToString() + " card(s) to attack with.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                GUIWindows.GUISelect guiSelect;
                List <CardGUIModel>  validSelections;
                int index;

                // only creatures that are engaged can be attacked
                validSelections = new List <CardGUIModel>();
                foreach (CardGUIModel cardGUI in listOppBattleGround)
                {
                    if (cardGUI.Card.isEngaged)
                    {
                        validSelections.Add(cardGUI);
                    }
                }

                if (validSelections.Count == 0)
                {
                    MessageBox.Show("There are no creatures you can attack.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    message   = ("You must select a creature to attack.");
                    guiSelect = new GUIWindows.GUISelect(validSelections, message, 1, null);

                    guiSelect.ShowDialog();
                    if (!guiSelect.wasCanceled)
                    {
                        // translate selected card indexes to listOppBattleGround indexes
                        index = listOppBattleGround.IndexOf(validSelections[guiSelect.selected[0]]);

                        // notify server of our attack so it can notify our opponent
                        sendAttack(new List <int>()
                        {
                            index
                        }, false);

                        // deselect card and engage it
                        index = listOwnBattleGround.IndexOf(selectedCards[0]);
                        ableToSelect.Remove(selectedCards[0]);
                        selectedCards[0].deselect();
                        engageBattleOWN(index);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        // safeguards are being attacked

        public void safeguardsUnderAttack(List <int> intArguments)
        {
            bool youBlocked;
            List <CardGUIModel> defenders = null;

            GUIWindows.GUISelect gUISelect = null;

            /*
             * intArguments[0] - the attacker
             * intArguments[1..] - the safeguards that are being attacked
             */

            engageBattleOPP(intArguments[0]);

            youBlocked = false;
            if (canBlock(intArguments[0]))
            {
                string message;

                defenders = getOwnDefendersThatCanBlock();
                message   = "Select one defender to block the attack with, or don't block at all.";

                gUISelect = new GUIWindows.GUISelect(defenders, message, 1, null);
                gUISelect.replaceCancelButtonMessage("Don't defend");
                gUISelect.ShowDialog();

                // you blocked the attack
                if (!gUISelect.wasCanceled)
                {
                    youBlocked = true;
                }
            }

            if (youBlocked)
            {
                int index;

                index = listOwnBattleGround.IndexOf(defenders[gUISelect.selected[0]]);

                engageBattleOWN(index);

                // you modify the target of the attacker to the index of the defender
                intArguments[1] = index;
                sendBattle(intArguments);
                Battle(intArguments, false);
            }
            else
            {
                // you delete the attacker from the list of arguments
                intArguments.RemoveAt(0);
                sendBrokenSafeguards(intArguments);
            }
        }
Ejemplo n.º 8
0
        public SelectGUI_CardGUIModel(CardGUIModel cardGUI, GUIWindows.GUISelect parent_, Thickness margin)
        {
            logger       = new Log.Logger();
            this.cardGUI = cardGUI;
            parent       = parent_;

            // Border
            Border        = new Border();
            Border.Width  = 73;
            Border.Height = 100;
            Border.HorizontalAlignment = HorizontalAlignment.Left;
            Border.Margin          = margin;
            Border.BorderThickness = new Thickness(5);
            Border.BorderBrush     = Brushes.Transparent;
            TranslateTransform t = new TranslateTransform(0, 0);

            Border.RenderTransform = t;
            Border.Visibility      = Visibility.Visible;

            // Button
            Btn        = new Button();
            Btn.Style  = parent.FindResource("cardButtonStyle") as Style;
            Btn.Cursor = System.Windows.Input.Cursors.Hand;

            Btn.Click += Btn_Click;

            Border.Child = Btn;

            // Image
            Image = new Image();
            try
            {
                if (cardGUI.Card == null)
                {
                    Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/GUI/CardBack.png", UriKind.Absolute));
                }
                else
                {
                    Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/Cards/" + cardGUI.Card.Name + ".png", UriKind.Absolute));
                }
            }
            catch (Exception ex)
            {
                logger.Log(ex.ToString());
            }

            Image.Stretch = Stretch.UniformToFill;
            Btn.Content   = Image;
        }
Ejemplo n.º 9
0
        private void triggerOwnSendTo(SpecialEffect se)
        {
            GUIWindows.GUISelect gUISelect;
            Tuple <List <CardGUIModel>, List <CardGUIModel> > validSelections, fullSelections;
            string selectMessage, friendlyFrom;
            bool   treatCountAsOne;

            if (se.TargetFrom == "OwnDeck")
            {
                switch (se.TargetTo)
                {
                case "OwnMana":
                    ctrl.send(new GameMessage("DECKTOMANA", ctrl.GameRoomID, se.Arguments));
                    return;

                default:
                    return;
                }
            }

            fullSelections  = getValidSelections(se, out friendlyFrom);
            treatCountAsOne = se.TargetFrom.Contains("Any") ? true : false;

            if (se.Condition == "LessOrEqual")
            {
                validSelections = new Tuple <List <CardGUIModel>, List <CardGUIModel> >(
                    fullSelections.Item1.Where(x => (x.Card.Type == "Creature" && x.Card.Power <= se.Arguments[1])).ToList <CardGUIModel>(),
                    fullSelections.Item2.Where(x => (x.Card.Type == "Creature" && x.Card.Power <= se.Arguments[1])).ToList <CardGUIModel>());
            }
            else
            {
                validSelections = new Tuple <List <CardGUIModel>, List <CardGUIModel> >(
                    fullSelections.Item1,
                    fullSelections.Item2);
            }

            if (validSelections.Item1.Count > 0 || validSelections.Item2.Count > 0)
            {
                gUISelect = null;
                List <int> selectedTargetIndexesOwn, selectedTargetIndexesOpp, translatedIndexesOwn, translatedIndexesOpp;

                // if you must select a number of cards from opponent's mana zone
                if (se.Arguments[0] != ALL)
                {
                    selectMessage = "";
                    if (validSelections.Item1.Count > 0)
                    {
                        if (validSelections.Item2.Count > 0)
                        {
                            selectMessage = string.Format("You must select a total of {0} cards from your {3} {1} {2} cards from your opponent's {3}.",
                                                          treatCountAsOne ? Math.Min(validSelections.Item1.Count + validSelections.Item1.Count, se.Arguments[0]) : Math.Min(validSelections.Item1.Count, se.Arguments[0]),
                                                          treatCountAsOne ? "or" : "and",
                                                          treatCountAsOne ? Math.Min(validSelections.Item1.Count + validSelections.Item1.Count, se.Arguments[0]) : Math.Min(validSelections.Item2.Count, se.Arguments[0]),
                                                          friendlyFrom);
                        }
                        else
                        {
                            selectMessage = string.Format("You must select a total of {0} card(s) from your {1}.",
                                                          Math.Min(se.Arguments[0], validSelections.Item1.Count),
                                                          friendlyFrom);
                        }
                    }
                    else
                    {
                        if (validSelections.Item2.Count > 0)
                        {
                            selectMessage = string.Format("You must select a total of {0} card(s) from your opponent's {1}.",
                                                          Math.Min(se.Arguments[0], validSelections.Item2.Count),
                                                          friendlyFrom);
                        }
                    }
                    gUISelect = new GUIWindows.GUISelect(
                        validSelections.Item1,
                        validSelections.Item2,
                        selectMessage,
                        friendlyFrom,
                        validSelections.Item1.Count == 0 ? 0 : Math.Min(validSelections.Item1.Count, se.Arguments[0]),
                        validSelections.Item2.Count == 0 ? 0 : Math.Min(validSelections.Item2.Count, se.Arguments[0]),
                        se.TargetFrom.Contains("Any") ? true : false);
                    gUISelect.removeCancelButton();
                    gUISelect.ShowDialog();

                    selectedTargetIndexesOwn = gUISelect.ownSelected;
                    selectedTargetIndexesOpp = gUISelect.oppSelected;
                }
                else
                {
                    selectedTargetIndexesOwn = new List <int>();
                    selectedTargetIndexesOpp = new List <int>();

                    for (int i = 0; i < validSelections.Item1.Count; i++)
                    {
                        selectedTargetIndexesOwn.Add(i);
                    }
                    for (int i = 0; i < validSelections.Item2.Count; i++)
                    {
                        selectedTargetIndexesOpp.Add(i);
                    }
                }

                // translate indexes

                translatedIndexesOwn = new List <int>();
                translatedIndexesOpp = new List <int>();

                foreach (int index in selectedTargetIndexesOwn)
                {
                    translatedIndexesOwn.Add(fullSelections.Item1.IndexOf(validSelections.Item1[index]));
                }
                foreach (int index in selectedTargetIndexesOpp)
                {
                    translatedIndexesOpp.Add(fullSelections.Item2.IndexOf(validSelections.Item2[index]));
                }

                switch (se.TargetTo)
                {
                case "OppHand":
                    sendToOppHand(se, translatedIndexesOwn, translatedIndexesOpp);
                    break;

                case "OwnHand":
                    sendToOwnHand(se, translatedIndexesOwn, translatedIndexesOpp);
                    break;

                case "OwnGrave":
                    sendToOwnGrave(se, translatedIndexesOwn, translatedIndexesOpp);
                    break;

                case "OppGrave":
                    sendToOppGrave(se, translatedIndexesOwn, translatedIndexesOpp);
                    break;

                case "OwnGround":
                    sendToOwnGround(se, translatedIndexesOwn, translatedIndexesOpp);
                    break;

                case "OwnersHand":
                    sendToOwnersHand(se, translatedIndexesOwn, translatedIndexesOpp);
                    break;
                }
            }
        }
 public SelectGUI_CardGUIModel(Card card, GUIWindows.GUISelect parent, Thickness margin, bool clickable = true, int shieldNumber = -1)
 {
     type = 1;
     init(card, parent, margin, clickable, shieldNumber);
 }