?? peopleclass.h
字號:
#include <time.h>
class people //抽象基類
{
protected:
int life;
int level;
int attack;
int recovery;
int experience;
int x;
int y;
int speed;
int direction;
int count_picture;
int count;
int width;
int height;
public:
LPDIRECTDRAWSURFACE7 lpdds1[4][3];
people(int,int,int,int,int,int,int,int);
// people(){}
void position();
int get_attack();
int get_x();
int get_y();
void set_xy(int tx ,int ty);
int set_direction(int);
int set_count_picture(int);
void show();
virtual void attack_fuction(people&)=0;
virtual void hurt(int)=0;
int get_life();
int get_level();
void show_fight_effect();
void free_walk(int **a);
void set_WH(int w,int h);
int get_W(){return width;}
int get_H(){return height;}
void set_att(int a){attack=a;}
void set_rec(int a){recovery=a;}
int get_rec(){return recovery;}
};
class enchanter:public people
{
protected:
int magic;
public:
enchanter(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed,
int tmagic);
virtual void attack_fuction(people&);
virtual void hurt(int);
};
class warrior:public people
{
public:
// warrior(): people()
// {}
warrior(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed);
virtual void attack_fuction(people&);
virtual void hurt(int);
};
class houyi:public warrior
{
private:
int max_life;
public:
houyi(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed);
LPDIRECTDRAWSURFACE7 lpdds[4][5];
void DrawPeople(int **);
virtual void attack_fuction(people&);
virtual void hurt(int);
void show();
void set_experience(int b);
void levelup();
void show_fight_effect();
void position();
void setlife(int lf){life+=lf;if(life>max_life)life=max_life;}
int get_max_life(){return max_life;}
void set_max_life(int a){max_life=a;}
int get_exp(){return experience;}
protected:
};
void people::position()
{
DDraw_Draw_Surface(lpdds1[direction][count_picture],x,y,get_W(),get_H(),lpddsback,1);
}
void people::set_WH(int w, int h)
{
width=w;
height=h;
}
void people::free_walk(int **a)
{
int x1=x,y1=y;
count++;
srand(time(NULL));
if(count%10==0)
{
direction=(rand()+life)%4;
}
if(direction==0)
{
y1-=speed;
count_picture++;
if(count_picture>2)count_picture=0;
}
if(direction==1)
{
x1+=speed;
count_picture++;
if(count_picture>2)count_picture=0;
}
if(direction==2)
{
y1+=speed;
count_picture++;
if(count_picture>2)count_picture=0;
}
if(direction==3)
{
x1-=speed;
count_picture++;
if(count_picture>2)count_picture=0;
}
if(bump(x1,y1,a))
{
x=x1;
y=y1;
}
else
direction=rand()%4;
DDraw_Draw_Surface((*this).lpdds1[direction][count_picture],get_x(),get_y(), get_W(),get_H(), lpddsback,1);
}
people::people(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed)
{
life=tlife;
level=tlevel;
attack=tattack;
recovery=trecovery;
experience=texperience;
x=tx;
y=ty;
speed=tspeed;
}
houyi::houyi(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed):warrior(tlife,
tlevel,tattack,trecovery,texperience,tx,ty,tspeed)
{
max_life=20;
}
void people::show_fight_effect()
{
}
inline int people::get_attack()
{
return attack;
}
inline int people::get_level()
{
return level;
}
inline int people::get_life()
{
return life;
}
void people::show()
{
// 732 516 life
// 557 attack
// 586 防
//615 level
// DDraw_Text_GDI("haha",732,516,150,lpddsback);
char **a;
a=(char**)malloc(4*sizeof(char*));
for(int i=0;i<4;i++)
a[i]=(char*)malloc(10);
a[0]=_itoa(life,a[0],10);
a[1]=_itoa(attack,a[1],10);
a[2]=_itoa(recovery,a[2],10);
a[3]=_itoa(level,a[3],10);
Draw_Text_GDI(a[0],736,516,150,lpddsback);
Draw_Text_GDI(a[1],736,557,150,lpddsback);
Draw_Text_GDI(a[2],736,587,150,lpddsback);
Draw_Text_GDI(a[3],736,615,150,lpddsback);
for(i=0;i<4;i++)
free(a[i]);
free(a);
}
inline void people::set_xy(int tx,int ty)
{
x=tx;
y=ty;
}
inline int people::get_x()
{
return x;
}
inline int people::get_y()
{
return y;
}
void houyi::DrawPeople(int **a)
{
int x1=x,y1=y;
if(KEYDOWN(VK_LEFT))
{
x1-=speed;
direction=1;
count_picture++;
if(count_picture>4)count_picture=1;
}
if(KEYDOWN(VK_RIGHT))
{
x1+=speed;
direction=3;
count_picture++;
if(count_picture>4)count_picture=1;
}
if(KEYDOWN(VK_UP))
{
y1-=speed;
direction=2;
count_picture++;
if(count_picture>4)count_picture=1;
}
if(KEYDOWN(VK_DOWN))
{
y1+=speed;
direction=0;
count_picture++;
if(count_picture>4)count_picture=1;
}
if(bump(x1,y1,a))
{
x=x1;
y=y1;
}
DDraw_Draw_Surface((*this).lpdds[direction][count_picture],get_x(),get_y(), 120,120, lpddsback,1);
}
enchanter::enchanter(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed,
int tmagic)
:people(tlife,tlevel,tattack, trecovery,
texperience, tx, ty, tspeed)
{
magic=tmagic;
}
void enchanter::attack_fuction(people& a)
{
a.hurt(a.get_attack());
experience+=level*attack;
}
void enchanter::hurt(int b)
{
srand(time(NULL));
life-=b*(rand()%41+80)/100-recovery;
if(life<=0)
life=0;
}
warrior::warrior(int tlife,int tlevel,int tattack,int trecovery,
int texperience,int tx,int ty,int tspeed)
:people(tlife,tlevel,tattack, trecovery,
texperience, tx, ty, tspeed)
{
}
void warrior::attack_fuction(people& a)
{
PlaySound(MAKEINTRESOURCE(IDR_WAVE1),hinstance_app,SND_ASYNC|SND_RESOURCE);
Sleep(500);
PlaySound(MAKEINTRESOURCE(IDR_WAVE5),hinstance_app,SND_ASYNC|SND_RESOURCE);
a.hurt(this->get_attack());
a.show();
experience+=level*attack;
}
void warrior::hurt(int b)
{
srand(time(NULL));
int k=b*(rand()%41+80)/100-recovery;
if(k<=0)
k=1;
life-=k;
if(life<=0)
life=0;
}
void houyi::attack_fuction(people& a)
{
a.hurt(this->attack);
a.show();
DDraw_Draw_Surface(lpddsbackground[0],0,0,1024,768,lpddsback,0);
// DDraw_Draw_Surface(background,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,lpddsback,0);
PlaySound(MAKEINTRESOURCE(IDR_WAVE1),hinstance_app,SND_ASYNC|SND_RESOURCE);
Sleep(500);
PlaySound(MAKEINTRESOURCE(IDR_WAVE4),hinstance_app,SND_ASYNC|SND_RESOURCE);
Sleep(500);
// experience+=a.level*5;
// levelup();
show_fight_effect();
}
void houyi::hurt(int b)
{
srand(time(NULL));
int k= b*(rand()%41+80)/100-recovery;;
if( k <=0)
k=1;
life-=k;
if(life<=0)
life=0;
}
void houyi::show()
{
char **a;
a=(char**)malloc(4*sizeof(char*));
for(int i=0;i<4;i++)
a[i]=(char*)malloc(10);
a[0]=_itoa(life,a[0],10);
a[1]=_itoa(attack,a[1],10);
a[2]=_itoa(recovery,a[2],10);
a[3]=_itoa(level,a[3],10);
Draw_Text_GDI(a[0],323,516,150,lpddsback);
Draw_Text_GDI(a[1],323,557,150,lpddsback);
Draw_Text_GDI(a[2],323,587,150,lpddsback);
Draw_Text_GDI(a[3],323,615,150,lpddsback);
for(i=0;i<4;i++)
free(a[i]);
free(a);
}
void houyi::set_experience(int b)
{
experience+=(30+b*20);
}
void houyi::levelup()
{
int a=level*10+50;
if(experience>=a)
{
level+=(int)experience/a;
experience=experience%a;
attack+=3;
recovery+=2;
max_life+=level*10;
}
}
void houyi::show_fight_effect()
{
/* int x=696,y=381,k=0;
while(x<815)
{
// k++;
// if(k%10==0)
x+=1;
DDraw_Draw_Surface(fight_effect[0],x,y,100,100,lpddsback,1);
DDraw_Draw_Surface(lpddsbackground[0],0,0,1024,768,lpddsback,0);
Sleep(10);
}
*/
}
void houyi::position()
{
DDraw_Draw_Surface(lpdds[direction][count_picture],x,y,120,120,lpddsback,1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -