public void Heal(Unit objectToHeal, out bool healSuccess)
        {
            healSuccess = true;
            
            //Healing method. "objectToHeal" is the unit that will be healed.
            if (this.HealthLevel > 0)
            {
                //Increase target unit's health level
                //if the priest has 1 health, he can't restore 2 health
                if (this.HealthLevel == 1)
                {
                    if (objectToHeal.HealthLevel == objectToHeal.MaxHealthLevel)
                    {
                        healSuccess = false;
                        return;
                    }

                    if ((objectToHeal.HealthLevel + 1) > objectToHeal.MaxHealthLevel)
                    {
                        objectToHeal.HealthLevel = objectToHeal.MaxHealthLevel;
                    }
                    else
                    {
                        objectToHeal.HealthLevel++;
                    }
                    
                    this.HealthLevel -= 1;
                }
                else
                {
                    if (objectToHeal.HealthLevel == objectToHeal.MaxHealthLevel)
                    {
                        healSuccess = false;
                        return;
                    }

                    if ((objectToHeal.HealthLevel + 2) > objectToHeal.MaxHealthLevel)
                    {
                        objectToHeal.HealthLevel = objectToHeal.MaxHealthLevel;
                        this.HealthLevel -= 1;
                    }
                    else
                    {
                        objectToHeal.HealthLevel += 2;
                        this.HealthLevel -= 2;
                    }
                }

                //Check if the priest is dead
                if (this.HealthLevel <= 0)
                {
                    this.IsAlive = false;
                    this.SmallImage.Source = new BitmapImage();
                    (this.SmallImage.Parent as Border).Background = null;
                    this.CurrentPosition = new Point(-1, -1);
                }
            }
        }
 public override void OpenSecret(Unit target)
 {
     if (target.AttackLevel - 2 <= 0)
     {
         target.AttackLevel = 0;
     }
     else
     {
         target.AttackLevel -= 2;
     }
 }
Example #3
0
 public override void OpenSecret(Unit target)
 {
     if (target.HealthLevel - 2 <= 0)
     {
         target.PlayDieSound();
         target.SmallImage.Source = new BitmapImage();
         (target.SmallImage.Parent as Border).Background = null;
         target.CurrentPosition = new Point(-1, -1);
         target.IsAlive = false;
     }
     else
     {
         target.HealthLevel -= 2;
     }
 }
 public abstract void OpenSecret(Unit target);
 public override void OpenSecret(Unit target)
 {
     target.AttackLevel += 2;
     target.MaxAttackLevel += 2;
 }
