#ifndef KORNJACA_H
#define KORNJACA_H
#include <graphics.h>
class c_kornjaca{
private: // nemoze im se pristupiti izvan objekta
int x;
int y;
int r;
colors color;
public: // moze im se pristupiti izvan projekta
c_kornjaca(int _x, int _y, int _r,colors _color);
~c_kornjaca();
void clearMe();
void drawMe();
void move(int position, int step, int maxX, int maxY);
};
c_kornjaca::c_kornjaca(int _x, int _y, int _r,colors _color){
x=_x;
y=_y;
r=_r;
color=_color;
drawMe();
}
void c_kornjaca::clearMe(){
setcolor(BLACK);
circle(x,y,r);
}
void c_kornjaca::drawMe(){
setcolor(color);
circle(x,y,r);
}
void c_kornjaca::move(int position, int step, int maxX, int maxY){
switch(position){
case KEY_LEFT:
if (x-r-step>0) {
clearMe();
x=x-step;
drawMe();
}
break;
case KEY_RIGHT:
if (x+r+step<maxX) {
clearMe();
x=x+step;
drawMe();
}
break;
case KEY_UP:
if (y-r-step>0) {
clearMe();
y=y-step;
drawMe();
}
break;
case KEY_DOWN:
if (y+r+step<maxY) {
clearMe();
y=y+step;
drawMe();
}
break;
}
}
#endif
No comments:
Post a Comment