#include <iostream.h>

class Point {
public:
   int x_cor, y_cor;
   void move(int dx, int dy);
   // virtualがついているときとついていないときの違いを確かめる
   /* virtual */ void print(void); 
   Point() {};
   Point(int x, int y) { x_cor = x; y_cor = y; }
};

void Point::move(int dx, int dy) {
   x_cor += dx;
   y_cor += dy;
}

void Point::print() {
  cout << "(" << x_cor << ", " << y_cor << ")";
}

// ----------------------------------------------------------------------

class ColorPoint : public Point {
private:
   char color;     // 0-黒 1-赤 2-緑 3-黄 4-青 5-紫 6-水 7-白 
public:
   void print(void);
   void setColor(char c);
   char getColor(void);
   ColorPoint() {}
   ColorPoint(int x, int y, char c) : Point(x, y) {
     setColor(c);
   }
};

void ColorPoint::print() {
   cout << "\033[" << color+30 << "m";
//   cout << "(" << x_cor << ", " << y_cor << ")";
   Point::print();
   cout << "\033[0m";
}

// blacK, Red, Green, Yellow, Blue, Magenta, Cyan, White
void ColorPoint::setColor(char c) {
   char i;
   char cs[] = "KRGYBMCW"; 

   for (i=0; cs[i]; i++) {
      if (c==cs[i]) {
        color = i;
      }
   }
   // 対応する文字がなかったら何もしない。
}

char ColorPoint::getColor() {
   char cs[] = "KRGYBMCW";
   return cs[color];
}

// ----------------------------------------------------------------------

class ShadowPoint : public Point {
private:
   int depth;
public:
   void setDepth(int);
   int getDepth(void); 
   void print(void);
   ShadowPoint() {}
   ShadowPoint(int x, int y, int d) : Point (x, y) {
      depth = d; 
   }
};

int ShadowPoint::getDepth() {
   return depth;
}

void ShadowPoint::setDepth(int d) {
   depth = d;
}

void ShadowPoint::print() {
   int i;

   for (i=0; i<depth; i++) {
      cout << "(";
   }
   cout << x_cor << ", " << y_cor;
   for (i=0; i<depth; i++) {
      cout << ")";
   }
}

void moveInSquare(Point* p) {
   p->move(1, 0);
   p->print();
   cout << " ";
   p->move(0, 1);
   p->print();
   cout << " ";
   p->move(-1, 0);
   p->print();
   cout << " ";
   p->move(0, -1);
   p->print();
   cout << "\n";
}


// ----------------------------------------------------------------------
int main() {
/*
   Point p;
   p.x_cor = 1;  p.y_cor = 2;

   ColorPoint cp;
   cp.x_cor = 3; cp.y_cor = 4; cp.setColor('B');

   ShadowPoint sp;
   sp.x_cor = 5; sp.y_cor = 6; sp.setDepth(5);

   Point* pts[3];
   pts[0]=&p; pts[1]=&cp; pts[2]=&sp;
*/

   Point* pts[3];
   pts[0] = new Point(1, 2);
   pts[1] = new ColorPoint(3, 4, 'G');
   pts[2] = new ShadowPoint(5, 6, 5);
 
   int i; 
   for(i=0; i<3; i++) {
      pts[i]->move(10, 10);
   }
   for(i=0; i<3; i++) {
      pts[i]->print();
      cout << " ";
   }

/*
   Point pts[3];
   pts[0]=p; pts[1]=cp; pts[2]=sp;

   int i; 
   for(i=0; i<3; i++) {
      pts[i].move(10, 10);
   }
   for(i=0; i<3; i++) {
      pts[i].print();
      cout << " ";
   }
*/
/*
   moveInSquare(&p);
   moveInSquare(&cp);
   moveInSquare(&sp);
*/
   cout << endl;
}


#if 0
int main() {
   ShadowPoint p;
   p.x_cor = 10; p.y_cor = 20; p.setDepth(5);
   p.move(1, -1);
   p.print();
   cout << endl;

/*
   ColorPoint p;

   p.x_cor = 10; p.y_cor = 20; p.setColor('B');
   p.move(1, -1);
   p.print();
   cout << endl;
*/
/*
   Point p;


   p.x_cor = 0; p.y_cor = 0;
   p.move(1, -1);
   p.print();
   cout << endl;
*/
/*
   Point *pt;

   pt = new Point;
   pt->x_cor = 0; pt->y_cor = 0;
   pt->move(10, 20);
   pt->print();
   delete pt;
   cout << endl;
*/
}
#endif
