コード例 #1
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.
                switch (_CurrentState)
                {
                case AIStates.Searching:
                    SearchCoords(ref row, ref column);
                    break;

                case AIStates.TargetingShip:
                    TargetCoords(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.get_Item(row, column) != TileView.Sea); //while inside the grid and not a sea tile do the search
        }
コード例 #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.get_Item(row, column) == TileView.Sea)
     {
         _Targets.Push(new Location(row, column));
     }
 }