home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch5 / Board.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.2 KB  |  65 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. /////////////////////////////////////////////////////////////
  22. // Board.h: Represent a tictactoe board
  23. /////////////////////////////////////////////////////////////
  24. #ifndef BOARD_H
  25. #define BOARD_H
  26.  
  27. // Different versions of C++ (2.X, 3.X, etc.) treat enumerated types declared
  28. // within a class differently. Although I prefer encapsulating these values in the 
  29. // Board class, the easiest way  to make these examples work with all versions
  30. // is to just move them out of the class declaration:
  31.  
  32. enum MoveStatus { validMove, illegalMove };
  33. enum markType { NOBODYYET, OO, XX, TIE };
  34.  
  35. // Convenient values
  36.     
  37. class Board {
  38.     
  39.   protected:
  40.     
  41.     int  _state[9];        // Internal game state
  42.     int  _freeList[9];     // List used to report free squares
  43.     int  numFreeSquares(); 
  44.     int  *_winningPattern; // Pattern last tested when someone wins
  45.     static int _winningBits[8][9];
  46.     
  47.   public:
  48.  
  49.     Board();
  50.     MoveStatus recordMove ( int, markType ); // Record an X or an O
  51.     
  52.     // Return number of available squares, and their indexes
  53.     
  54.     int *const freeSquares ( int& );   
  55.     
  56.     // Public access for winning pattern of squares
  57.     
  58.     int *const winningSquares() { return _winningPattern; }
  59.     
  60.     void clear();           // Clear and reset the board
  61.     markType whoHasWon();   // Return code for possible winner
  62.     virtual const char *const className() { return "Board"; }
  63. };
  64. #endif
  65.