Example #6
0
        public void Attack(Unit targetUnit, out bool successAttack)
        {
            successAttack = false;

            //Check if the aggresssor could reach the target
            if (this.IsCorrectMove(targetUnit.CurrentPosition) && this.IsClearWay(targetUnit.CurrentPosition))
            {
                successAttack = true;
                targetUnit.HealthLevel -= this.AttackLevel;
                this.PlayAttackSound();

                if (targetUnit.IsCorrectMove(this.CurrentPosition))
                { 
                    this.HealthLevel -= targetUnit.CounterAttackLevel;                    
                }

                if (this.HealthLevel <= 0 && targetUnit.HealthLevel <= 0)
                {
                    this.PlayDieSound();
                    targetUnit.PlayDieSound();

                    targetUnit.SmallImage.Source = new BitmapImage();
                    (targetUnit.SmallImage.Parent as Border).Background = null;
                    targetUnit.CurrentPosition = new Point(-1, -1);

                    this.SmallImage.Source = new BitmapImage();
                    (targetUnit.SmallImage.Parent as Border).Background = null;
                    this.CurrentPosition = new Point(-1, -1);

                    this.IsAlive = false;
                    targetUnit.IsAlive = false;

                    return;                        
                }

                if (targetUnit.HealthLevel <= 0)
                {
                    targetUnit.PlayDieSound();
                    targetUnit.IsAlive = false;

                    //Level up the selected unit and at the same time up its attack and health
                    this.Level++;
                    this.MaxAttackLevel++;
                    this.AttackLevel++;
                    this.MaxHealthLevel++;
                    this.HealthLevel++;

                    targetUnit.SmallImage.Source = new BitmapImage();
                    (targetUnit.SmallImage.Parent as Border).Background = null;
                    
                    this.CurrentPosition = targetUnit.CurrentPosition;
                    targetUnit.CurrentPosition = new Point(-1, -1);

                    Grid.SetRow(this.SmallImage.Parent as Border, (int)this.CurrentPosition.Y);
                    Grid.SetColumn(this.SmallImage.Parent as Border, (int)this.CurrentPosition.X);
                }

                if (this.HealthLevel <= 0)
                {
                    this.PlayDieSound();
                    this.IsAlive = false;
                    
                    //Level up the selected unit and at the same time up its attack and health
                    targetUnit.Level++;
                    targetUnit.MaxAttackLevel++;
                    targetUnit.AttackLevel++;
                    targetUnit.MaxHealthLevel++;
                    targetUnit.HealthLevel++;

                    this.SmallImage.Source = new BitmapImage();
                    (this.SmallImage.Parent as Border).Background = null;

                    this.CurrentPosition = new Point(-1, -1);
                }
            }
        }
        private void HighLightPossibleObjectToHeal(object sender, Unit HoveredUnit)
        {
            if (HoveredUnit == null)
            {
                return;
            }

            if ((SelectedUnit.Race == HoveredUnit.Race) && HoveredUnit.HealthLevel < HoveredUnit.MaxHealthLevel)
            {
                ((sender as Image).Parent as Border).BorderBrush = Brushes.DeepSkyBlue;
                ((sender as Image).Parent as Border).BorderThickness = new Thickness(2);
            }
        }
 public void SetRightSidebarStats(Unit hoveredUnit)
 {
     this.Health.Text = "Health: " + hoveredUnit.HealthLevel.ToString() + "/" + hoveredUnit.MaxHealthLevel.ToString();
     this.Damage.Text = "Attack: " + hoveredUnit.AttackLevel.ToString();
     this.Defence.Text = "Defense: " + hoveredUnit.CounterAttackLevel.ToString();
     this.Level.Text = "Level: " + hoveredUnit.Level.ToString();
 }
 private void HighLightPossibleEnemy(object sender, Unit HoveredUnit)
 {
     if ((SelectedUnit != null && HoveredUnit != null) &&
         ((SelectedUnit.Race == RaceTypes.Horde && turn) || (SelectedUnit.Race == RaceTypes.Alliance && !turn)) &&
         (SelectedUnit.Race != HoveredUnit.Race) &&
         SelectedUnit.IsCorrectMove(HoveredUnit.CurrentPosition) &&
         SelectedUnit.IsClearWay(HoveredUnit.CurrentPosition))
     {
         ((sender as Image).Parent as Border).BorderBrush = Brushes.Red;
         ((sender as Image).Parent as Border).BorderThickness = new Thickness(2);
     }
 }
        private void ResetState()
        {
            foreach (var item in this.Playfield.Children)
            {
                (item as Border).Child = new Image();
            }

            SelectedUnit = null;
            secret = null;

            InitializedTeams.AllianceTeam = new List<RaceAlliance>
            {
                new AllianceSquire(new Point(0, 6)),
                new AllianceSquire(new Point(1, 6)),
                new AllianceSquire(new Point(2, 6)),
                new AllianceSquire(new Point(3, 6)),
                new AllianceSquire(new Point(4, 6)),
                new AllianceSquire(new Point(5, 6)),
                new AllianceSquire(new Point(6, 6)),
                new AllianceSquire(new Point(7, 6)),
                new AllianceMage(new Point(1, 7)),
                new AllianceMage(new Point(6, 7)),
                new AllianceCaptain(new Point(2, 7)),
                new AllianceCaptain(new Point(5, 7)),
                new AllianceWarGolem(new Point(0, 7)),
                new AllianceWarGolem(new Point(7, 7)),
                new AlliancePriest(new Point(3, 7)),
                new AllianceKing(new Point(4, 7)),
            };

            InitializedTeams.HordeTeam = new List<RaceHorde>
            {
                new HordeGrunt(new Point(0, 1)),
                new HordeGrunt(new Point(1, 1)),
                new HordeGrunt(new Point(2, 1)),
                new HordeGrunt(new Point(3, 1)),
                new HordeGrunt(new Point(4, 1)),
                new HordeGrunt(new Point(5, 1)),
                new HordeGrunt(new Point(6, 1)),
                new HordeGrunt(new Point(7, 1)),
                new HordeWarlock(new Point(1, 0)),
                new HordeWarlock(new Point(6, 0)),
                new HordeCommander(new Point(2, 0)),
                new HordeCommander(new Point(5, 0)),
                new HordeDemolisher(new Point(0, 0)),
                new HordeDemolisher(new Point(7, 0)),
                new HordeShaman(new Point(3, 0)),
                new HordeWarchief(new Point(4, 0)),
            };

            isMouseCapture = false;
            mouseXOffset = 0;
            mouseYOffset = 0;
            translateTransform = new TranslateTransform();
            backgroundMusic = new MediaPlayer();
            isSomeUnitSelected = false;
            selectedBorder = new Border();
            turn = true;
        }
        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Image image = (Image)sender;
            Border border = (Border)image.Parent;
            Grid grid = (Grid)border.Parent;

            if (translateTransform == null)
            {
                if (isMouseCapture)
                {
                    isMouseCapture = false;
                    image.ReleaseMouseCapture();
                }
                return;
            }

            image.ReleaseMouseCapture();
            isMouseCapture = false;

            Point coordinates;

            if (SelectedUnit != null)
            {
                //Get the new position it row and col
                grid.GetDynamicRowColumn(e.GetPosition(border), SelectedUnit.CurrentPosition, out coordinates);

                //The selected unit current position + calculated coordinates
                coordinates.X = (int)SelectedUnit.CurrentPosition.X + coordinates.X;
                coordinates.Y = (int)SelectedUnit.CurrentPosition.Y + coordinates.Y;

                if (SelectedUnit.IsClearWay(new Point(coordinates.X, coordinates.Y)) &&
                    SelectedUnit.IsCorrectMove(new Point(coordinates.X, coordinates.Y)) &&
                    SelectedUnit.IsSomeoneAtThisPosition(new Point(coordinates.X, coordinates.Y)))
                {
                    //Change the selected unit current position if the unit can move on that position
                    SelectedUnit.CurrentPosition = new Point(coordinates.X, coordinates.Y);

                    //Open the secret field if the coordinates matches
                    if (secret.CurrentPosition == SelectedUnit.CurrentPosition)
                    {
                        secret.OpenSecret(SelectedUnit);
                        secret.RevealSound();
                        DrawSecretInfo(secret);
                        DrawSecret();
                    }

                    try
                    {
                        if (coordinates.X < 0 || coordinates.X > 7 || 
                            coordinates.Y <0 || coordinates.Y > 7)
                        {
                            throw new OutOfGameFieldException();
                        }
                        Grid.SetRow(border, (int)coordinates.Y);
                        Grid.SetColumn(border, (int)coordinates.X);
                    }
                    catch (OutOfGameFieldException)
                    {
                        translateTransform = new TranslateTransform();

                        translateTransform.X = 0;
                        translateTransform.Y = 0;

                        mouseXOffset = 0;
                        mouseYOffset = 0;

                        image.RenderTransform = translateTransform;            
                        return;
                    }
                    
                    DeselectUnit();

                    DownLightPossibleMoves();

                    SetTurn();

                    SelectedUnit = null;
                }
            }
            
            translateTransform = new TranslateTransform();

            translateTransform.X = 0;
            translateTransform.Y = 0;

            mouseXOffset = 0;
            mouseYOffset = 0;

            image.RenderTransform = translateTransform;            
        }
        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Image image = (Image)sender;
            Border border = (Border)image.Parent;
            Grid grid = (Grid)border.Parent;

            SelectedUnit = GetUnitOnMousePosition(e.GetPosition(grid), grid);

            RaceTypes RaceTurn = turn ? RaceTypes.Horde : RaceTypes.Alliance;

            if (!isTurnSelected || SelectedUnit.Race != RaceTurn)
            {
                SelectedUnit = null;
                return;
            }

            if (isSomeUnitSelected && (selectedBorder != border))
            {
                DeselectUnit();
            }

            selectedBorder = border;

            image.CaptureMouse();
            isMouseCapture = true;
            mouseXOffset = e.GetPosition(border).X;
            mouseYOffset = e.GetPosition(border).Y;

            if (SelectedUnit != null)
            {
                SelectedUnit.IsSelected = true;
                isSomeUnitSelected = true;

                //Get the hovered image and change the right sidebar image            
                Unit hoveredUnit = GetUnitOnMousePosition(e.GetPosition(grid), grid);
                SetRightSidebarImage(sender);
                SetRightSidebarStats(hoveredUnit);

                SelectedUnit.PlaySelectSound();
            }

            //Mark the selected item
            if (SelectedUnit.GetType().BaseType.Name == "RaceAlliance")
            {
                border.BorderThickness = new Thickness(2, 2, 2, 2);
                border.BorderBrush = Brushes.RoyalBlue;
                border.Background = Brushes.LightSkyBlue;
            }
            else
            {
                border.BorderThickness = new Thickness(2, 2, 2, 2);
                border.BorderBrush = Brushes.Crimson;
                border.Background = Brushes.LightCoral;
            }

            HighLightPossibleMoves();
        }
 public override void OpenSecret(Unit target)
 {
     target.HealthLevel += 2;
     target.MaxHealthLevel += 2;
 }