注意:本作未降低难度,建议小白直接copy源码玩。
首先,为照顾开了快速编辑模式的用户,本作为纯键盘输入。
讲解
头文件(别看很多,其实有些是重复的,有些是不必要的):
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
定义变量:
int blue=100;这是蓝量
int HP=1000;这是血量
int hurt=100;这是伤害
int x=10,y=1; 这是玩家坐标
int Boss_HP=2000;BOSS血量
int Boss_hurt=200;BOSS伤害
int Boss_x=10,Boss_y=20;BOSS坐标
int monsters_HP=200;小怪血量
int monsters_hurt=20;小怪伤害
int monsters_x,monsters_y;小怪坐标
int hj=0;护甲
int fj=0;反甲
int money=0;金钱
取随机数
int x_what(int x) {//取随机数
srand((unsigned)time(NULL));
return( rand() % x);
}
原理:用srand()和rand()取随机数
商城
int sc(){ //商城界面 //判断购买物品 开始界面(无非就是输出): int open(){ 游戏函数(输出界面和进行操作) int out(){//输出游戏界面 //按键操作 main()函数: int main(){ //后面的是判断死亡、受伤、胜利的。
system("cls");
char cz;
cout<<"金钱"<
while(!kbhit()){
}
cz=getch();//按键选择购买物品
if(cz=='1'&&money>=200){
money-=200;
fj+=100;
}
if(cz=='2'&&money>=100){
money-=100;
hj+=100;
}
if(cz=='3'&&money>=100){
money-=100;
hurt+=100;
}
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED| FOREGROUND_GREEN);
cout<<" 传奇(DEVC++阳光版)";
cout<<"by:黑客小C"<
while(!kbhit()) {
}
system("cls");
monsters_x=x_what(18);
monsters_x++;
monsters_y=x+1;
}
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
cout<<"血量:"<
for(int j=0;j<=21;j++){
if(i==0||i==21){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED| FOREGROUND_GREEN);
cout<<"+";
}
else if(j==0||j==21){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED| FOREGROUND_GREEN);
cout<<"+";
}
else if(i==x&&j==y){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout<<"8";
}
else if(i==monsters_x&&j==monsters_y){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"o";
}
else if(i==Boss_x&&j==Boss_y){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"M";
}
else{
cout<<" ";
}
}
cout<
}
int play(){
char cz;
if(kbhit())
{
cz=getch();
if(cz=='w'){
x--;
}
if(cz=='s'){
x++;
}
if(cz=='a'){
y--;
}
if(cz=='d'){
y++;
}
if(cz=='f'){
if(x==monsters_x&&y==monsters_y-1){
monsters_HP-=hurt;
}
if(x==Boss_x&&y==Boss_y-1){
Boss_HP-=hurt;
}
}
if(cz=='e'){
if(blue>=100){
blue-=100;
HP+=200;
if(x==monsters_x&&y==monsters_y-1){
monsters_HP-=(hurt*2);
}
if(x==Boss_x&&y==Boss_y-1){
Boss_HP-=(hurt*2);
}
}
}
if(cz=='q'){
sc();
}
}
}
open();
while(true){
out();
play();
if(Boss_HP<=0){
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED| FOREGROUND_GREEN);
cout<<"游戏胜利";
Sleep(2000);
return 0;
}
if(HP<=0){
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"你死了";
Sleep(2000);
return 0;
}
if(monsters_HP<=0){
monsters_HP=200;
money+=100;
hurt+=100;
monsters_x=x_what(18);
monsters_x++;
monsters_y=x+1;
}
if(x==monsters_x&&y==monsters_y-1){
HP-=monsters_hurt;
HP+=hj;
monsters_HP-=fj;
}
if(x==Boss_x&&y==Boss_y-1){
HP-=Boss_hurt;
HP+=hj;
Boss_HP-=fj;
}
blue+=10;
Sleep(100);
}
return 0;
}源码
#include效果
