here is the coordinate header file...coordinate.h...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef COORDINATE_H | |
#define COORDINATE_H | |
#include <stdlib.h> | |
class Coordinate | |
{ | |
public: | |
Coordinate(unsigned | |
int yCoordinate, | |
unsigned int xCoordinate, | |
unsigned int frameHeight, | |
unsigned int frameWidth); | |
int getQtRenderingXCoordinate(); | |
int getQtRenderingYCoordinate(); | |
void changeInXCoordinate(int change); | |
void changeInYCoordinate(int change); | |
void setYCoordinateToZero(int offset); | |
void setXCoordinateToZero(int offset); | |
unsigned int getFrameHeight(); | |
unsigned int getFrameWidth(); | |
void setFrame(unsigned int height, unsigned int width); | |
private: | |
unsigned int m_xCoordinate; | |
unsigned int m_yCoordinate; | |
unsigned int m_frameHeight; | |
unsigned int m_frameWidth; | |
}; | |
#endif // COORDINATE_H |
ball.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef BALL_H | |
#define BALL_H | |
#include "coordinate.h" | |
#include <QPainter> | |
class Ball | |
{ | |
public: | |
Ball(Coordinate coordinate); | |
Ball(Coordinate coordinate, | |
unsigned int radius); | |
Ball(Coordinate coordinate, | |
unsigned int radius, | |
double gravity, | |
double yVelocity, | |
double xVelocity); | |
~Ball(){} | |
void render(QPainter &painter, unsigned int time); | |
bool isCollision(); | |
unsigned int getRadius(); | |
Coordinate* getCoordinate(); | |
private: | |
Ball(); | |
Coordinate m_coordinate; | |
unsigned int m_radius; | |
double m_gravity; | |
double m_xVelocity; | |
double m_yVelocity; | |
}; | |
#endif // BALL_H |
dialog.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DIALOG_H | |
#define DIALOG_H | |
#include <QDialog> | |
#include "ball.h" | |
#include <QTimer> | |
namespace Ui { | |
class Dialog; | |
} | |
class Dialog : public QDialog | |
{ | |
Q_OBJECT | |
public: | |
static Dialog* Instance(Ball ball, bool bgChange, bool frameChange); | |
static Dialog* getInstance(); | |
QList<QString> getColors(); | |
bool getbgChange(); | |
~Dialog(); | |
public slots: | |
void nextFrame(); | |
protected: | |
explicit Dialog(Ball &ball, bool bgChange, bool frameChange,QWidget *parent = 0); | |
void closeEvent(QCloseEvent *); | |
void resizeEvent(QResizeEvent *event); | |
void paintEvent(QPaintEvent *event); | |
private: | |
static Dialog* m_this; | |
Ui::Dialog *ui; | |
Ball m_ball; | |
int m_counter; | |
bool m_bgChange, m_frameChange; | |
QList<QString> m_colors; | |
}; | |
#endif // DIALOG_H |
sample config file looks like this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Frame= 500 450 | |
Radius= 23 | |
Velocity= 12 17 | |
Position= -60 2873 | |
bgChange= true | |
frameChange = true |
now some explanation. coordinate class is for translating coordinate in Qt in a way that we are comfortable of. it means Qt consider top left corner (0,0), and while you're moving to right or down it increases the x and y coordinate. personally, I think we don't need this..well...here it is...
ball class has some functions needs proper implementation beside normal getter/setter methods. render and isCollision functions. isCollision function checks if the ball hit any edges of the box, and render function handle the ball movements.
dialog class is the core of this to put them all together. we used Singleton Design Pattern here to make sure only one instance of dialog exists at any time. I hope I explained it good enough, as I'm still learning. I'll post the implementation files and main method in near future, meanwhile stay hungry, keep coding
Some other information:
- this is not my code. mine was similar but it didn't changed colour when ball hits the box
- again this is implemented in Qt
- the actual website that have the tutorial on basic set up to start on this assignment can be found Here
Hi may I ask that you still keep OO quiz last year?
ReplyDeleteThanks
Hi, unfortunately not. we couldn't take the quiz paper out. quiz is easy, just normal stuff. you should be worried about assignments and final exam.and since the lecturer is changed this semester...last year lecturer was real good..., good luck
ReplyDelete