home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / BARNHART / SO_WALL.CPP < prev    next >
C/C++ Source or Header  |  1993-11-21  |  2KB  |  79 lines

  1.  
  2. // so_wall.cpp - implements objects Wall and Rungs
  3.  
  4. // Andy Barnhart
  5. // This program is provided as a sample to accompany an article on graphics
  6. //    animation using C++
  7. // This seems to work for me and I hope it works for you. No other warranty
  8. //    is expressed or implied.
  9.  
  10. #include <so_all.hpp>
  11.                                                   
  12. // These objects as very trivial. All they do are create one or more ScreenItem
  13. //   objects which are each pieces of the wall, in either a vertical or
  14. //   horizontal manner. They are not true aggregate objects, however. The
  15. //   objects they create are not "owned", but created in the constructor
  16. //   and deleted in the destructor, but left to their own inherent behavior
  17. //   during play.
  18.                                                   
  19. Wall::Wall( char *res, int ix, int iy, int len, int vert)
  20.         : ScreenItem( res, ix, iy)
  21.     {
  22.     SOType = TYPE_WALL;
  23.     mems = len;
  24.     if( vert)
  25.         hmult = len;
  26.     else
  27.         wmult = len;
  28.     dir = vert;
  29.     if( len > 1)
  30.         {
  31.         int i;
  32.         for (i = 1; i < len; i++)
  33.             {
  34.             if( vert)
  35.                 iy += height;
  36.             else
  37.                 ix += width;
  38.             lastmem = new ScreenItem( res, ix, iy);
  39.             lastmem->SOType = TYPE_WALL;
  40.             }
  41.         }
  42.     else
  43.         {
  44.         lastmem = NULL;
  45.         }
  46.     }
  47.  
  48. Wall::~Wall( void)
  49.     {
  50.     if( lastmem != NULL)
  51.         {
  52.         ScreenItem *cur, *nxt;
  53.         cur = (ScreenItem *) Next();
  54.         while( cur != lastmem)
  55.             {
  56.             nxt = (ScreenItem *) cur->Next();
  57.             delete( cur);
  58.             cur = nxt;
  59.             }
  60.         delete( lastmem);
  61.         }
  62.     }
  63.  
  64. Rungs::Rungs(char *res, int ix, int iy, int len, int vert)
  65.         : Wall( res, ix, iy, len, vert)
  66.     {
  67.     if( lastmem != NULL)
  68.         {
  69.         ScreenItem *cur;
  70.         cur = (ScreenItem *) Next();
  71.         while( cur != lastmem)
  72.             {
  73.             cur->SOType = TYPE_RUNGS;
  74.             cur = (ScreenItem *) cur->Next();
  75.             }
  76.         lastmem->SOType = TYPE_RUNGS;
  77.         }
  78.     SOType = TYPE_RUNGS;
  79.     }