1.02更新:增加弓箭、死斗模式。(提前声明:本版本超吃配置,请确保使用时电脑不烫)
代码
#include<algorithm>
#include<fstream>
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include <time.h>
#include <stdlib.h>
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //必要的,要背下来
using namespace std;
//KEY_DOWN(MOUSE_EVENT)检测右键
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);颜色
//█
int vs_map[3][10];
bool bed=true,dbed=true;
int fx=1;
int hurt=1;
int HP=10;
int dHP=10;
int x,y;
int dx,dy;
int bx,by;
int dbx,dby;
int go;
int money=0;
int x_what(int x) {//取随机数srand((unsigned)time(NULL));return( rand() % x);
}
int j_out() {if(hurt<10) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"|";} else {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);cout<<"|";}
}
int play() {char c;if(HP<=0&&bed==true) {HP=10;x=1;y=0;}if(kbhit()) {c=getch();if(c=='w'&&x>0) {x--;}if(c=='a'&&y>0) {y--;fx=-1;}if(c=='s'&&x<2) {x++;}if(c=='d'&&y<9) {fx=1;y++;}if(c=='e'&&money>=20&&x==1) {hurt=10;money-=20;}if(c=='f'&&money>=10){money-=10;dHP=0;}}if(KEY_DOWN(MOUSE_EVENT)) {if(x==dx&&y==dy) {dHP-=hurt;}if(x==dbx&&y==dby&&dbed==true) {dbed=false;money+=20;}}
}
int AI() {if(go%3!=0) {return 0;}if(dHP<=0&&dbed==true) {dx=1;dy=9;dHP=10;money+=10;return 0;}if(vs_map[dx][dy-1]==1) {if(x_what(1)==0) {dx++;} else {dx--;}} else if(dx==x&&dy==y) {HP--;} else if(dx==bx&&dy==by) {bed=false;} else if(dy!=by) {dy--;} else {if(dx<bx) {dx++;} else {dx--;}}
}
int out() {system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);for(int i=0; i<HP; i++) {cout<<"V";}SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);if(go<100){cout<<"战斗模式"<<endl; }else{cout<<"死斗模式"<<endl; bed=false;dbed=false;}cout<<"经验:"<<money<<endl;for(int i=0; i<3; i++) {for(int j=0; j<10; j++) {if(vs_map[i][j]==1) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE| FOREGROUND_GREEN);cout<<"█";} else if(i==x&&j==y) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);cout<<"█";} else if(i==dx&&j==dy) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);cout<<"█";} else if(i==bx&&j==by&&bed) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);cout<<"█";} else if(i==dbx&&j==dby&&dbed) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);cout<<"█";} else if(i==x&&j==y+fx) {j_out();} else {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED);cout<<"█";}}cout<<endl;}if(vs_map[x][y]==1) {x=1;y=0;}if(vs_map[dx][dy]==1) {dx=1;dy=9;}
}
int first() {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);cout<<"|----------|"<<endl;cout<<"|MC起床战争|"<<endl;cout<<"|网易花雨庭|"<<endl;cout<<"|按右键开始|"<<endl;cout<<"|----------|"<<endl;while(!KEY_DOWN(MOUSE_EVENT)) {}system("cls");bed=true;dbed=true;x=1;y=0;dbx=1;dby=9;bx=1;by=0;dx=1;dy=9;for(int i=1; i<9; i++) {vs_map[1][i]=1;}
}
int game_get_up() {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);cout<<"加载中"<<endl;for(int i=0; i<10; i++) {Sleep(500);}while(true) {out();play();AI();if(bed==false&&HP<=0) {system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE| FOREGROUND_GREEN);cout<<"失败";Sleep(2000);return 0;}if(dbed==false&&dHP<=0) {system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE| FOREGROUND_GREEN);cout<<"胜利";Sleep(2000);return 0;}go++;}
}
int main() {first();int n;while(true) {bed=true;dbed=true;x=1;y=0;dbx=1;dby=9;bx=1;by=0;dx=1;dy=9;for(int i=1; i<9; i++) {vs_map[1][i]=1;}system("cls");game_get_up();system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);cout<<"输入1退出,其他继续。";cin>>n;}
}