Source of Queen.h


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: /** Listing 5-2.
  5:     @file Queen.h */

  7: #ifndef _QUEEN
  8: #define _QUEEN

 10: class Board; // Forward declaration of Board class

 12: /** The Queen class. */
 13: class Queen
 14: {
 15: private:
 16:    int row; // Row (or prospective row) of queen if it is on the board
 17:    int col; // Column (or prospective column) of queen if it is on the board
 18:    
 19:    // All queens share the same board
 20:    static const Board* boardPtr;

 22: public:
 23:    /** Places a queen in upper-left corner of board. */
 24:    Queen();
 25:          
 26:    /** Places a queen in supplied location. */
 27:    Queen(int inRow, int inCol);
 28:    
 29:    /** @return Column number. */
 30:    int getCol() const;
 31:    
 32:    /** @return Row number. */
 33:    int getRow() const;
 34:    
 35:    /** Moves queen to next row. */
 36:    void nextRow();
 37:    
 38:    /** Sees whether the queen is under attack by another queen.
 39:     @return  True if another queen is in the same row or the same
 40:        diagonal; otherwise, returns false. */
 41:    bool isUnderAttack() const;
 42:    
 43:    /** Saves a pointer to the board for all queens. */
 44:    static void setBoard(const Board* bPtr);   
 45: }; // end Queen
 46: #endif