该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
#include
/*
设定:
玩家:
攻击力,生命值,技能效果,CD;
敌人:
攻击力,生命值,CD;
//跳跃怎么做?如果我想要子弹打在敌人身上才算攻击成功,怎么做?结构体:玩家,敌人。
子函数:画布初始化。
玩家初始化。
敌人初始化。//需要么?
绘制玩家。
绘制敌人。
绘制玩家技能。
绘制敌人技能。
绘制玩家跳跃动画(5帧)
玩家行为函数。
敌人行为函数。
//尝试敌人攻击频率随机。*/
void fun(int ch); //用于控制英雄的行为模式
void fun2(); //用于控制敌人的行为模式
void hero_init(); //初始化英雄 √
int random(); //产生随机数 √
void paper_print(); //画纸打印到命令行界面上 √
void paint_dragon(int x,int y); //把大龙画到画纸上 √
void paint_hero(int x,int y); //把英雄画到画纸上 √
void paint_dragon_health(); //把大龙生命条画到画纸上 //能不能做到攻击敌人敌人生命条递减? √(理论上递减)
void paint_hero_skill_e(); //绘制技能动画 √
void paint_hero_skill_w(); //跳跃动画
void paint_dragon_skill(); //把大龙技能画到画纸上 √
void paper_init(); //清空画纸 √
char paper[25][110];int mode1=0;
int mode2=0;
int protect=0;
struct hero
{
char name[100];
int health;
int attack;
int delay;
};struct dragon
{
char name[100];
int health;
int attack;
int delay;
};struct hero player;struct dragon enemy;void dragon_init()
{
// enemy.name = "dragon";
enemy.health = 50;
enemy.attack = 20;
enemy.delay = 10;
}int main(int argc, char *argv[]) //主函数
{
int ch,i,j;
srand((unsigned int)time(NULL));
hero_init();
dragon_init();
paper_init();
for(;;)
{
if(enemy.health<0||player.health<0)
// {break;}
// system("cls");
if(_kbhit)
{
ch = _getch();
}
paper_init();
paint_dragon_health();
fun(ch);
fun2();
ch = 0;
paint_dragon(106,23);
paper_print();
printf("\n");
printf("玩家: 姓名:%s 生命值:%d 攻击力:%d 技能CD:%d s\n",player.name,player.health,player.attack,player.delay);
printf("%d",ch); sleep(50);
printf("%d",1);
}
system("cls");
if(player.health < 0)
{
printf("DEAD\n");
}
if(enemy.health < 0)
{
printf("WIN\n");
}
return 0;
}
void paper_init() //画纸初始化
{
int i,j;
for(i=0;i<25;i++){
for(j=0;j<110;j++){
paper[i][j] = ' ';
}
}
}void paper_print() //绘制函数
{
int i,j;
for(i=0;i<25;i++)
{
for(j=0;j<110;j++){printf("%c",paper[i][j]);}
printf("\n");
}
}void paint_dragon_skill() //绘制敌人技能动画
{
int i,j;
for(i = 99;i >5; i--){
for(j=23;j>22;j--){
paper[j][i] = '-';
}
}
}void paint_hero_skill_e(int x) //绘制玩家技能动画
{
int i,j;
for(i = 24;i > 22; i--){
for(j=x;j
paper[i][j] = '|';
}
}
}void paint_hero_skill_w() //绘制玩家跳跃动画
{
switch(player.delay)
{
case 3:
paint_hero(2,22);
protect=1;
break;
case 2:
paint_hero(2,21);
protect=1;
break;
case 1:
paint_hero(2,22);
protect=1;
break;
case 0:
paint_hero(2,23);
protect=0;
break;
}
}
void paint_hero(int x,int y) //绘制玩家
{
paper[y-1][x] = '@';
paper[y][x-1] = '/';
paper[y][x] = '|';
paper[y][x+1] = '-';
paper[y+1][x-1] = '/';
paper[y+1][x] = ' ';
paper[y+1][x+1] = '|';
}void paint_dragon(int x,int y) //绘制敌人
{
switch(mode2)
{
case 0://正常
paper[y][x] = ')';
paper[y][x-1] = ' ';
paper[y][x-2] = ' ';
paper[y][x-3] = '0';
paper[y][x-4] = 'w';
paper[y][x-5] = '0';
paper[y][x-6] = '(';
break;
case 1://被击中
paper[y][x] = ')';
paper[y][x-1] = ' ';
paper[y][x-2] = ' ';
paper[y][x-3] = '
paper[y][x-4] = 'a';
paper[y][x-5] = '>';
paper[y][x-6] = '(';
break;
case 2://攻击
paper[y][x] = ')';
paper[y][x-1] = ' ';
paper[y][x-2] = ' ';
paper[y][x-3] = '=';
paper[y][x-4] = 'W';
paper[y][x-5] = '=';
paper[y][x-6] = '(';
break;
case 3:
paper[y][x] = ')';
paper[y][x-1] = ' ';
paper[y][x-2] = ' ';
paper[y][x-3] = '>';
paper[y][x-4] = 'w';
paper[y][x-5] = '
paper[y][x-6] = '(';
break;
}
}void paint_dragon_health() //绘制大龙血条
{
int i,j;
for(i=110;i>(110-enemy.health);i--)
for(j=2;j<3;j++)
{
paper[j][i] = '*';
}
}int random()
{
return rand();
}void hero_init() //英雄初始化
{
int ch;
int time = 0;
printf("请输入您的名字:\n");
scanf("%s",&player.name);
player.delay = 0;
do
{
if(time!=0)
if(_kbhit)
{
ch = _getch();
if(ch==13) {break;}
else if(ch!=32) {continue;}
}
else {continue;}
system("cls");
printf("自动生成数据如下:\n");
printf("玩家姓名:%s\n生命值:%d\n攻击力:%d\n攻击CD:%d s\n",player.name,player.health = random()%20+90,player.attack = random()%5+15,1);
printf("按 回车 键继续,按 空格 键重新生成数据。");
time = 1;
}while(1);
}
void fun(int ch) //玩家行动函数
{
if(player.delay == 0)
{
switch(ch)
{
case 119:
player.delay = 3;
mode1 = 1;
break;
case 101:
player.delay = 5;
mode1 = 2;
if(paper[24][99] == '|')
{
mode2 = 1;
paint_dragon(106,23);
enemy.health = enemy.health - player.attack;
}
break;
}
}
switch(mode1)
{
case 0:
paint_hero(2,23);
break;
case 1:
paint_hero_skill_w();
break;
case 2:
paint_hero(2,23);
paint_hero_skill_e(3 + 20*(5 - player.delay));
break;
}
if(player.delay > 0)
{
player.delay--;
}
else {player.delay = 0;}
}void fun2() //敌人行动函数
{
if(enemy.delay == 0)
{
mode2 = 2;
paint_dragon(106,23);
paint_dragon_skill();
if(protect == 0) {player.health = player.health - enemy.attack;}
}
else if(enemy.delay == 3)
{
mode2 = 3;
paint_dragon(106,23);
}
else {paint_dragon(106,23);}
if(enemy.delay > 0)
{
enemy.delay--;
}
else {enemy.delay = 0;}
}