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

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
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation VII.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation V.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation IX.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_recitation 13.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation 1.ppt
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_vector_string.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Start with C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Random Number_Graphics.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_programming style guide for C plusplus.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_objects and classes.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Vg101.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Introduction to Computer and Programming.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Function.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_files_DataBase Design.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Expressions and Statements.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_examples on class design.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_Array and its Applications.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_20 Looking Ahead.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_19 Recursion 1.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Lecture Notes_16 MATLAB environment short.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation X.ppt
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(1/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第十四章 MCS-51单片机(2/2).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第一章 微机原理与接口技术绪论(朱兰娟).pdf
- 上海交通大学:《微机原理与接口技术》课程教学资源(课件讲稿)第二章 8086系统结构.pdf
- 上海交通大学:《数据库系统原理 The principle of Database System》课程教学资源(课件讲稿)chapter9 SQL in a server environment.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Pointer Review Solution.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Pointer Review.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Practice Final 1.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_practice Final 2.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_practice Final 3.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Solution for Practice Final 1.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)05年期末习题_Solution for Practice Final 2.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_I.运算符重载.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_II.继承与派生.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_III.多态性.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_IV.异常处理与模板.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_V. 流库.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_VI.类与对象.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_VII.类与对象的高级操作.pdf