Esempio n. 1
0
 /// <summary>
 /// Just shoot randomly
 /// </summary>
 /// <param name="row">the generated row</param>
 /// <param name="column">the generated column</param>
 protected override void GenerateCoords(ref int row, ref int column)
 {
     do
     {
         SearchCoords(ref row, ref column);
     } while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.Item(row, column) != TileView.Sea));
     //while inside the grid and not a sea tile do the search
 }
Esempio n. 2
0
 /// <summary>
 ///     ''' AddTarget will add the targets it will shoot onto a stack
 ///     ''' </summary>
 ///     ''' <param name="row">the row of the targets location</param>
 ///     ''' <param name="column">the column of the targets location</param>
 private void AddTarget(int row, int column)
 {
     if ((row >= 0 && column >= 0 && row < EnemyGrid.Height && column < EnemyGrid.Width && EnemyGrid.Item(row, column) == TileView.Sea))
     {
         _Targets.Push(new Target(new Location(row, column), _CurrentTarget.ShotAt));
     }
 }
Esempio n. 3
0
    /// <summary>
    ///     ''' GenerateCoords will call upon the right methods to generate the appropriate shooting
    ///     ''' coordinates
    ///     ''' </summary>
    ///     ''' <param name="row">the row that will be shot at</param>
    ///     ''' <param name="column">the column that will be shot at</param>
    protected override void GenerateCoords(ref int row, ref int column)
    {
        do
        {
            _CurrentTarget = null;

            // check which state the AI is in and uppon that choose which coordinate generation
            // method will be used.
            switch (_CurrentState)
            {
            case AIStates.Searching:
            {
                SearchCoords(ref row, ref column);
                break;
            }

            case AIStates.TargetingShip:
            case AIStates.HittingShip:
            {
                TargetCoords(ref row, ref column);
                break;
            }

            default:
            {
                throw new ApplicationException("AI has gone in an invalid state");
            }
            }
        }while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.Item(row, column) != TileView.Sea)); // while inside the grid and not a sea tile do the search
    }
Esempio n. 4
0
    /// <summary>
    /// GenerateCoordinates should generate random shooting coordinates
    /// only when it has not found a ship, or has destroyed a ship and
    /// needs new shooting coordinates
    /// </summary>
    /// <param name="row">the generated row</param>
    /// <param name="column">the generated column</param>
    protected override void GenerateCoords(ref int row, ref int column)
    {
        do
        {
            switch (_CurrentState)
            {
            case AIStates.Searching:
                SearchCoords(ref row, ref column);
                break;

            default:
                throw new ApplicationException("AI has gone in an imvalid state");
            }
        } while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.Item(row, column) != TileView.Sea));
    }
Esempio n. 5
0
 /// <summary>
 /// GenerateCoordinates should generate random shooting coordinates
 /// only when it has not found a ship, or has destroyed a ship and
 /// needs new shooting coordinates
 /// </summary>
 /// <param name="row">the generated row</param>
 /// <param name="column">the generated column</param>
 protected override void GenerateCoords(ref int row, ref int column)
 {
     do
     {
         //check which state the AI is in and uppon that choose which coordinate generation
         //method will be used.
         SearchCoords(ref row, ref column);
     } while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.Item(row, column) != TileView.Sea));
     //while inside the grid and not a sea tile do the search
 }
Esempio n. 6
0
        /// <summary>
        /// GenerateCoordinates should generate random shooting coordinates
        /// only when it has not found a ship, or has destroyed a ship and
        /// needs new shooting coordinates
        /// <param name="row">the generated row</param>
        /// <param name="column">the generated column</param>
        /// </summary>
        protected override void GenerateCoords(ref int row, ref int column)
        {
            do
            {
                //// Check which state the AI is in and upon that choose which coordinate generation
                //// method will be used.
                //switch (_CurrentState)
                //{

                //    case AIStates.Searching:
                //        {

                //            break;
                //        }

                //    case AIStates.TargetingShip:
                //        {
                //            TargetCoords(ref row, ref column);
                //            break;
                //        }

                //    default:
                //        {
                //            throw new ApplicationException("AI has gone in an imvalid state");
                //            break;
                //        }
                //}

                SearchCoords(ref row, ref column);
            }while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.Item(row, column) != TileView.Sea)); // while inside the grid and not a sea tile do the search
        }