#include <iostream>
#include <stdio.h> //printf/getch itp.
#include <conio.h> //kbhit()
#include <graphics.h> //funkcje graficzne BGI
#include <windows.h> //Sleep(xx)
#include <time.h>
using namespace std;
class figura
{
protected:
double x,y,a;
public:
figura();
~figura();
virtual void rysuj(int kolor);
void przesun(int dx, int dy);
};
figura::figura()
{
x=rand()%640;
y=rand()%480;
a=rand()%200+20;
}
void figura::rysuj(int kolor)
{
setcolor(kolor);
}
void figura::przesun(int dx, int dy)
{
rysuj(BLACK);
x+=dx;
y+=dy;
rysuj(LIGHTGREEN);
}
figura::~figura()
{
rysuj(BLACK);
}
class kwadrat: public figura
{
public:
void rysuj(int kolor);
};
void kwadrat::rysuj(int kolor)
{
setcolor(kolor);
rectangle(x-0.5*a,y-0.5*a,x+0.5*a,y+0.5*a);
}
class kolo: public figura
{
public:
void rysuj(int kolor);
};
void kolo::rysuj(int kolor)
{
setcolor(kolor);
circle(x,y,a);
}
int main()
{
int GraphDriver = DETECT;
int GraphMode;
int ErrorCode;
initgraph(&GraphDriver, &GraphMode,"");
ErrorCode = graphresult();
if(ErrorCode != grOk)
{
printf("Blad trybu graficznego: %sn", grapherrormsg(ErrorCode) );
exit(1);
}
//Tutaj kod związany z rysowaniem
//******************************************************************************************************************
srand(time(NULL));
figura *a[20];
int i,x,p,h,k;
char z,b;
for(i=0; i<20; i++)
{
a[i]=NULL;
}
do
{
system("CLS");
cout<<"R-RysujnZ-zmazujnP-przesunnQ-Wyjscie"<<endl;
cin>>z;
switch(z)
{
case 'r':
system("CLS");
cout<<"Ktory element chcesz narysowac"<<endl;
cin>>p;
cout<<"K-KwadratnO-Okrag"<<endl;
cin>>k;
switch(k)
{
case 'o':
if(a[p]==NULL)
{
cout<<"Jakiego koloru ma byc okrag?"<<endl;
cin>>x;
a[p]=new kolo;
a[p]->rysuj(x);
}
else
{
system("CLS");
cout<<"Pole juz zajete"<<endl;
Sleep(1500);
}
break;
case'k':
if(a[p]==NULL)
{
cout<<"Jakiego koloru ma byc kwadrat?"<<endl;
cin>>x;
a[p]=new kwadrat;
a[p]->rysuj(x);
}
else
{
system("CLS");
cout<<"Pole juz zajete"<<endl;
Sleep(1500);
}
break;
}
break;
case 'z':
system("CLS");
cout<<"Ktory element chcesz zmazac"<<endl;
cin>>p;
if(a[p]!=NULL)
{
a[p]->rysuj(BLACK);
delete a[p];
a[p]=NULL;
}
else
{
cout<<"Pole jest juz puste"<<endl;
Sleep(1500);
}
break;
case 'p':
system("CLS");
cout<<"Ktory elemen chcesz przesunac?"<<endl;
cin>>h;
cout<<"e - Wyjscie z trybu przesuwania"<<endl;
if(a[h]!=NULL)
{
do
{
if(kbhit())
{
b=getch();
switch(b)
{
case 'w':
a[h]->przesun(0,-5);
break;
case's':
a[h]->przesun(0,5);
break;
case 'a':
a[h]->przesun(-5,0);
break;
case 'd':
a[h]->przesun(5,0);
break;
}
}
}
while(b!='e');
}
else
{
cout<<"Pole jest puste"<<endl;
}
break;
}
}
while(z!='q');
for(i=0; i<20; i++)
{
if(a[i]!=NULL)
{
delete a[i];
cout<<"Usunieto element numer:t"<<i<<endl;
}
}
//******************************************************************************************************************
//koniec rysowania
//program czeka na naciœniêcie klawisza i ZAMYKA tryb graficzny!
fflush(stdin);
getch(); //tylko zatrzymanie programu, żeby nie zamykał natychmiast okna graficznego
closegraph(); //koniec trybu graficznego
return(0);
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}