|

楼主 |
发表于 2020-4-20 19:50:31
|
显示全部楼层
- #include <cstdlib>
- #include <iostream>
- #include <graphics.h>
- using namespace std;
- void usage()
- {
- int x = textheight("1")+100;
- int y = textwidth ("1")+20;
- //void settextstyle(int font, int direction, int charsize);
-
- settextstyle(0,0,0);
- setcolor(LIGHTGREEN);
- outtextxy(x,y ,"吃到红块 按左键打字弹");
- outtextxy(x,y*2,"吃到黄块 减短拍子");
- outtextxy(x,y*3,"吃到蓝块 加长拍子");
- outtextxy(x,y*4,"吃到绿块 拍子粘球,右键再次发球");
- outtextxy(x,y*5,"吃到蓝块 球数翻倍 (初始化不发射有bug)");
- outtextxy(x,y*7,"规则 球不能掉到屏幕下方去 但这在测试");
- outtextxy(x,y*8,"依靠鼠标在游戏窗口中左右来控制拍子来回移动 右键发球");
- outtextxy(x,y*9,"--- 按任意键开始 ---2020.04.20");
- setcolor(WHITE);
- getch();
- }
- class o
- {
- int *p,size,left,top,l,w,c;
- public:
- o():p(NULL),size(0),left(0),top(0),l(0),w(0),c(0){};
- ~o(){ delete [] p; };
-
- o(char,char);
- o(char,char,char);
-
- o(const o&);
- void operator =(const o&);
-
- bool init(int,int);
- };
- class e
- {
- o *p;
- int total,*statu;
- char *name;
- public:
- e():p(NULL),total(0),name("none"),statu(0){};
- ~e(){ delete [] p,statu; };
-
- e(int,o&o,char*);
-
- };
- e:: e(int sum,o&oi,char*n):total(sum),name(n)
- {
- p = new o [ sum ];
-
- statu=new int [sum];
-
- for(int i=0;i<sum;i++)
- {
- p[i] = oi;
- statu[i]=0;
- }
-
-
- outtextxy(0,10,"测试摆出");
-
- for(int i=0;i<sum;i++)
- {
- if(p[i].init(i*12,100))
- {
- cout<<name<<" "<<i<<" 已初始化完成 statu="<<statu[i]<<endl;
- }
- }
-
- cout<<name<<" "<<sum<<" 已初始化完成"<<endl;
- }
- int main(int argc, char *argv[])
- {
- initwindow(800,600,"OO图形化教程",600,100);
-
- o ball(5,WHITE);
- // o b(ball);
- // o c;
- // c=ball;
- //
- // o block(50,22,2);
- // o bl(block);
- // o blo;
- // blo = block;
- //
- // ball.init(200,100);
- // b.init(200,120);
- // c.init(200,140);
- //
- // block.init(300,100);
- // bl.init(300,200);
- // blo.init(300,300);
-
- e a(5,ball,"balls");
-
-
-
-
- getch();
- //system("PAUSE");
- return EXIT_SUCCESS;
- }
- /*
- */
- o:: o(char r,char C):left(0),top(0),l(r+r),w(r+r),c(C)
- {
- setcolor(c);
- circle(r,r,r);
- setfillstyle(1,c);
- floodfill(r,r,c);
- size=imagesize(left,top,left+l,top+w);
- p = new int [size];
- getimage(left,top,l,w,p);
- cleardevice();
- setcolor(WHITE);
- }
- o:: o(char L,char W,char c):left(0),top(0),l(L),w(W),c(c)
- {
- setcolor(c);
- rectangle(left,top,l,w);
- setfillstyle(1,c);
- floodfill(1,1,c);
- size=imagesize(left,top,left+l,top+w);
- p = new int [size];
- getimage(left,top,l,w,p);
- getch();
- cleardevice();
- setcolor(WHITE);
- }
- o:: o(const o&o):size(o.size),left(o.left),top(o.top),l(o.l),w(o.w),c(o.c)
- {
- delete [] p;
- p = new int [size];
-
- memcpy(p,o.p,size);
-
- cout<<"复制 内存大小: "<<size<<"\n原地址: "<<o.p
- <<"\n新地址: "<<p<<endl<<endl;
- }
- void o:: operator =(const o&o)
- {
- delete [] p;
- size = o.size;
- left = o.left;
- top = o.top;
- l = o.l;
- w = o.w;
- c = o.c;
-
- p = new int [size];
-
- memcpy(p,o.p,size);
-
- cout<<"赋值 内存大小: "<<size<<"\n原地址: "<<o.p
- <<"\n新地址: "<<p<<endl<<endl;
- }
- bool o:: init(int x, int y)
- {
- left = x;
- top = y;
- putimage(left,top,p,1);
- cout<< p<<endl;
- return true;
- }
- /*
- */
复制代码 |
|