VG101 RECITATION 8 By TAs
VG101 RECITATION 8 By TAs
CONTENTS o Brief review of class o Strategy for assignment 9 o Questions about assignment 7,8
CONTENTS Brief review of class Strategy for assignment 9 Questions about assignment 7, 8
BRIEF REVIEW OF CLASS o In header file: ·Base class · Constructors Private/protected/public member Data/function member ·Accessors/utators o In cpp file: Implementation of class functions
BRIEF REVIEW OF CLASS In header file: Base class Constructors Private/protected/public member Data/ function member Accessors/ Mutators In cpp file: Implementation of class functions
class RectangleT:public GObjectT { Base class PointT llp,urp;∠ Data members Private void drawRect ( member public: constructor RectangleT(const double x0=0,const double y0=0, const double x1=0,const double y1=0, const string clr ="Blue",const double fill=0); RectangleT(const PointT &p0,const PointT &p1, const string clr ="Blue",const double fill=0); const PointT &getLocation (return llp;) double getWidth const; double getHeight const; Public double getArea const; Get Set member void setLocation (const double x,const double y); void setLocation(const PointT p); void setWidth (const double w); void setHeight (const double h); void draw 0; Function void draw (const string clr,const double density =0); members
class RectangleT : public GObjectT { PointT llp, urp; void drawRect (); public: RectangleT (const double x0 = 0, const double y0 = 0, const double x1 = 0, const double y1 = 0, const string clr = "Blue", const double fill = 0); RectangleT (const PointT &p0, const PointT &p1, const string clr = "Blue", const double fill = 0); const PointT &getLocation () {return llp;} double getWidth () const; double getHeight () const; double getArea () const; void setLocation (const double x, const double y); void setLocation (const PointT p); void setWidth (const double w); void setHeight (const double h); void draw (); void draw (const string clr, const double density = 0); }; Base class Private member Public member constructor Get & Set Data members Function members
BRIEF REVIEW OF CLASS o Base class Base class will be constructed first ·∥BallT is a derived class from ArcT ·/∥A ball is an arc of360 degree BallT (double r=0):ArcT (r,0,360,"Blue",1); o Constructors Always define a default constructor(suggested) One and only one of the constructors must be called
BRIEF REVIEW OF CLASS Base class Base class will be constructed first // BallT is a derived class from ArcT // A ball is an arc of 360 degree BallT (double r = 0) : ArcT (r, 0, 360, "Blue" , 1) {}; Constructors Always define a default constructor (suggested) One and only one of the constructors must be called
STRATEGY FOR ASSIGNMENT 9 o Divide the project into several stages: ·1.class design ·2.initialization 3.get ball/paddle moving ·4.handle collisions 。5.end of game o One function for one simple purpose only o Test your functions one by one o Test your program after finishing each stage o Have fun after finishing the whole project
STRATEGY FOR ASSIGNMENT 9 Divide the project into several stages: 1. class design 2. initialization 3. get ball/paddle moving 4. handle collisions 5. end of game One function for one simple purpose only Test your functions one by one Test your program after finishing each stage Have fun after finishing the whole project
STAGE ONE:CLASS DESIGN o Game window:GwindowT Represent the application window o Brick wall Represent all the bricks Row,column,vector of bricks... o Brick:RectangleT ·Represent one brick Color,position(row,column),location(x,y)... o Paddle:RectangleT ·Location(x,y).…
STAGE ONE: CLASS DESIGN Game window: GwindowT Represent the application window Brick wall Represent all the bricks Row, column, vector of bricks… Brick: RectangleT Represent one brick Color, position(row, column), location( x, y)… Paddle: RectangleT Location(x, y) …
STAGE ONE:CLASS DESIGN o What need you to design: ·l.constructors 2.data members and their accessors and mutators 3.special functions: ·Samples: ·∥let the paddle move when being selected bool paddle::selected(...) void paddle::move(...) .//draw the brick wall,the main function in initialization void brickWall::draw(...)
STAGE ONE: CLASS DESIGN What need you to design: 1. constructors 2. data members and their accessors and mutators 3. special functions: Samples: // let the paddle move when being selected bool paddle::selected(…) void paddle::move(…) // draw the brick wall, the main function in initialization void brickWall::draw(…)
STAGE TWO:INITIALIZATION o Initialize the game: 1.init brick wall,give color,location to each brick 2.init paddle,give color,location to it 3.draw the window ,the wall and paddle o No movement in this stage o Refer to the lecture note on drawing the brick wall
STAGE TWO: INITIALIZATION Initialize the game: 1. init brick wall, give color, location to each brick 2. init paddle, give color, location to it 3. draw the window ,the wall and paddle No movement in this stage Refer to the lecture note on drawing the brick wall
STAGE THREE:GET BALL/PADDLE MOVING o To move the ball Just as what you do in assignment 5-2 Consider the brick wall as a static border of the window,don't drop out the brick been clicked o To move the paddle Just as the movingBall program discussed in lecture (page 46) Don't let the paddle move out of the window o These are not difficult,but they are basis for the following stage
STAGE THREE: GET BALL/PADDLE MOVING To move the ball Just as what you do in assignment 5-2 Consider the brick wall as a static border of the window, don’t drop out the brick been clicked To move the paddle Just as the movingBall program discussed in lecture (page 46) Don’t let the paddle move out of the window These are not difficult, but they are basis for the following stage