Ejemplo n.º 1
0
        private void SaveHero_Button(object sender, RoutedEventArgs e)
        {
            var currentHero = (Hero)DataContext;

            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.MediumVioletRed);
            if (HeroNameBox.Text == null || HeroNameBox.Text.Length < 3 || HeroNameBox.Text.Length > 60)
            {
                stsBarTextBlock.Text = "Hero name length allowed: 3-60!";
                HeroNameBox.Focus();
                HeroNameBox.SelectAll();
                return;
            }
            if (GoldBox.Text == null || GoldBox.Text == "" || decimal.Parse(GoldBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Gold cannot be negative or null!";
                GoldBox.Focus();
                GoldBox.SelectAll();
                return;
            }
            if (HpBox.Text == null || HpBox.Text == "" || double.Parse(HpBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Hp cannot be negative or null!";
                HpBox.Focus();
                HpBox.SelectAll();
                return;
            }
            if (ManaBox.Text == null || ManaBox.Text == "" || double.Parse(ManaBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Mana cannot be negative or null!";
                ManaBox.Focus();
                ManaBox.SelectAll();
                return;
            }
            if (DefenceBox.Text == null || DefenceBox.Text == "" || double.Parse(DefenceBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Defence cannot be negative or null!";
                DefenceBox.Focus();
                DefenceBox.SelectAll();
                return;
            }
            if (AttackPowerBox.Text == null || AttackPowerBox.Text == "" || double.Parse(AttackPowerBox.Text) < 0)
            {
                stsBarTextBlock.Text = "AttackPower cannot be negative or null!";
                AttackPowerBox.Focus();
                AttackPowerBox.SelectAll();
                return;
            }

            var hero = context.Heroes.FirstOrDefault(h => h.Id == currentHero.Id);

            hero.Name                  = HeroNameBox.Text;
            hero.Gold                  = decimal.Parse(GoldBox.Text);
            hero.HeroStats.Hp          = double.Parse(HpBox.Text);
            hero.HeroStats.Mana        = double.Parse(ManaBox.Text);
            hero.HeroStats.Defence     = double.Parse(DefenceBox.Text);
            hero.HeroStats.AttackPower = double.Parse(AttackPowerBox.Text);


            context.SaveChanges();
            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.Green);
            stsBarTextBlock.Text       = "Success!";
        }
Ejemplo n.º 2
0
    //tällä kauppa

    /*void Pause()
     * {
     *
     *  List<Label> painikkeet = new List<Label>();
     *
     *  Label kauppa = new Label("Kauppa:");
     *  Label ostaHp = new Label("Osta eläimiä");
     *  Label ostaAmmo = new Label("Osta Ammuksia(maksetaan elämillä)");
     *
     *  kauppa.Position = new Vector(0, 40);
     *  ostaHp.Position = new Vector(0, 50);
     *  ostaAmmo.Position = new Vector(0, 60);
     *  painikkeet.Add(kauppa);
     *  painikkeet.Add(ostaHp);
     *  painikkeet.Add(ostaAmmo);
     *  ostaHp.BorderColor = Color.Black;
     *  ostaAmmo.BorderColor = Color.Black;
     *
     *  foreach (Label painike in painikkeet)
     *  {
     *      Add(painike);
     *  }
     *  Mouse.ListenOn(ostaHp, MouseButton.Left, ButtonState.Pressed, pelaajaOstaaHp, null);
     *  Mouse.ListenOn(ostaAmmo, MouseButton.Left, ButtonState.Pressed, pelaajaOstaaAmmo, null);
     * }*/
    //kierrosten ja vihujen luonti
    void Kierros()
    {
        //lita vihuista
        vihut = new List <Monsteri>();

        kierros++;
        vihollisteMaara = 2 * kierros;


        //vihujenluonti
        for (int z = 0; z < vihollisteMaara; z++)
        {
            //viholliset seuraajiksi
            Zombie zombi = new Zombie(40, 80);

            FollowerBrain VihunAivot = new FollowerBrain(pelaaja1)
            {
                Speed         = zombi.nopeus,
                DistanceFar   = 1900,
                DistanceClose = 10
            };


            zombi.Image    = ZombienKuva;
            zombi.Position = zombi.Respaus;
            zombi.Tag      = "vihu";

            zombi.Brain     = VihunAivot;
            zombi.CanRotate = false;

            AddCollisionHandler(pelaaja1, zombi, Hyokkaa);

            vihut.Add(zombi);
            Add(zombi);
        }
        // piruja joka 3. rundi
        if (kierros % 3 == 0)
        {
            vihollisteMaara++;
            Piru piru = new Piru(100, 100);

            FollowerBrain VihunAivot = new FollowerBrain(pelaaja1)
            {
                Speed         = piru.nopeus,
                DistanceFar   = 1900,
                DistanceClose = 30
            };
            piru.Image    = pirunKuva;
            piru.Brain    = VihunAivot;
            piru.Tag      = "vihu";
            piru.Position = piru.Respaus;
            while (piru.Position.Distance(pelaaja1.Position) < 40)
            {
                piru.Position = piru.Respaus;
            }

            piru.CanRotate = false;
            AddCollisionHandler(pelaaja1, piru, Hyokkaa);
            vihut.Add(piru);
            Add(piru);
        }
        //HpBoxit peliin, joka kierros chance saada 20%
        Random hpChance = new Random();

        if (hpChance.Next(0, 10) >= 8)
        {
            hp       = new HpBox(30, 30);
            hp.Image = hpBoxi;
            AddCollisionHandler(pelaaja1, hp, Keraa);
            if (hp.hpBoxiKentalla == false)
            {
                hp.hpBoxiKentalla = true;
                Add(hp);
            }
        }
        //kauppa joka 3. kierros
        if (kierros % 3 == 0)
        {
            //Pause();
        }
    }
Ejemplo n.º 3
0
        private void SaveHero_Button(object sender, RoutedEventArgs e)
        {
            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.MediumVioletRed);
            if (HeroNameBox.Text == null || HeroNameBox.Text.Length < 3 || HeroNameBox.Text.Length > 60)
            {
                stsBarTextBlock.Text = "Hero name length allowed: 3-60!";
                HeroNameBox.Focus();
                HeroNameBox.SelectAll();
                return;
            }
            if (GoldBox.Text == null || GoldBox.Text == "" || decimal.Parse(GoldBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Gold cannot be negative or null!";
                GoldBox.Focus();
                GoldBox.SelectAll();
                return;
            }
            if (HpBox.Text == null || HpBox.Text == "" || double.Parse(HpBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Hp cannot be negative or null!";
                HpBox.Focus();
                HpBox.SelectAll();
                return;
            }
            if (ManaBox.Text == null || ManaBox.Text == "" || double.Parse(ManaBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Mana cannot be negative or null!";
                ManaBox.Focus();
                ManaBox.SelectAll();
                return;
            }
            if (DefenceBox.Text == null || DefenceBox.Text == "" || double.Parse(DefenceBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Defence cannot be negative or null!";
                DefenceBox.Focus();
                DefenceBox.SelectAll();
                return;
            }
            if (AttackPowerBox.Text == null || AttackPowerBox.Text == "" || double.Parse(AttackPowerBox.Text) < 0)
            {
                stsBarTextBlock.Text = "AttackPower cannot be negative or null!";
                AttackPowerBox.Focus();
                AttackPowerBox.SelectAll();
                return;
            }

            var user = AuthenticationService.GetCurrentUser();

            var newHero = new Hero()
            {
                Name   = HeroNameBox.Text,
                Gold   = decimal.Parse(GoldBox.Text),
                UserId = user.Id
            };

            var newHeroStats = new HeroStats()
            {
                Hero        = newHero,
                Hp          = double.Parse(HpBox.Text),
                Mana        = double.Parse(ManaBox.Text),
                Defence     = double.Parse(DefenceBox.Text),
                AttackPower = double.Parse(AttackPowerBox.Text)
            };

            newHero.HeroStats = newHeroStats;

            context.Heroes.Add(newHero);
            context.HeroStatistics.Add(newHeroStats);
            context.SaveChanges();
            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.Green);
            stsBarTextBlock.Text       = "Success!";
        }