#include<conio.h>
#include<windows.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
/* 【自学去】网站收集 http://www.zixue7.com */
struct player
{
char name[10];
int power,speed,wisdom;
int att,def;
int HPmax,HP;
float burst,dodge;
int EXP,EXPmax,LV,spot;
}player1;
struct monster
{
char name[10];
int HP;
int att,def;
int EXP;
float burst,dodge;
}monster1;
main()
{
int i=1,j=0,m=28,n=12;
char c1;
void play1();
int bug1(int sli);
void help();
void HideCursor();
void gotoxy(int x,int y);
void start();
void wait();
void initp1();
void initm1();
void boundary();
void play();
void addspot();
void sure();
void p1order();
void p1die();
S: m=28,n=12;
start();
system("color 2B");
HideCursor();
gotoxy(m,n);
while(1)//{gotoxy(28,12);}
{
c1=getch();
switch(c1)
{
case'w':
case'W':
printf(" ");
n-=3;
if(n<12)n=18;
gotoxy(m,n);
printf("★");
gotoxy(m-1,n);
break;
case's':
case'S':
printf(" ");
n+=3;
if(n>18)n=12;
gotoxy(m,n);
printf("★");
gotoxy(m-1,n);
break;
case'j':
case'J':
if(18==n)
exit(0);
if(15==n)
{
system("cls");
help();
while(getch()){system("cls");goto S;}
}
if(12==n)
{
system("cls");
wait();
initp1();
initm1();
while(1)
{
printf("请输入你的名字:(请少于10个字符)\n");
sprintf(player1.name,"%s","\0");
gets(player1.name);
if(strlen(player1.name)<=9)break;
}
system("cls");
boundary();
while(1){
initm1();
play();
Sleep(1000);
addspot();
sure();
Sleep(1000);
p1order();}
}
break;
}
}
}
void gotoxy(int x,int y) //将光标移动到坐标为(x,y)的地方
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut;
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
csbiInfo.dwCursorPosition.X = x;
csbiInfo.dwCursorPosition.Y = y;
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);
}
void HideCursor()//隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int bug1(int sli)
{
if(sli<0)sli=0;
return sli;
}
void play1()
{
int t=0,i=1;
int LV=1,EXPmax=10,EXP=0,HPmax=30,HP=30,power=0,speed=0,wisdom=0,att=10,def=5,spot=0;
float dodge=5,burst=5;
int AI1_HP,AI1_att,AI1_def,AI1_exp;
int AI2_HP,AI2_att,AI2_def,AI2_exp;
char yc1,yc2;
char enter1,enter2;
char name[10];
srand(time(NULL));
power=rand()%8+7;
speed=rand()%8+7;
wisdom=rand()%8+7;
spot=45-power-speed-wisdom;
NO3:printf("你的名字是?\n");
scanf(" %s",name);
NO2:while(1)
{
printf("请分配你的属性点。(a.力量b.速度c.智力)(最大HP%d,力量%d,速度%d,智力%d,攻击%d,防御%d,闪避率%f,暴击率%f,剩余%d点)\n",HPmax=30+power*2,power,speed,wisdom,att=10+power*1.5,def=5+wisdom*1.5,dodge=5+speed*0.4,burst=5+speed*0.4,spot);
scanf(" %c",&yc1);
switch(yc1)
{
case'a':power+=1,spot-=1;break;
case'b':speed+=1,spot-=1;break;
case'c':wisdom+=1,spot-=1;break;
default:printf("操作错误,请重新输入。\n");
}
if(spot==0)break;
}
printf("昵称:%s\n状态:LV:%d\nEXP:%d/%d\n最大HP:%d\nHP:%d\n攻击力:%d\n防御力:%d\n闪避率:%f\n暴击率:%f\n",name,LV,EXP,EXPmax,HPmax,HP=HPmax,att,def,dodge,burst);
NO1:printf("按y继续\n");
while(1)
{
scanf(" %c",&enter1);
if(enter1!='y')printf("按y继续\n");
if(enter1=='y')break;
}
AI1_HP=rand()%20+30;
AI1_att=rand()%15+25;
AI1_def=50-AI1_att;
AI1_exp=15;
printf("遇到怪物,准备进入战斗。\n怪物信息:\nHP:%d\n攻击:%d\n防御:%d\n",AI1_HP,AI1_att,AI1_def);
while(1)
{
if(HP<=0)break;
printf("a.攻击b.逃跑\n");
scanf(" %c",&yc2);
switch(yc2)
{
case'a':if(rand()%100+1<=5)printf("%s攻击,miss!\n",name);
else if((rand()%100+1)*10<=burst*10)
printf("%s攻击,暴击,怪物损失%dHP,怪物剩余%dHP\n",name,att,bug1(AI1_HP-=att));
else
printf("%s攻击,怪物损失%dHP,怪物剩余%dHP\n",name,bug1(att-AI1_def),bug1(AI1_HP-=bug1(att-AI1_def)));
if(AI1_HP<=0)break;
if((rand()%100+1)*10<=dodge*10)printf("怪物攻击,miss!\n");
else if(rand()%100+1<=5)
printf("怪物攻击,暴击,%s损失%dHP,%s剩余%dHP\n",name,AI1_att,name,bug1(HP-=AI1_att));
else
printf("怪物攻击,%s损失%dHP,%s剩余%dHP\n",name,bug1(AI1_att-def),name,bug1(HP-=bug1(AI1_att-def)));break;
case'b':if(rand()%2==0)goto NO1;
else if((rand()%100+1)*10<=dodge*10)printf("逃跑失败,怪物攻击,miss!\n");
else if(rand()%100+1<=5)
printf("逃跑失败,怪物攻击,暴击,%s损失%dHP,%s剩余%dHP\n",name,AI1_att,name,bug1(HP-=AI1_att));
else
printf("逃跑失败,怪物攻击,%s损失%dHP,%s剩余%dHP\n",name,bug1(AI1_att-def),name,bug1(HP-=bug1(AI1_att-def)));break;
default:printf("操作错误,请重新输入。\n");
}
if(AI1_HP<=0)break;
}
if(HP<=0)goto END;
EXP+=AI1_exp;
if(EXP>=EXPmax)LV+=1,spot+=5,EXP-=EXPmax,EXPmax+=20*(LV-1),printf("打败怪物,%s升级了。\n",name);
else printf("打败怪物,输入y继续遇怪,输入q查看属性。\n");
if(spot!=0)goto NO2;
while(1)
{
scanf(" %c",&enter2);
if(enter2!='y')printf("按y继续\n");
if(enter2=='q')printf("昵称:%s\n状态:最大HP:%d\nHP:%d\n攻击力:%d\n防御力:%d\n闪避率:%f\n暴击率:%f\n",name,HPmax,HP=HPmax,att,def,dodge,burst);
if(enter2=='y')goto NO1;
}
END:printf("角色死亡,游戏结束。\n");
}
void wait()
{
int i=0,m=4,n=3;
void HideCursor();
void gotoxy(int x,int y);
printf("╔══════════════════════════════════════╗");
printf("║ ║");
printf("║ ╱▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏▔◥║");
printf("║ ▏ ▏%% ║");
printf("║ ╲▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏▁◢║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ┐╭─┼─┐ ┌┬┌┐┐┐ ┌─╮┬─╮ ║");
printf("║ ┐ ─┼─┐ ┌┼┌┴┴┐ │└╮└└╮ ║");
printf("║ │┌─┴── ╭┤│ │ ──┼─ ║");
printf("║ │ ├──┤ │├├──┤ ┌──┴─┐ ║");
printf("║ │ ├──┤ ││├──┤ ┌─┬─┼┐ ║");
printf("║ └╰┘ ┘ └└└ ╯ └──╯ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║