Exemplo n.º 1
0
 /// <summary>
 /// The only method that can be called outside the class. It will take in two Character objects and try to battle them.
 /// This method is responsible for subtracting the actual damage from the Character SDC or HP property.
 /// </summary>
 /// <param name="attacker"></param>
 /// <param name="defender"></param>
 /// <returns>A boolean that represents that damage was dealt in combat.</returns>
 public CombatResults startCombat(Character attacker, Character defender)
 {
     results = new CombatResults();
     if ((attacker is Player && defender is Player)
         || (attacker is Zed && defender is Zed))
     {
         results.Allies = true;
         results.Message = "The combatants are allies";
         return results;
     }
     else
     {
         this.attacker = attacker;
         this.defender = defender;
         setAttackerBonuses();
         bool attackHit = confirmHit();
         results.AttackHit = attackHit;
         if (attackHit)
         {
             bool damageHP = false;
             if (attacker is Zed)
             {
                 damageHP = (((Zed)attacker) is Shank) ? true : false;
             }
             int damage = damageDone();
             results.Damage = damage;
             if (defender.SCD >= damage && !damageHP)
             {
                 defender.SCD -= damage;
             }
             else if (defender.SCD < damage && defender.SCD > 0 && !damageHP)
             {
                 damage -= defender.SCD;
                 defender.SCD = 0;
                 defender.HP -= damage;
             }
             else
             {
                 defender.HP -= damage;
             }
             return results;
         }
         else
         {
             results.Message = "Attack missed";
             return results;
         }
     }
 }
