Skini winbgim.h biblioteku (to je biblioteka za borlandov graphics)
http://apcsteacher.com/reference/cpp/dev_cpp_setup.htm
Takodje kad radis Class header ne pocinje sa #ifdef ...
napravio sam greske...
bomba.cpp
#include <winbgim.h>
#include "bomba.h"
void Bomba :: crtanje()
{
rectangle(x,y,(x+20),(y+5));
}
void Bomba :: brisanje()
{
setcolor(WHITE);
rectangle(x,y,(x+20),(y+5));
setcolor(BLACK);
y = y + 5;
if(y>490){
y = -((static_cast <float> (rand()) / RAND_MAX) * 480);
x = ((static_cast <float> (rand()) / RAND_MAX) * 620);
}
}
Bomba :: Bomba(){
x = ((static_cast <float> (rand()) / RAND_MAX) * 620);
y = ((static_cast <float> (rand()) / RAND_MAX) * 480);
}
bomba.h
class Bomba
{
private:
int x, y;
public:
Bomba();
void crtanje();
void brisanje();
};
main.cpp
#include <cstdlib>
#include <iostream>
#include <winbgim.h>
#include <ctime>
using namespace std;
#include "objekt.h"
#include "bomba.h"
int main()
{
Bomba Bomba1, bomba2, bomba3;
objekt brod;
int gdriver = 9;
int gmode = 2;
initgraph(&gdriver, &gmode, "");
setbkcolor (WHITE);
setcolor (BLACK);
cleardevice();
char odgovor = 'd';
srand(time(NULL));
brod.crtaj();
do{
Bomba1.brisanje();
bomba2.brisanje();
bomba3.brisanje();
Bomba1.crtanje();
bomba2.crtanje();
bomba3.crtanje();
delay(2);
if (kbhit()){
odgovor = getch();
brod.pomak(odgovor);
}
brod.crtaj();
}while (odgovor!= 'k');
return 0;
}
objekt.h
class objekt
{
private:
int x;
char kretanje;
public:
objekt()
{
x = 290;
}
void pomak(char);
void crtaj();
};
objekt.cpp
#include <winbgim.h>
#include "objekt.h"
void objekt :: pomak(char tipka)
{
kretanje = tipka;
if (kretanje == 75)
{
setcolor (WHITE);
rectangle(x, 432, x+60, 438);
setcolor (BLACK);
x = x - 5;
}
if (kretanje == 77)
{
setcolor (WHITE);
rectangle(x, 432, x+60, 438);
setcolor (BLACK);
x = x + 5;
}
}
void objekt :: crtaj()
{
rectangle(x, 432, x+60, 438);
}
|