0
已解决
周明轩
资深光能
资深光能
我写了一个垃圾的代码:
#include<bits/stdc++.h>
#include<windows.h>
#pragma GCC optimize(2)
using namespace std;
struct play_date{
int map_i;
int p_x,p_y;
int p_hp;
int p_h;
}player;
struct mon_date{
int m_hp;
int m_h;
}mon;
string note="W、A、S、D移动,碰到门就会到下一张地图,碰到怪会开始战斗,◎是重生点。\n";
void ini_p(void){
player.map_i=0;
player.p_x=1;
player.p_y=1;
player.p_hp=100;
player.p_h=5;
}
void ini_m(void){
mon.m_hp=20;
mon.m_h=2;
}
int map_p[2][5][8]={
{
{1,1,1,1,1,1,1,1},
{1,4,0,0,0,0,0,1},
{1,0,0,0,0,0,0,2},
{1,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1}
},
{
{1,1,1,1,1,1,1,1},
{1,0,3,0,0,0,0,1},
{2,0,0,0,0,3,0,1},
{1,0,0,3,0,0,0,1},
{1,1,1,1,1,1,1,1}
}
};
void out(void){
for(int x=0;x<5;x++){
for(int y=0;y<8;y++){
if(x==player.p_x&&y==player.p_y){
cout<<"玩";
continue;
}
if(map_p[player.map_i][x][y]==4){
cout<<"◎";
}
if(map_p[player.map_i][x][y]==1){
cout<<"■";
}
if(map_p[player.map_i][x][y]==0){
cout<<" ";
}
if(map_p[player.map_i][x][y]==3){
cout<<"怪";
}
if(map_p[player.map_i][x][y]==2){
cout<<"门";
}
}
cout<<endl;
}
cout<<note;
}
bool Cross(int x,int y){
if(x<4&&x>0&&y<7&&y>0){
return true;
}
else{
return false;
}
}
void print_p(){
for(int i=1;i<=24;i++){
system("cls");
for(int j=2;j<=i;j++){
cout<<' ';
}
cout<<"我";
for(int j=1;j<=24-i;j++){
cout<<' ';
}
cout<<"怪";
cout<<"\n生命值:"<<setw(3)<<player.p_hp<<" 生命值:"<<setw(2)<<mon.m_hp;
cout<<"\n战斗力:"<<setw(3)<<player.p_h<<" 战斗力:"<<setw(2)<<mon.m_h;
Sleep(1);
}
Sleep(999);
system("cls");
cout<<"我 怪"<<endl;
cout<<"生命值:"<<setw(3)<<player.p_hp<<" 生命值:"<<setw(2);
cout<<mon.m_hp<<'-'<<player.p_h;
cout<<"\n战斗力:"<<setw(3)<<player.p_h<<" 战斗力:"<<setw(2)<<mon.m_h;
mon.m_hp-=player.p_h;
Sleep(1000);
return ;
}
void print_m(){
for(int i=1;i<=24;i++){
system("cls");
cout<<"我";
for(int j=1;j<=24-i;j++){
cout<<' ';
}
cout<<"怪";
cout<<"\n生命值:"<<setw(3)<<player.p_hp<<" 生命值:"<<setw(2)<<mon.m_hp;
cout<<"\n战斗力:"<<setw(3)<<player.p_h<<" 战斗力:"<<setw(2)<<mon.m_h;
Sleep(1);
}
Sleep(999);
system("cls");
cout<<"我 怪"<<endl;
cout<<"生命值:"<<setw(3)<<player.p_hp<<'-'<<mon.m_h;
cout<<" 生命值:"<<setw(2)<<mon.m_hp;
cout<<"\n战斗力:"<<setw(3)<<player.p_h<<" 战斗力:"<<setw(2)<<mon.m_h;
player.p_hp-=mon.m_h;
Sleep(1000);
return ;
}
void fight(void){
int mon_hp=20;
int mon_h=2;
while(1){
system("cls");
cout<<"我 怪"<<endl;
cout<<"生命值:"<<setw(3)<<player.p_hp<<" 生命值:"<<setw(2)<<mon.m_hp;
cout<<"\n战斗力:"<<setw(3)<<player.p_h<<" 战斗力:"<<setw(2)<<mon.m_h;
cout<<"\n1.攻击 0.逃跑";
int ls;
cin>>ls;
if(ls!=1&&ls!=0){
do{
cout<<"不支持,请重新输入。";
cin>>ls;
}while(ls!=1&&ls!=0);
}
if(ls==1){
print_p();
print_m();
}
else{
system("cls");
return ;
}
if(player.p_hp<=0){
return ;
}
if(mon.m_hp<=0){
system("cls");
cout<<"胜利!!!";
Sleep(1000);
system("cls");
ini_m();
return ;
}
}
}
void play(void){
char c;
while(1){
out();
cin>>c;
if(c!='W'&&c!='A'&&c!='S'&&c!='D'){
do{
cout<<"不支持,请重新输入。\n";
cin>>c;
}while(c!='W'&&c!='A'&&c!='S'&&c!='D');
}
if(c=='W'){
if(map_p[player.map_i][player.p_x-1][player.p_y]==2){
if(player.map_i==0){
player.map_i=1;
player.p_x=2;
player.p_y=0;
}
else{
player.map_i=0;
player.p_x=2;
player.p_y=5;
}
}
if(Cross(player.p_x-1,player.p_y)){
player.p_x--;
}
}
if(c=='A'){
if(map_p[player.map_i][player.p_x][player.p_y-1]==2){
if(player.map_i==0){
player.map_i=1;
player.p_x=2;
player.p_y=0;
}
else{
player.map_i=0;
player.p_x=2;
player.p_y=5;
}
}
if(Cross(player.p_x,player.p_y-1)){
player.p_y--;
}
}
if(c=='S'){
if(map_p[player.map_i][player.p_x+1][player.p_y]==2){
if(player.map_i==0){
player.map_i=1;
player.p_x=2;
player.p_y=0;
}
else{
player.map_i=0;
player.p_x=2;
player.p_y=5;
}
}
if(Cross(player.p_x+1,player.p_y)){
player.p_x++;
}
}
if(c=='D'){
if(map_p[player.map_i][player.p_x][player.p_y+1]==2){
if(player.map_i==0){
player.map_i=1;
player.p_x=2;
player.p_y=0;
}
else{
player.map_i=0;
player.p_x=2;
player.p_y=5;
}
}
if(Cross(player.p_x,player.p_y+1)){
player.p_y++;
}
}
system("cls");
if(map_p[player.map_i][player.p_x][player.p_y]==3){
fight();
}
if(player.p_hp<=0){
system("cls");
cout<<"GAMEOVER!!!";
Sleep(1000);
system("cls");
ini_p();
Sleep(1000);
}
}
return ;
}
void be_in(void){
cout<<"欢迎来到勇者的世界";
Sleep(1000);
char c='%';
for(int i=0;i<=100;i++){
system("cls");
cout<<"正在进入游戏中……"<<i<<c;
Sleep(10);
}
Sleep(1000);
system("cls");
return ;
}
int main(){
ini_p();
ini_m();
be_in();
play();
return 0;
}
请各位大佬指点
周明轩在2020-09-12 10:10:08追加了内容
顶!!!
0
已采纳
余彦文
初级光能
初级光能
可以再加几张地图,顺便加一下武器商店,毕竟一下一下的打手好累
余彦文在2020-09-12 10:49:08追加了内容
有代码共享标签,妈妈再也不用担心我发代码禁言了
0
0
0
0
叶子滔
高级守护
高级守护
你的bug有点多,比如打架时怪物0血是还打一下,然后就是可以在多做几个地图,比如一个地图多个门,还有就是你的移动可以一次性移动,武器也可以做一些,技能药品也搞起来,加油,你还能更好ヾ(◍°∇°◍)ノ゙
0