当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VIII

资源类别:文库,文档格式:PPT,文档页数:14,文件大小:580KB,团购合买
点击下载完整版文档(PPT)

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

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共14页,试读已结束,阅读完整版请下载
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有