Exemplo n.º 2
0
        private void BuildGrid(CombatResults results)
        {
            CellHeight = GameGrid.ActualHeight / 25;
            CellWidth = GameGrid.ActualWidth / 25;
            Grid combatView = new Grid();
            combatView.RowDefinitions.Add(new RowDefinition());
            combatView.RowDefinitions.Add(new RowDefinition());
            combatView.RowDefinitions.Add(new RowDefinition());
            combatView.RowDefinitions.Add(new RowDefinition());
            combatView.RowDefinitions.Add(new RowDefinition());
            combatView.RowDefinitions.Add(new RowDefinition());
            combatView.ColumnDefinitions.Add(new ColumnDefinition());
            combatView.ColumnDefinitions.Add(new ColumnDefinition());
            combatView.ColumnDefinitions.Add(new ColumnDefinition());
            combatView.ColumnDefinitions.Add(new ColumnDefinition());
            combatView.Background = new SolidColorBrush(Colors.Wheat);
            //Attacker and Defender Labels
            Label AttackerLabel = new Label();
            AttackerLabel.Content = "Attacker";
            Grid.SetColumnSpan(AttackerLabel, 2);
            combatView.Children.Add(AttackerLabel);
            Label DefenderLabel = new Label();
            DefenderLabel.Content = "Defender";
            Grid.SetColumn(DefenderLabel, 2);
            Grid.SetColumnSpan(DefenderLabel, 2);
            combatView.Children.Add(DefenderLabel);
            //Name Labels
            Label AttackerName = new Label();
            AttackerName.Content = attacker.Name;
            Grid.SetColumnSpan(AttackerName, 2);
            Grid.SetRow(AttackerName, 1);
            combatView.Children.Add(AttackerName);
            Label DefenderName = new Label();
            DefenderName.Content = defender.Name;
            Grid.SetColumn(DefenderName, 2);
            Grid.SetColumnSpan(DefenderName, 2);
            Grid.SetRow(DefenderName, 1);
            combatView.Children.Add(DefenderName);
            //AttackRoll DefendRoll
            if (!results.Allies)
            {
                Label AttackRollLabel = new Label();
                AttackRollLabel.Content = "Attack Roll";
                Grid.SetRow(AttackRollLabel, 2);
                combatView.Children.Add(AttackRollLabel);
                Label AttackRoll = new Label();
                AttackRoll.Content = results.AttackRoll;
                if (results.AttackCrit)
                {
                    AttackRollLabel.Background = new SolidColorBrush(Colors.Green);
                    AttackRoll.Background = new SolidColorBrush(Colors.Green);
                }
                if (results.AttackFail)
                {
                    AttackRollLabel.Background = new SolidColorBrush(Colors.Red);
                    AttackRoll.Background = new SolidColorBrush(Colors.Red);
                }
                Grid.SetRow(AttackRoll, 2);
                Grid.SetColumn(AttackRoll, 1);
                combatView.Children.Add(AttackRoll);
                if (results.AttackHit)
                {
                    Label DefendRollLabel = new Label();
                    DefendRollLabel.Content = results.DefenseType;
                    Grid.SetColumn(DefendRollLabel, 2);
                    Grid.SetRow(DefendRollLabel, 2);
                    combatView.Children.Add(DefendRollLabel);
                    Label DefendRoll = new Label();
                    DefendRoll.Content = results.DefendRoll;
                    if (results.DefendCrit)
                    {
                        DefendRollLabel.Background = new SolidColorBrush(Colors.Green);
                        DefendRoll.Background = new SolidColorBrush(Colors.Green);
                    }
                    if (results.DefendFail)
                    {
                        DefendRollLabel.Background = new SolidColorBrush(Colors.Red);
                        DefendRoll.Background = new SolidColorBrush(Colors.Red);
                    }
                    Grid.SetColumn(DefendRoll, 3);
                    Grid.SetRow(DefendRoll, 2);
                    combatView.Children.Add(DefendRoll);
                    if (results.Damage != 0)
                    {
                        Label DamageDoneLabel = new Label();
                        DamageDoneLabel.Content = "Damage";
                        Grid.SetRow(DamageDoneLabel, 3);
                        combatView.Children.Add(DamageDoneLabel);
                        Label DamageDone = new Label();
                        DamageDone.Content = results.Damage;
                        Grid.SetColumn(DamageDone, 1);
                        Grid.SetRow(DamageDone, 3);
                        combatView.Children.Add(DamageDone);
                        Label AttackerHPLabel = new Label();
                        AttackerHPLabel.Content = "Health";
                        Grid.SetRow(AttackerHPLabel, 4);
                        combatView.Children.Add(AttackerHPLabel);
                        Label AttackerHP = new Label();
                        AttackerHP.Content = attacker.HP;
                        Grid.SetRow(AttackerHP, 4);
                        Grid.SetColumn(AttackerHP, 1);
                        combatView.Children.Add(AttackerHP);
                        Label DefenderHPLabel = new Label();
                        DefenderHPLabel.Content = "Health";
                        Grid.SetRow(DefenderHPLabel, 4);
                        Grid.SetColumn(DefenderHPLabel, 2);
                        combatView.Children.Add(DefenderHPLabel);
                        Label DefenderHP = new Label();
                        DefenderHP.Content = defender.HP;
                        Grid.SetRow(DefenderHP, 4);
                        Grid.SetColumn(DefenderHP, 3);
                        combatView.Children.Add(DefenderHP);

                        Label AttackerSDCLabel = new Label();
                        AttackerSDCLabel.Content = "SDC";
                        Grid.SetRow(AttackerSDCLabel, 5);
                        combatView.Children.Add(AttackerSDCLabel);
                        Label AttackerSDC = new Label();
                        AttackerSDC.Content = attacker.SCD;
                        Grid.SetRow(AttackerSDC, 5);
                        Grid.SetColumn(AttackerSDC, 1);
                        combatView.Children.Add(AttackerSDC);
                        Label DefenderSDCLabel = new Label();
                        DefenderSDCLabel.Content = "SDC";
                        Grid.SetRow(DefenderSDCLabel, 5);
                        Grid.SetColumn(DefenderSDCLabel, 2);
                        combatView.Children.Add(DefenderSDCLabel);
                        Label DefenderSDC = new Label();
                        DefenderSDC.Content = defender.SCD;
                        Grid.SetRow(DefenderSDC, 5);
                        Grid.SetColumn(DefenderSDC, 3);
                        combatView.Children.Add(DefenderSDC);
                    }
                    else
                    {
                        Label SuccessDefend = new Label();
                        SuccessDefend.Content = "Successfully Defended Attack";
                        Grid.SetRow(SuccessDefend, 3);
                        Grid.SetColumnSpan(SuccessDefend, 4);
                        combatView.Children.Add(SuccessDefend);
                    }
                }
                else
                {
                    Label AttackMiss = new Label();
                    AttackMiss.Content = attacker.Name + " missed";
                    Grid.SetRow(AttackMiss, 3);
                    Grid.SetColumnSpan(AttackMiss, 4);
                    combatView.Children.Add(AttackMiss);
                }
            }
            else
            {
                Label FriendlyMessage = new Label();
                FriendlyMessage.Content = results.Message;
                Grid.SetRow(FriendlyMessage, 2);
                Grid.SetColumnSpan(FriendlyMessage, 4);
                combatView.Children.Add(FriendlyMessage);
            }
            //Add grid to canvas at location, wait 3 seconds and close
            Canvas.SetTop(combatView, (CellHeight * (FirstX + 1)));
            Canvas.SetLeft(combatView, (CellWidth * (FirstY)));
            GameGrid.Children.Add(combatView);

            if(GameGrid.Children.Contains(battleView))
            {
                GameGrid.Children.Remove(battleView);
            }
            battleView = combatView;
        }