小型打怪游戏1

#include <bits/stdc++.h>
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <ctime>
#include <cstdlib> 
using namespace std;
char maze[15][35] = {
    "###################",
    "#O   #      T     #",
    "#       @         #",
    "###################",
};
int g=10,boss=500,xl=30,sh=1,gj=2;
int sl=0;
int main()
{
    int x = 1, y = 1,j=1;
    for(int i=0;i<=99;i++){
        Sleep(0.1);
        cout<<"                  加载中  "<<i<<"%";
        system("cls");
    }
    cout<<"                  加载中  "<<99<<"%";
    Sleep(5000);
    system("cls");
    cout<<"                  加载中  "<<100<<"%";
    Sleep(100);
    system("cls");
    cout<<endl<<endl<<endl<<"                         小学生出品";
    Sleep(3000);
    system("cls");
    char op;
    srand(time(0));
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 35; j++) {
            cout << maze[i][j] << " ";
        }
        cout << endl;
    }
    cout<<endl<<"x=杀,w=上,s=下,a=左,d=右。"<<endl<<"@=怪    T=boss"<<endl<<"怪的血:"<<g<<"       boss的血:"<<boss<<endl<<"你的血量:"<<xl<<"            伤害:"<<j; 
    while (true) {
        // 主角移动 
        op = getch();
        if (op == 'w' && maze[x-1][y] != '#'&& maze[x-1][y] != '@'&& maze[x-1][y] != 'T') {
            maze[x][y] = ' ';
            x--;
        }
        else if (op == 's' && maze[x+1][y] != '#'&& maze[x+1][y] != '@'&& maze[x+1][y] != 'T') {
            maze[x][y] = ' ';
            x++;
        }
        else if (op == 'a' && maze[x][y-1] != '#'&& maze[x][y-1] != '@'&& maze[x][y-1] != 'T') {
            maze[x][y] = ' ';
            y--;
        }
        else if (op == 'd' && maze[x][y+1] != '#'&& maze[x][y+1] != '@'&& maze[x][y+1] != 'T') {
            maze[x][y] = ' ';
            y++;
        }
        else if (op == 'x' ) {
            if (maze[x+1][y] == '@'|| maze[x-1][y] == '@'|| maze[x][y+1] == '@'|| maze[x][y-1] == '@') {
                g-=j;
                xl-=rand()%7;
            }
            if ( maze[x+1][y] == 'T'|| maze[x-1][y] == 'T'|| maze[x][y+1] == 'T'|| maze[x][y-1] == 'T') {
                boss-=j;
                xl-=rand()%50;
            }
        }
        if(g<=0){
            j+=rand()%10;
            g+=gj*10;
            xl+=rand()%30;
            gj++;
        }
        if(xl<=0){
            system("cls");
            break;
        } 
        system("cls");
        
        maze[x][y]='O';
        if(boss<=0){
            boss=0;
            sl=1;
            system("cls");
            break;
        }
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 35; j++) {
                cout << maze[i][j] << " ";
            }
            cout << endl;
        }
        cout<<endl<<"@=怪    T=boss"<<endl<<"怪的血:"<<g<<"       boss的血:"<<boss<<endl<<"你的血量:"<<xl<<"            伤害:"<<j; 
    }
    if(sl==1)cout<<endl<<endl<<"                              你赢了"; 
    else cout<<endl<<endl<<"                              你输了"; 
    Sleep(5000);
    return 0;
}

//好了,今天的代码就到此结束了,各位点个赞呗。

  • 15
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值