fishforth.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 34 行

CPP
34
字号
 // from backandforth.cpp
 class BackForthBouncer : public Bouncer
 {
   public:
     BackForthBouncer(Shape * left, Shape * right,
                      double angle, double velocity);
     virtual void updateright (AnimatedCanvas& c, Point& p);
     virtual void updateleft  (AnimatedCanvas& c, Point& p);  
     virtual Shape* clone();
   protected:
     Shape * myLeft;
     Shape * myRight;
 };

 void BackForthBouncer::updateright(AnimatedCanvas& c, Point& p)
 {
    myShape = myLeft;          // use left-facing shape
    myShape->setLocation(p);   // update location
    Bouncer::updateright(c,p); // bounce
 }

 void BackForthBouncer::updateleft(AnimatedCanvas& c, Point& p)
 {
   myShape = myRight;          // use right-facing shape
   myShape->setLocation(p);    // update location
   Bouncer::updateleft(c,p);   // bounce
 }

 Shape* BackForthBouncer::clone()
 {
   return 
      new BackForthBouncer(myLeft,myRight,myAngle,myVelocity);
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?