c++⼩游戏代码(5个)免费
DEV-C++的编程内容⼗分受限,想编游戏更是天⽅夜谭, 但总有⼤神,我为⼤家准备了5个dev-c++就能编的程序。⽃破苍穹
#include<stdio.h>
#include<ctime>
#include<time.h> //suiji
#include<windows.h> //SLEEP函数
struct Player //玩家结构体,并初始化player
{
char name[21];
int attack;
int defense;
int health;
long int max_health;
int level;
int exp;
int range_exp;
long int max_exp;
} player= {"勇者",50,40,100,100,1,0,0,100};
struct Enemy //怪的结构体,并初始化各种怪
{
char name[20];
char wupin[12];
int attack;
int defense;
int health;
int money;
long int exp;
int wupin_sign;
int wupinpro;
int double_attack;
int miss;
} strongman= {"森林巨⼈","黄⾦圣⾐",40,50,350,200,100,1,2,1,0},
witch= {"森林⼥巫","银甲",25,15,100,50,50,2,2,1,1},
xiyi= {"森林蜥蜴","铁甲",18,10,50,30,35,3,3,2,2},
big_strongman= {"森林巨⼈王","巨⼈晶⽯",40*5,50*5,200*5,200*5,100*5,4,4,2,0},
lion= {"草原雄狮","绝世好剑",60,30,280,200,100,5,2,1,0},
horse= {"草原野马","碧⾎剑",28,12,90,50,50,6,2,1,1},
bee= {"草原黄蜂","长剑",17,11,60,30,35,7,3,2,2},
shitu= {"使徒","\0",60*8,30*8,280*8,200*8,100*8,9,1,1,0},
guai= {"\0","\0",0,0,0,0,0,0,0,0,0};
struct Place
{
int bar,hotel,forest1,forest2,forest3,grass1,grass2,grass3;
} place= {1,2,3,4,5,6,7,8};
int max_exp=0;
int choose_number=0,s=0,strongman_arm=0,battle=0,money=500,place_sign=9;
int cao=3,jijiubao=2,baiyao=2,superbaiyao=1,boom=3,dubiao=2,atom_boom=1;
int fang=0,fang1=10,fang1n=0,fang2=20,fang2n=0,fang3=40,fang3n=0,fang4=100,fang4n=0;
int gong=0,gong1=8,gong1n=0,gong2=15,gong2n=0,gong3=25,gong3n=0,gong4=60,gong4n=0;
int jingyancao=0,jingyanbao=0,jingyanshi=0;
char gongname[20]="⽆",fangname[20]="⽆";
char proof;
void AddWupin(int);
int AttackResult();
void BattleAct();
void ChooseWupin();
void DisplayState();
void OrdinaryAct();
int SuiJi();
int SuiJi100();简单好玩的编程代码复制
void WhetherLevelUp();
void SlowDisplay(char *);
int main()
{
int i=0,j=0,k=0;
char player_name[21];
Sleep(1000);
printf("--------------------------欢迎来到 [苍穹世界] 2.2 测试版-----------------------\n\n\n");
//如果想使⽤外挂,名字请输⼊:“圣战⽃⼠ ”。
Sleep(1000);
printf("这⾥是苍穹世界! 雅莉萨斯国的罗茜公主被陌⽣⼈了!\n\n\n 伟⼤的勇者啊~拿起你们的武器,营救公主!\n\n\n输⼊你的名字: (20个字符)\n\n\n");
scanf("%s",player_name);
strncpy(player.name,player_name,20);
if(strcmp(player.name,"圣战⽃⼠")==0)
{
printf("\n\n\n封印多年的圣剑⾎统啊!你终于觉醒了!\n\n\n圣战⽃⼠,你成为了天选之⼈,请你救出公主吧!\n\n\n");
player.attack=999;
player.defense=999;
player.health=9999;
player.max_health=9999;
}
getchar();
OrdinaryAct();
return 0;
}
int SuiJi()
{
srand((unsigned)time(NULL));
return rand()%10;
}
int SuiJi100()
{
srand((unsigned)time(NULL));
return rand()%100;
}
void ChooseWupin() //选择物品 并使⽤
printf("物品: 1,⽌⾎草%d个 2,急救包%d个 3,云南⽩药%d个 4,超级云南⽩药%d个 5,⼿雷%d个 6,毒标%d个 7,⼿抛式原⼦弹%d个 8,经验草%d个 9,经验包%d个 10,经验⽯%d个 11,巨⼈晶⽯%d个 0,返回
\n\n\n",cao,jijiubao,baiyao,superbaiyao,boom,dubiao,atom_boom,jingyancao,jingyanbao,jingyanshi,strongman_arm);
switch(scanf("%d",&choose_number),choose_number)
{
case 1:
if(cao>0)
{
printf("使⽤⽌⾎草,HP增加60\n\n\n");
cao--;
if(player.health+60>player.max_health)player.health=player.max_health;
else player.health+=60;
}
else printf("没有⽌⾎草了\n\n\n");
break;
case 2:
if(jijiubao>0)
{
printf("使⽤急救包,HP增加80\n\n\n");
jijiubao--;
if(player.health+80>player.max_health)player.health=player.max_health;
else player.health+=80;
}
else printf("没有急救包了\n\n\n");
break;
case 3:
if(baiyao>0)
{
printf("使⽤云南⽩药,HP增加120\nz\n\n");
baiyao--;
if(player.health+120>player.max_health)player.health=player.max_health;
else player.health+=120;
}
else printf("没有云南⽩药了\n\n\n");
break;
case 4:
if(superbaiyao>0)
{
printf("使⽤超级云南⽩药,HP增加200\n\n\n");
superbaiyao--;
if(player.health+200>player.max_health)player.health=player.max_health;
else player.health+=200;
}
else printf("没有超级云南⽩药了\n\n\n");
break;
case 5:
if(battle) //在战⽃中(battle=1),否则(battle=0)不能使⽤攻击性物品
{
if(boom>0)
{
printf("使⽤⼿雷,敌⼈HP减少100\n\n\n");
boom--;
guai.health-=100;
AttackResult();
else printf("⾮战⽃状态,不能使⽤⼿雷!\n\n\n");
break;
case 6:
if(battle) //在战⽃中(battle=1),否则(battle=0)不能使⽤攻击性物品{
if(dubiao>0)
{
printf("使⽤毒标,敌⼈HP减少200\n\n\n");
dubiao--;
guai.health-=200;
AttackResult();
}
}
else printf("⾮战⽃状态,不能使⽤毒标!\n\n\n");
break;
case 7:
if(battle) //在战⽃中(battle=1),否则(battle=0)不能使⽤攻击性物品{
if(atom_boom>0)
{
printf("使⽤⼿抛式原⼦弹,敌⼈HP减少666666666\n\n\n");
atom_boom--;
guai.health-=666666666;
AttackResult();
}
}
else printf("⾮战⽃状态,不能使⽤⼿抛式原⼦弹!\n\n\n");
break;
case 8:
if(jingyancao>0 && player.level<1000)
{
printf("使⽤经验草,等级增加10级\n\n\n");
jingyancao--;
player.level+=10;
printf("等级:%d\n",player.level);
}
else if(jingyancao<1)
{
printf("没有经验草了\n\n\n");
}
else printf("等级超过45级,修为太⾼,⽆法使⽤。\n\n\n"); break;
case 9:
if(jingyanbao>0 && player.level<1000)
{
if(player.level>44&&player.level<1000)
{
int sheng;
sheng=45-player.level;
player.level+=sheng;
printf("使⽤经验包,等级增加%d级",sheng);
printf("等级:%d\n",player.level);
{
printf("使⽤经验包,等级增加2级\n\n\n");
jingyanbao--;
player.level+=2;
printf("等级:%d\n",player.level);
}
}
else if(jingyanbao<1)
{
printf("没有经验包了");
}
else printf("等级超过45级,修为太⾼,⽆法使⽤。\n\n\n"); break;
case 10:
if(jingyanshi>0 && player.level<1000)
{
if(player.level>42&&player.level<1000)
{
int sheng;
sheng=45-player.level;
player.level+=sheng;
printf("使⽤经验⽯,等级增加%d级\n",sheng);
printf("等级:%d\n",player.level);
}
else
{
printf("使⽤经验⽯,等级增加10级\n");
jingyanshi--;
player.level+=10;
}
}
else if(jingyanshi<1)
{
printf("没有经验⽯了\n\n\n");
}
else printf("等级超过45级,修为太⾼,⽆法使⽤。\n\n\n"); break;
case 11:
if(strongman_arm>0 && player.level<10000)
{
if(player.level>29&&player.level<10000)
{
int sheng;
sheng=45-player.level;
player.level+=sheng;
printf("使⽤巨⼈晶⽯,等级增加%d级",sheng);
printf("等级:%d\n",player.level);
}
else
{
printf("使⽤巨⼈晶⽯,等级增加16级\n\n\n");
strongman_arm--;
printf("等级:%d\n",player.level);
}
}
else if(strongman_arm<1)
{
printf("没有巨⼈晶⽯了。\n\n\n");
}
else printf("等级超过45级,修为太⾼,⽆法使⽤。\n\n\n");
break;
case 0:
break;
default:
printf("ChooseWupin error!\n\n\n");
}
}
int AttackResult() //攻击结果:判断是否获胜 是否获得物品 和 是否升级{
if(guai.health<=0)
{
battle=0;
printf("战⽃胜利!获得⾦币%d,经验%d\n\n\n",,p); p+=p;
player.range_exp+=p;
money+=;
s=SuiJi();
if(s<guai.wupinpro)
{
printf("从敌⼈⼫骸中发现");
printf("%s\n\n\n",guai.wupin);
AddWupin(guai.wupin_sign);
}
WhetherLevelUp();
if(strcmp(guai.name,"使徒")==0)
{
printf("战⽃胜利,救出公主");
getchar();
getchar();
exit(0);
}
return 1; //攻击有结果了返回1,否则返回0,⽤于判断是否继续做战⽃⾏为}
else
{
int s=SuiJi();
if((guai.attack+s-player.defense/3)<0)
{
player.health-=1;
printf("%s反击,你的HP减少了 1\n\n",guai.name);
}
else
{
player.health-=guai.attack+s-player.defense/3;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论