예제 #1
0
        //damage returneres mens denne fratrækkes Health
        //Healthbar sættes og farve checkes
        //Billeder ændres og en timer sættes
        //Angrebsinformation tilføjes til overbliksliste
        //Angrebsknapper disables
        private void Attack2Button_Click(object sender, RoutedEventArgs e)
        {
            int damage = Controller.Fight(f2, f1);

            HP1.Height = Controller.HealthBarSet(f1);

            Controller.AddInfoToOverview(f2, f1, damage);

            if (f1.Health > 0)
            {
                FighterImg1.Source = new BitmapImage(new Uri(@"./Resources/Block1.png", UriKind.Relative));
                FighterImg2.Source = new BitmapImage(new Uri(@"./Resources/Attack2.png", UriKind.Relative));

                CheckHealth(HP1);

                ButtonsEnabled(false);

                TimeOut(Controller.GenerateRandom(6));
            }
            else
            {
                FighterImg1.Source = new BitmapImage(new Uri(@"./Resources/Dead1.png", UriKind.Relative));
                Header.Text        = String.Format("The Winner is {0}", f2.GenerateInfo());

                Controller.GetFightOverview().Add(StickManStats.GenerateWinnerInfo(f2, f1));

                ButtonsEnabled(false);

                OverviewButton.Visibility = Visibility.Visible;
            }
        }
예제 #2
0
        //Tilføjer angrebsinfo til overblikslisten.
        //Listen instantieres ved første kald af funktionen.
        public static void AddInfoToOverview(StickManStats f1, StickManStats f2, int dmg)
        {
            if (FightOverview == null)
            {
                FightOverview = new List <string>();
            }

            FightOverview.Add(GenerateFightInfo(f1, f2, dmg));
        }
예제 #3
0
 //Returnerer tekststreng med info om angrebet
 private static string GenerateFightInfo(StickManStats f1, StickManStats f2, int dmg)
 {
     if (f2.Health < 0)
     {
         return(string.Format("{0} attacked {1} with {2} damage, {1} now has 0 health left", f1.Name, f2.Name, dmg, f2.Health));
     }
     else
     {
         return(string.Format("{0} attacked {1} with {2} damage, {1} now has {3} health left", f1.Name, f2.Name, dmg, f2.Health));
     }
 }
예제 #4
0
 //Sætter højde af Healthbar ved begyndelsen af kampen
 public static double HealthBarSet(StickManStats f)
 {
     if (f.Health > 0)
     {
         return(Convert.ToDouble(f.Health));
     }
     else
     {
         return(0);
     }
 }
예제 #5
0
        //Der skal laves en instans af listen, før der kan komme indhold i den.
        //Derefter oprettes en StickManStats ved brug af Constructor
        //Den oprettede StickManStats tilføjes til listen
        public static void CreateNewStickMan(string name, string nationality)
        {
            if (StickManList == null || StickManList.Count >= 2)
            {
                StickManList = new List <StickManInfo>();
            }

            StickManInfo Fighter = new StickManStats(name, nationality);

            StickManList.Add(Fighter);
        }
        //Methods
        //Intastede stats tilføjes til de enkelte StickMen
        public static void AddStats(StickManStats s1, StickManStats s2, string h1, string a1, string b1, string h2, string a2, string b2)
        {
            try
            {
                s1.Health    = Convert.ToInt32(h1);
                s1.AttackMax = Convert.ToInt32(a1);
                s1.BlockMax  = Convert.ToInt32(b1);

                s2.Health    = Convert.ToInt32(h2);
                s2.AttackMax = Convert.ToInt32(a2);
                s2.BlockMax  = Convert.ToInt32(b2);
            }
            catch (OverflowException) { }
            catch (FormatException) { }
        }
예제 #7
0
        //Returnerer damage på baggrund af de to randomiserede Attack- og Block-værdier
        public static int Fight(StickManStats f1, StickManStats f2)
        {
            if (f2.Health > 0)
            {
                int damage = f1.Attack() - f2.Block();

                if (damage >= 0)
                {
                    f2.Health -= damage;
                }

                return(damage);
            }

            return(0);
        }
        //Eventhandlers
        private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            inputOk = true;

            InputValidation.InputVal(Health1.Text, errHealth1, ref inputOk);
            InputValidation.InputVal(Health2.Text, errHealth2, ref inputOk);
            InputValidation.InputVal(AttMax1.Text, errAttMax1, ref inputOk);
            InputValidation.InputVal(AttMax2.Text, errAttMax2, ref inputOk);
            InputValidation.InputVal(BloMax1.Text, errBloMax1, ref inputOk);
            InputValidation.InputVal(BloMax2.Text, errBloMax2, ref inputOk);

            if (inputOk)
            {
                StickManStats.AddStats(f1, f2, Health1.Text, AttMax1.Text, BloMax1.Text, Health2.Text, AttMax2.Text, BloMax2.Text);

                NavigationService ns = NavigationService.GetNavigationService(this);
                ns.Navigate(new Uri("Fight.xaml", UriKind.Relative));
            }
        }
 //Returnerer vinderinformation som bruges til afsluttende overblik
 public static string GenerateWinnerInfo(StickManStats winner, StickManStats loser)
 {
     return(String.Format("{0} has died, and the Winner is {1}", loser.Name, winner.GenerateInfo()));
 }