home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_02 / 8n02056a < prev    next >
Text File  |  1990-03-01  |  3KB  |  114 lines

  1.  
  2.  
  3. *****Listing 7*****
  4.  
  5. 001  #include <stdio.h>
  6. 002  #include <stdarg.h>
  7. 003  #include "utility.h"
  8. 004  
  9. 005  /********************************************************/
  10. 006  /* CLASS GRAPHICAL OBJECT */
  11. 007  
  12. 008  class graph_obj {
  13. 009  public:
  14. 010      int y;
  15. 011      int x;
  16. 012      void init(int y, int x);
  17. 013      void move(int y, int x);
  18. 014      virtual void draw(int color){};
  19. 015  };
  20. 016  
  21. 017  void graph_obj::init(int y2, int x2)
  22. 018  {
  23. 019      y = y2;
  24. 020      x = x2;
  25. 021  }
  26. 022  
  27. 023  void graph_obj::move(int y_delta, int x_delta)
  28. 024  {
  29. 025      draw(g_black);
  30. 026      x += x_delta;
  31. 027      y += y_delta;
  32. 028      draw(g_white);
  33. 029  }
  34. 030  
  35. 031  /********************************************************/
  36. 032  /* CLASS CIRCLE */
  37. 033  
  38. 034  class circle: public graph_obj {
  39. 035  public:
  40. 036      int radius;
  41. 037      void init(int y, int x, int radius);
  42. 038      void draw(int color);
  43. 039  };
  44. 040  
  45. 041  void circle::init(int y2, int x2, int radius2)
  46. 042  {
  47. 043      graph_obj::init(y2, x2);
  48. 044      radius = radius2;
  49. 045      draw(g_white);
  50. 046  }
  51. 047  
  52. 048  void circle::draw(int color)
  53. 049  {
  54. 050      g_circle(y, x, radius, color);
  55. 051  }
  56. 052  
  57. 053  /********************************************************/
  58. 054  /* CLASS SQUARE */
  59. 055  
  60. 056  class square: public graph_obj {
  61. 057  public:
  62. 058      int size;
  63. 059      void init(int y, int x, int radius);
  64. 060      void draw(int color);
  65. 061  };
  66. 062  
  67. 063  void square::init(int y2, int x2, int size2)
  68. 064  {
  69. 065      graph_obj::init(y2, x2);
  70. 066      size = size2;
  71. 067      draw(g_white);
  72. 068  }
  73. 069  
  74. 070  void square::draw(int color)
  75. 071  {
  76. 072      g_square(y, x, size, color);
  77. 073  }
  78. 074  
  79. 075  /********************************************************/
  80. 076  /* CLASS DOUBLE_CIRCLE */
  81. 077  
  82. 078  class double_circle: public circle {
  83. 079  public:
  84. 080      void draw(int color);
  85. 081  };
  86. 082  
  87. 083  void double_circle::draw(int color)
  88. 084  {
  89. 085      g_circle(y, x, radius, color);
  90. 086      g_circle(y, x, radius - 2, color);
  91. 087  }
  92. 088  
  93. 089  /********************************************************/
  94. 090  
  95. 091  int main(void);
  96. 092  int main(void)
  97. 093  {
  98. 094      int x;
  99. 095      circle c1;
  100. 096      square s1;
  101. 097      double_circle dc1;
  102. 098      g_init();
  103. 099      c1.init(40, 40, 20);
  104. 100      s1.init(40, 100, 20);
  105. 101      dc1.init(40, 160, 20);
  106. 102      for (x = 0; x < 100; ++x) {
  107. 103          c1.move(1, 1);
  108. 104          s1.move(1, 0);
  109. 105          dc1.move(0, -1);
  110. 106      }
  111. 107      cleanup();
  112. 108      return (0);
  113. 109  }
  114.