Ejemplo n.º 1
0
        public BattleTile FindNearestGladiatorOnPlayerTeam()
        {
            BattleTile nearestTileWithPlayerGladiator = null;
            double     lowestDist = 100.0;
            double     dist       = 0;

            foreach (Gladiator glad in BattleTile.MyTeam)
            {
                try
                {
                    if (glad.State == State.alive)
                    {
                        dist = (int)Math.Sqrt(Math.Pow(glad.X - SelectedTile.X, 2) + Math.Pow(glad.Y - SelectedTile.Y, 2));
                        if (dist < lowestDist)
                        {
                            lowestDist = dist;
                            nearestTileWithPlayerGladiator = glad.CurrentTile;
                        }
                    }
                }
                catch
                {
                    return(null);
                }
            }
            return(nearestTileWithPlayerGladiator);
        }
Ejemplo n.º 2
0
        public void AttackGladiator(BattleTile attacker, BattleTile defender, RichTextBox rtbBattleMonitor)
        {
            attacker.gladiator.HasMoved = true;
            rtbBattleMonitor.Text      += attacker.gladiator.Name + " attacks " + defender.gladiator.Name + "." + Environment.NewLine;
            rtbBattleMonitor.Refresh();
            int damage = GladiatorDamageCalculator(attacker.gladiator, defender.gladiator);

            rtbBattleMonitor.Text += damage + " damage is dealt." + Environment.NewLine;
            rtbBattleMonitor.Refresh();
            if (defender.gladiator.CurrentHP <= 0)
            {
                rtbBattleMonitor.Text           += defender.gladiator.Name + " has fainted." + Environment.NewLine + Environment.NewLine;
                attacker.gladiator.potentialEXP += defender.gladiator.RewardEXP;
                rtbBattleMonitor.Refresh();
                defender.gladiator.State = State.dead;
                SelectedTile             = null;
                defender.gladiator       = null;
                defender.ShowTileIsOccupied();
            }
            else
            {
                rtbBattleMonitor.Text += Environment.NewLine;
                SelectedTile           = null;
            }
        }
