159.234 Object Oriented Programming Tutorial 4: OO Principles in Graphical Programs Part One

silkthrilledSoftware and s/w Development

Nov 18, 2013 (3 years and 8 months ago)

69 views

159.234 Object Oriented Programming Tutorial 4:
OO Principles in Graphical Programs Part One
Tutors: Anton Gerdelan + Daniel Playne
Use the Object Oriented principles that you have learned to write a class called

Alien
.
Q1.
Divide the class into
public
and
private
sections.
Q2.
Create variables within the class to store:
·
X and Y position of the alien.
·
Current Speed (in both X and Y directions)
·
The colour of the alien
·
Boolean that indicate if it: is
alive
, has been
shot
, can
see

its enemy
.
·
Information about what the alien looks like (in terms of circles and rectangles)
Q3.
Write either a constructor or an
init()
function that will allow the programmer

to set the initial position & colour of the alien, and reset all of the other variables.
Q4.
Write a function called
update()
that will change the X and Y position of the

alien based on the current speed.
Q5.
Write an internal function, that will be called from inside
update()
, that will

change the colour of the robot.
Q6.
Write a function
getPos()
that will return (pass back) two references, so that

the
main()
function can get the position of the alien.
Q7
. Write two functions;
setSpeed()
and
getSpeed()
that will be called by the

main program to get and set the speed of an alien object.
Q8.
Write a function
draw()
that will be called
inside the main drawing function
to

draw the graphical parts of the alien to the screen.
*Q9.
A function
checkIfHit(int x, int y)
that will check if a bullet at

position
(x,y)
will have hit the alien.
Bring the results of this tutorial for use in the next tutorial.
159.234 Object Oriented Programming Tutorial 5:
OO Principles in Graphical Programs Part Two
Tutors: Anton Gerdelan + Daniel Playne
This tutorial is based on the class
Alien
that you made in tutorial 4.
Q1.
Write a basic main() function. Include a main game loop.
Q2.
Write a global function
init()
and call this function in your main program.

Inside
init()
include code that will instantiate four objects of the class
Alien
.

Allocate any memory you may need. Set the aliens to start at different positions on the

screen (assume you have dimensions
800*600
). Give all the aliens different speeds

and colours.
Q3.
Write a global function
shutdown()
and call this function in your main

program. Free any memory that you allocated inside your
init()
function. If your

classes used constructors, you will activate their destructors by using the
delete

command.
Q4.
Write a global function
update()
and call this function inside your main

program. Inside the update function, one by one, call the functions of your alien

objects that will update the aliens’ positions based on their current speed.
Q5.
Write a global function
draw()
and call this function inside your main program.

Add
pseudo-code
to your function that will set up a page for drawing (using double

buffering) and display another page.
Add code inside this function that will call the drawing functions for all of your alien

objects.
*Q6.
Add
pseudo-code
to your program so that the
elapsed time
is used as part of

speed calculations. Consider how you might capture the elapsed time using the

timeGetTime()
function. (There is an example of how I have done this on my

homepage).