/// <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.GetItem(row, column) == TileView.Sea)) { _Targets.Push(new Target(new Location(row, column), _CurrentTarget.ShotAt)); } }
/// <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 { SearchCoords(ref row, ref column); }while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.GetItem(row, column) != TileView.Sea)); // while inside the grid and not a sea tile do the search }
/// <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"); //break; } } }while ((row < 0 || column < 0 || row >= EnemyGrid.Height || column >= EnemyGrid.Width || EnemyGrid.GetItem(row, column) != TileView.Sea)); // while inside the grid and not a sea tile do the search }
/// <summary> /// Avoid the rows and columns added /// </summary> /// <param name="row">the row of the targets location</param> /// <param name="column">the column of the targets location</param> private void AddAvoidingTarget(int row, int column) { if (row >= 0 && column >= 0 && row < EnemyGrid.Height && column < EnemyGrid.Width && EnemyGrid.GetItem(row, column) == TileView.Sea) { _Targets.Push(new Location(row, column)); } }