ad左右移动,地图中F为武馆可以在那里按两次s加任意键开启战斗。战斗中ad移动,eq闪现,1攻击,受击时会有1秒闪烁。现在只有三张地图,武馆处可能有无限战斗的问题,多按一次s就行,注意用小写操控。(必看)
下面是代码:
#include<time.h>
#include<windows.h>
#include<iomanip>
#include<string>
#include<cmath>
#include<bits/stdc++.h>//头文件
#include<windows.h>//头文件
#include <conio.h>
#include <cstdio>
#include <fstream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
//角色信息
struct person
{
char na[255];
long long health;
long long attack;
int distance;
int speed;
long long money;
}player={"\0",100,2,1,5,1000};
//敌人信息
struct enemy
{
char na[255];
int health;
int attack;
int distance;
int skill;
}enemy[20]={{"\0",0,0,0,0},{"哥布林",10,2,1,0}};
struct enemy_instead
{
char na[255];
int health;
int attack;
int distance;
int skill;
}enemy_instead[20]={{"\0",0,0,0,0},{"哥布林",10,2,1,0}};
//商品信息
struct weapon
{
char na[255];
int attack;
int distance;
int skill;
int price;
bool have;
bool wear;
int color;
}weapon[20]={{"\0",0,0,0,0,0,0,0},{"木剑",5,1,0,0,0,0,1},{"铁剑",10,1,0,25,0,0,1},{"剑",10,1,0,25,0,0,3},{"剑",10,1,0,25,0,0,5}};
//药
struct bottle
{
char na[255];
int health;
int skill;
int price;
int have;
int color;
}bottle[20]={{"\0",0,0,0,0,0},{"小药水",10,0,10,0,1},{"中药水",50,0,25,0,1},{"大药水",100,0,50,0,1}};
//函数声明
void effect();
void effect_player();
void random_all();
void start_draw_fight();
void fight_move();
void Save();
void Read();
void color(int);
void slowplay();
void fastplay();
void shop_move();
void Map_move();
void shop();
void move();
void enemy_choice();
void draw_Map();
void shop_w();
void shop_h();
void shop_f();
void draw_fight();
//变量声明区
int random_fight,random_number;
bool get=0;
bool finish=0;
int step=0;
int action_enemy=4;
int x_fight;
int action=4;
int max_action=8;
bool fight=false;
int number=0;
int dudang;
int Lock(int);
int UnLock(int);
int item=0;
string chat;
char ch;
char bh;
int Exit=0;
int x,y,x_enemy,y_enemy;
int level=0;
int x_far=x-x_enemy;
int level_01=0;
bool chengjiu[1000];
char Map[100][100][100]={
{
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"## @",
"## @",
"## @",
"## @",
"##* @",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
},
{
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"@ @",
"@ @",
"@ @",
"@ @",
"@* @",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
},
{
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"@ @",
"@ @",
"@ @",
"@ @",
"@* @",
"####W####H####F#########################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
}
};
char fight_map[100][100]={
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"#* !#",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
};
char instead_fight_map[100][100]={
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"#* !#",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
"########################################",
};
int main()
{
chat="要读档吗。。。";
slowplay();
cout<<"1读!2NO"<<endl;
cin>>dudang;
if(dudang==1) {
chat="请稍等(你如果没存档那后果自负)";
slowplay();
Read();
}
if(dudang==2) {
chat="请输入你的名字";
slowplay();
cin>>player.na;
cout<<"你好"<<player.na<<" 请开始你的冒险"<<endl;
Sleep(2000);
}
start:
system("cls");
/*****地图*****/
/*****初始化*****/
cout<<"小游戏(@是出口)"<<endl;
/*****打印Map(a)*****/
for (int i=0;i<=16;i++)
{
for (int j=0;j<=39;j++)
{
if(Map[level][i][j]=='#') color(1);
else color(6);
if (Map[level][i][j]=='*') x=j,y=i;
printf("%c",Map[level][i][j]);
}
cout<<endl;
}
/*****移动*****/
while(1){
srand(time(0));
random_all();
if(fight==true){
start_draw_fight();
while(player.health>0&&enemy[1].health>0){
while(action_enemy>0 && player.health>0&&enemy[1].health>0){
draw_fight();
enemy_choice();
}
while(action>0 && player.health>0&&enemy[1].health>0){
draw_fight();
fight_move();
}
step++;
action=4;
action_enemy=4;
}
enemy[1].health=enemy_instead[1].health;
fight=false;
x_fight==1;
x_enemy==38;
}
draw_Map();
cout<<"x标"<<x<<" "<<"y标"<<y<<" "<<"地图"<<level<<" 随机数a,b"<<random_fight<<" "<<random_number<<endl;
shop();
move();
Map_move();
Save();
}
return 0;
}
//加密
int Lock(int x)
{
return (x+3141)*592-6535897+9323846;
}
//解密
int Unlock(int x)
{
return (x-9323846+6535897)/592-3141;
}
//字体颜色
void color(int a)
{
switch(a)
{
//黑底白字
case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);break;
//黑底红字
case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);break;
//黑底绿字
case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);break;
//黑底黄字
case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);break;
//黑底蓝字
case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);break;
//黑底品红
case 6:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);break;
//黑底青色
case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);break;
}
}
//慢输出
void slowplay()
{
int l=chat.length();
for(int i=0;i<l;i++)
printf("%c",chat[i]),Sleep(85);cout<<endl;
}
//快输出
void fastplay()
{
int l=chat.length();
for(int i=0;i<l;i++)
printf("%c",chat[i]),Sleep(2);cout<<endl;
}
//移动
void move(){
ch=_getch();
if(ch=='a'){
if(Map[level][y][x-1]!='#'&&Map[level][y][x-1]!='+'&&Map[level][y][x-1]!='@'){
Map[level][y][x]=' ';
x--;
Map[level][y][x]='*';
}
}
if(ch=='d'){
if(Map[level][y][x+1]!='#'&&Map[level][y][x+1]!='+'&&Map[level][y][x+1]!='@'){
Map[level][y][x]=' ';
x++;
Map[level][y][x]='*';
}
}
}
//副本移动
//地图移动
void Map_move()
{
if(x==38) {
level++;
}
if(x==1){
level--;
}
}
//商店选择
void shop_move(){
if(ch=='w'){
item--;
}
if(ch=='s'){
item++;
}
if(item<0||ch=='a'||ch=='d'){
item=0;
}
}
//商店__W
void shop_w(){
//get=1;
for(int i=1;i<=7;i++){
color(weapon[i].color);
cout<<weapon[i].na<<" 攻击:"<<weapon[i].attack<<" 射程:"<<weapon[i].distance<<" 价格:"<<weapon[i].price<<" 是否拥有:"<<weapon[i].have<<endl;
}
}
//商店__H
void shop_h(){
//get=2;
for(int i=1;i<=7;i++){
color(bottle[i].color);
cout<<bottle[i].na<<" 回血:"<<bottle[i].health<<" 特殊效果:"<<bottle[i].skill<<" 价格:"<<bottle[i].price<<" 拥有:"<<bottle[i].have<<endl;
}
}
//商店__F
void shop_f(){
if(item==2)fight=true;
else fight=false;
}
//商店交互
void shop()
{ //武器
if(level==2&&x==4) {
shop_move();
cout<<item<<endl;
shop_w();
}
if(level==2&&x==9) {
shop_move();
cout<<item<<endl;
shop_h();
}
//馆
if(level==2&&x==14) {
shop_move();
cout<<item;
shop_f();
}
}
//画地图
void draw_Map(){
system("cls");
cout<<"小游戏(@是出口)"<<endl;
for (int i=0;i<=16;i++)
{
for (int j=0;j<=39;j++)
{
if(Map[level][i][j]=='#') color(1);
else color(6);
if (Map[level][i][j]=='*') x=j,y=i;
cout<<Map[level][i][j];
}
cout<<endl;
}
}
//存档(已完成)
void Save()
{
ofstream out("Save_map.txt");
//presonal information
out<<player.na<<'\n';
out<<Lock(player.health)<<' '<<Lock(player.speed)<<' ';
out<<Lock(player.money)<<'\n';
//书&询问
out<<level<<' '<<'\n';
out.close();
}
//读档(已完成)
void Read()
{
ifstream in("Save_map.txt");
int lalala;
//presonal information
in>>player.na;
in>>(player.health)>>(player.speed);
in>>(player.money);
player.health=Unlock(player.health);
player.speed=Unlock(player.speed);
player.money=Unlock(player.money);
//level
in>>level;
in.close();
}
//战斗地图
void draw_fight(){
system("cls");
for (int i=0;i<=16;i++)
{
for (int j=0;j<=39;j++)
{
if(fight_map[i][j]=='#') color(1);
if(fight_map[i][j]=='!') color(2);
if(fight_map[i][j]=='*') color(6);
if (fight_map[i][j]=='*') x_fight=j,y=i;
if (fight_map[i][j]=='!') x_enemy=j,y_enemy=i;
cout<<fight_map[i][j];
}
cout<<endl;
}
cout<<x<<" "<<y<<" "<<x_enemy<<" "<<y_enemy<<endl;
cout<<"行动点;"<<action<<endl;
}
//初始战斗地图
void start_draw_fight(){
system("cls");
for (int i=0;i<=16;i++)
{
for (int j=0;j<=39;j++)
{
fight_map[i][j]=instead_fight_map[i][j];
}
}
}
//角色移动
void fight_move(){
bh=_getch();
int far_x;
x_far=x_fight-x_enemy;
far_x=abs(x_far);
if(bh=='a'&& action>0){
if(fight_map[y][x_fight-1]!='#'&&fight_map[y][x_fight-1]!='+'&&fight_map[y][x_fight-1]!='!'){
fight_map[y][x_fight]=' ';
x_fight--;
fight_map[y][x_fight]='*';
action--;
}
}
if(bh=='d'&& action>0){
if(fight_map[y][x_fight+1]!='#'&&fight_map[y][x_fight+1]!='+'&&fight_map[y][x_fight+1]!='!'){
fight_map[y][x_fight]=' ';
x_fight++;
fight_map[y][x_fight]='*';
action--;
}
}
if(bh=='q' && action>1){
if(fight_map[y][x_fight-3]!='#'&&fight_map[y][x_fight-3]!='+'&&fight_map[y][x_fight-3]!='!'&&x_fight-3>=1){
fight_map[y][x_fight]=' ';
x_fight-=3;
fight_map[y][x_fight]='*';
action-=2;
}
}
if(bh=='e'&& action>1){
if(fight_map[y][x_fight+3]!='#'&&fight_map[y][x_fight+3]!='+'&&fight_map[y][x_fight+3]!='!'&&x_fight+3<=38){
fight_map[y][x_fight]=' ';
x_fight+=3;
fight_map[y][x_fight]='*';
action-=2;
}
}
if(bh=='1'&&far_x<=player.distance&& action>1){
enemy[1].health-=player.attack;
color(2);
cout<<enemy[1].health;
Sleep(500);
action-=2;
effect();
}
}
//战斗
void enemy_choice(){
x_far=x_fight-x_enemy;
int far_x=abs(x_far);
if(far_x>enemy[1].distance){
if(x_far>1){
fight_map[10][x_enemy]=' ';
x_enemy++;
fight_map[10][x_enemy]='!';
action_enemy--;
}
if(x_far<1){
fight_map[10][x_enemy]=' ';
x_enemy--;
fight_map[10][x_enemy]='!';
action_enemy--;
}
}
if(far_x<=enemy[1].distance&&action_enemy>1){
player.health-=enemy[1].attack;
color(3);
cout<<player.health;
Sleep(500);
action_enemy-=2;
effect_player();
}
if(far_x<=enemy[1].distance&&action_enemy==1){
cout<<"";
action_enemy-=1;
}
}
//随机数
void random_all(){
random_fight=rand()%101;
random_number=rand()%1001;
}
//受击特效
void effect(){
for(int a=0;a<=3;a++){
system("cls");
if(a%2==0) fight_map[y_enemy][x_enemy]=' ';
else fight_map[y_enemy][x_enemy]='!';
for (int i=0;i<=16;i++)
{
for (int j=0;j<=39;j++)
{
if(fight_map[i][j]=='#') color(1);
if(fight_map[i][j]=='!') color(2);
if(fight_map[i][j]=='*') color(6);
if (fight_map[i][j]=='*') x_fight=j,y=i;
if (fight_map[i][j]=='!') x_enemy=j,y_enemy=i;
cout<<fight_map[i][j];
}
cout<<endl;
}
cout<<x<<" "<<y<<" "<<x_enemy<<" "<<y_enemy<<endl;
cout<<"行动点;"<<action<<endl;
Sleep(250);
}
}
void effect_player(){
for(int a=0;a<=3;a++){
system("cls");
if(a%2==0) fight_map[y][x_fight]=' ';
else fight_map[y][x_fight]='*';
for (int i=0;i<=16;i++)
{
for (int j=0;j<=39;j++)
{
if(fight_map[i][j]=='#') color(1);
if(fight_map[i][j]=='!') color(2);
if(fight_map[i][j]=='*') color(6);
if (fight_map[i][j]=='*') x_fight=j,y=i;
if (fight_map[i][j]=='!') x_enemy=j,y_enemy=i;
cout<<fight_map[i][j];
}
cout<<endl;
}
cout<<x<<" "<<y<<" "<<x_enemy<<" "<<y_enemy<<endl;
cout<<"行动点;"<<action<<endl;
Sleep(250);
}
}