home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / demos / puzzle.h < prev    next >
C/C++ Source or Header  |  1998-01-19  |  2KB  |  102 lines

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Puzzle.h : Header file for puzzle.cpp                 */
  4. /*                                                         */
  5. /*---------------------------------------------------------*/
  6. /*
  7.  *      Turbo Vision - Version 2.0
  8.  *
  9.  *      Copyright (c) 1994 by Borland International
  10.  *      All Rights Reserved.
  11.  *
  12.  */
  13.  
  14. #if !defined( __PUZZLE_H )
  15. #define __PUZZLE_H
  16.  
  17. class TPuzzleView : public TView
  18. {
  19.  
  20. public:
  21.  
  22.     TPuzzleView(TRect& r);
  23.     TPuzzleView( StreamableInit ) : TView(streamableInit) { };
  24.     virtual TPalette& getPalette() const;
  25.     virtual void handleEvent(TEvent& event);
  26.     virtual void draw();
  27.     void moveKey(int key);
  28.     void moveTile(TPoint point);
  29.     void scramble();
  30.     void winCheck();
  31.  
  32. private:
  33.  
  34.     char board[6][6];
  35.     int moves;
  36.     char solved;
  37.  
  38.     virtual const char *streamableName() const
  39.         { return name; }
  40.  
  41. protected:
  42.  
  43.     virtual void write( opstream& );
  44.     virtual void *read( ipstream& );
  45.  
  46. public:
  47.  
  48.     static const char * const name;
  49.     static TStreamable *build();
  50.  
  51. };
  52.  
  53. inline ipstream& operator >> ( ipstream& is, TPuzzleView& cl )
  54.     { return is >> (TStreamable&) cl; }
  55. inline ipstream& operator >> ( ipstream& is, TPuzzleView*& cl )
  56.     { return is >> (void *&) cl; }
  57.  
  58. inline opstream& operator << ( opstream& os, TPuzzleView& cl )
  59.     { return os << (TStreamable&) cl; }
  60. inline opstream& operator << ( opstream& os, TPuzzleView* cl )
  61.     { return os << (TStreamable *) cl; }
  62.  
  63.  
  64. class TPuzzleWindow : public TWindow
  65. {
  66.  
  67. public:
  68.  
  69.     TPuzzleWindow();
  70.     TPuzzleWindow( StreamableInit ) :
  71.         TWindow(streamableInit), TWindowInit(&TPuzzleWindow::initFrame) { };
  72.  
  73. private:
  74.  
  75.     virtual const char *streamableName() const
  76.         { return name; }
  77.  
  78. protected:
  79.  
  80.     virtual void write( opstream& );
  81.     virtual void *read( ipstream& );
  82.  
  83. public:
  84.  
  85.     static const char * const name;
  86.     static TStreamable *build();
  87.  
  88. };
  89.  
  90. inline ipstream& operator >> ( ipstream& is, TPuzzleWindow& cl )
  91.     { return is >> (TStreamable&) cl; }
  92. inline ipstream& operator >> ( ipstream& is, TPuzzleWindow*& cl )
  93.     { return is >> (void *&) cl; }
  94.  
  95. inline opstream& operator << ( opstream& os, TPuzzleWindow& cl )
  96.     { return os << (TStreamable&) cl; }
  97. inline opstream& operator << ( opstream& os, TPuzzleWindow* cl )
  98.     { return os << (TStreamable *) cl; }
  99.  
  100.  
  101. #endif      // __PUZZLE_H
  102.