Exemplo n.º 1
0
        private void buttonAddFraction_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxFraction.Text == "")
            {
                MessageBox.Show("Field fraction is empty");
                return;
            }

            using (CardGameDBContext db = new CardGameDBContext())
            {
                Fraction fr = db.Fractions.FirstOrDefault(f => f.Name == textBoxFraction.Text);
                if (fr != null)
                {
                    MessageBox.Show("This fraction already exist");
                    return;
                }

                Fraction fraction = new Fraction
                {
                    Name = textBoxFraction.Text
                };
                db.Fractions.Add(fraction);
                db.SaveChanges();
                comboBoxFraction.ItemsSource = db.Fractions.ToList();
            }
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            comboBoxFraction.DisplayMemberPath = "Name";
            comboBoxFraction.SelectedValuePath = "Id";
            using (CardGameDBContext db = new CardGameDBContext())
            {
                comboBoxFraction.ItemsSource = db.Fractions.ToList();
                dataGrid.ItemsSource         = db.Cards.ToList();
            }
            comboBoxFraction.SelectedIndex = 0;
        }
Exemplo n.º 3
0
        public override Deck CreateDeck()
        {
            Deck deck = new Deck();

            Models.Cards.Card card;
            using (CardGameDBContext db = new CardGameDBContext())
            {
                card = db.Cards.FirstOrDefault(c => (c.IdFraction == 1) && (c as Models.Cards.SworderCard) != null);
            }
            for (int i = 0; i < 20; i++)
            {
                deck.Cards.Add(card.Clone() as Models.Cards.Card);
            }

            return(deck);
        }
Exemplo n.º 4
0
        private void buttonAddCard_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxHealth.Text == "" || textBoxAttack.Text == "" || textBoxName.Text == "" || textBoxDescription.Text == "" || textBoxCost.Text == "")
            {
                MessageBox.Show("Some field is empty");
                return;
            }

            CardGameClassLibrary.Models.Cards.Card card;
            int fraction = (int)comboBoxFraction.SelectedValue;

            switch (comboBoxType.SelectedItem.ToString())
            {
            case "Sworderman":
                card = new CardGameClassLibrary.Models.Cards.SworderCard();
                break;

            case "Archer":
                card = new CardGameClassLibrary.Models.Cards.ArcherCard();
                break;

            case "Siege":
                card = new CardGameClassLibrary.Models.Cards.SiegeCard();
                break;

            default:
                card = null;
                break;
            }

            card.Health      = Convert.ToInt32(textBoxHealth.Text);
            card.Attack      = Convert.ToInt32(textBoxAttack.Text);
            card.Name        = textBoxName.Text;
            card.Description = textBoxDescription.Text;
            card.Cost        = Convert.ToInt32(textBoxCost.Text);
            card.IdFraction  = fraction;

            using (CardGameDBContext db = new CardGameDBContext())
            {
                db.Cards.Add(card);
                db.SaveChanges();
                dataGrid.ItemsSource = db.Cards.ToList();
            }
        }