Ejemplo n.º 3
0
 public bool TargetTileOccupied(BattleTile target)
 {
     if (target.gladiator == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 4
0
 public void MoveGladiator(BattleTile targetTile)
 {
     targetTile.gladiator             = SelectedTile.gladiator;
     targetTile.gladiator.X           = targetTile.X;
     targetTile.gladiator.Y           = targetTile.Y;
     targetTile.gladiator.CurrentTile = targetTile;
     SelectedTile.gladiator.HasMoved  = true;
     SelectedTile.gladiator           = null;
     SelectedTile.Button.Text         = "";
     SelectedTile = null;
     targetTile.ShowTileIsOccupied();
 }
Ejemplo n.º 5
0
 public bool TileIsInAttackRange(BattleTile target)
 {
     if (SelectedTile.gladiator.X > target.X + target.gladiator.AttackRange ||
         SelectedTile.gladiator.X < target.X - target.gladiator.AttackRange ||
         SelectedTile.gladiator.Y > target.Y + target.gladiator.AttackRange ||
         SelectedTile.gladiator.Y < target.Y - target.gladiator.AttackRange)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 6
0
 public bool TileIsInMovementRange(BattleTile target)
 {
     if (target.X > SelectedTile.X + SelectedTile.gladiator.MovementRange ||
         target.X < SelectedTile.X - SelectedTile.gladiator.MovementRange ||
         target.Y > SelectedTile.Y + SelectedTile.gladiator.MovementRange ||
         target.Y < SelectedTile.Y - SelectedTile.gladiator.MovementRange)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 7
0
 public void SelectGladiator(BattleTile clickedTile, RichTextBox rtbBattleMonitor)
 {
     if (clickedTile.gladiator != null && clickedTile.gladiator.InPlayersTeam) //no gladiator selected so selects gladiator
     {
         if (clickedTile.gladiator.HasMoved)
         {
             rtbBattleMonitor.Text += clickedTile.gladiator.Name + " has already moved this turn." + Environment.NewLine + Environment.NewLine;
         }
         else
         {
             SelectedTile           = this;
             rtbBattleMonitor.Text += SelectedTile.gladiator.Name + " selected." + Environment.NewLine;
         }
     }
 }
Ejemplo n.º 8
0
        public void AIGladiatorTurn(BattleTile NearestTile)
        {
            if (NearestTile == null)
            {
                return;
            }
            if (SelectedTile.TileIsInAttackRange(NearestTile))
            {
                SelectedTile.AttackGladiator(SelectedTile, NearestTile, rtbBattleMonitor);
            }

            else if (SelectedTile.TileIsInMovementRange(NearestTile))
            {
                int XToMove = NearestTile.X - SelectedTile.X;
                if (XToMove > 0)
                {
                    XToMove--;
                }
                else if (XToMove < 0)
                {
                    XToMove++;
                }

                int YToMove = NearestTile.Y - SelectedTile.Y;
                if (YToMove > 0)
                {
                    YToMove--;
                }
                else if (YToMove < 0)
                {
                    YToMove++;
                }

                int targetX = SelectedTile.X + XToMove;
                int targetY = SelectedTile.Y + YToMove;

                BattleTile tileToMoveTo = ArenaField[targetX, targetY];

                if (!TargetTileOccupied(tileToMoveTo))
                {
                    SelectedTile.MoveGladiator(tileToMoveTo);
                }
                else
                {
                }
            }
        }
Ejemplo n.º 9
0
        public BattleTile(Panel panelIn, Occupied state, int height, int width, int x, int y, int mapSquare, RichTextBox rtbbattleMonitor, BattleTile selectedTile, List <Gladiator> myTeam, List <Gladiator> enemyTeam, BattleTile[,] arena, int yHeight)
        {
            Button           = new Button();
            gladiator        = null;
            Height           = height;
            Width            = width;
            TopLoc           = height * y;
            LeftLoc          = width * x;
            X                = x + 1;
            Y                = yHeight - y;
            rtbBattleMonitor = rtbbattleMonitor;
            SelectedTile     = selectedTile;
            MyTeam           = myTeam;
            EnemyTeam        = enemyTeam;
            ArenaField       = arena;

            Button.Click += new EventHandler(buttonClicked);

            switch (mapSquare)
            {
            case 0:
            {
                Button.BackColor = Color.Aqua;
                break;
            }

            case 1:
            {
                Button.BackColor = Color.Aquamarine;
                break;
            }
            }
            Button.Height = Height;
            Button.Width  = Width;
            Button.Left   = LeftLoc;
            Button.Top    = TopLoc;

            Button.Refresh();
        }
Ejemplo n.º 10
0
 public void buttonClicked(object sender, EventArgs e)
 {
     if (!GladiatorIsSelected())
     {
         SelectGladiator(this, rtbBattleMonitor);
     }
     else  //gladiator is already selected
     {
         if (!TileIsInMovementRange(this) && !TargetTileOccupied(this))
         {
             rtbBattleMonitor.Text += "Cannot move here, out of range" + Environment.NewLine;
             SelectedTile           = null;
         }
         else
         {
             if (!TargetTileOccupied(this)) //square empty so puts selected there
             {
                 MoveGladiator(this);
             }
             else if (this == SelectedTile) //on top of self
             {
                 rtbBattleMonitor.Text += "You are already here." + Environment.NewLine;
                 SelectedTile           = null;
             }
             else
             {
                 if (this.gladiator.InPlayersTeam == SelectedTile.gladiator.InPlayersTeam) //can't move in to team mate
                 {
                     rtbBattleMonitor.Text += "You cannot move here as this tile is occupied." + Environment.NewLine;
                     SelectedTile           = null;
                 }
                 else //attack enemy
                 {
                     if (TileIsInAttackRange(this))
                     {
                         AttackGladiator(SelectedTile, this, rtbBattleMonitor);
                     }
                     else
                     {
                         rtbBattleMonitor.Text += "Out of attack range.";
                         SelectedTile           = null;
                     }
                 }
             }
         }
         rtbBattleMonitor.Text += Environment.NewLine;
     }
     if (CheckTeamAllDead(EnemyTeam))
     {
         BattleWon();
     }
     if (CheckTeamAllDead(MyTeam))
     {
         BattleLost();
     }
     if (CheckAllTeamMoved(MyTeam))
     {
         foreach (Gladiator glad in EnemyTeam)
         {
             if (glad.State == State.alive)
             {
                 SelectedTile = glad.CurrentTile;
             }
             try
             {
                 AIGladiatorTurn(FindNearestGladiatorOnPlayerTeam());
             }
             catch
             {
                 return;
             }
         }
         SelectedTile = null;
     }
 }