小型打怪游戏2

#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 sl=0;
int main()
{
    int g=10,boss=150,xl=30,sh=1,gj=2,sjsh=0;
    int ex = 1;
    int ey = 12;
    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(1){
        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 == '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] == '@') {
                    sjsh = rand()%8;
                    if(sjsh>=1){
                        g-=j;
                    }
                    else{
                        g=g-j*3;
                    }
                    xl-=rand()%7;
                }
                if ( maze[x+1][y] == 'T'|| maze[x-1][y] == 'T'|| maze[x][y+1] == 'T'|| maze[x][y-1] == 'T') {
                    sjsh = rand()%8;
                    if(sjsh>=1){
                        boss-=j;
                    }
                    else{
                        boss=g-j*3;
                    }
                    xl-=rand()%50;
                }
            }
//        int eop = rand()%4;
//        maze[ex][ey] = ' ';
//        if (eop == 0 && maze[ex-1][ey] != '#'&& maze[ex-1][ey] != '$') {
//            ex--;
//        } 
//        else if (eop == 1 && maze[ex+1][ey] != '#'&& maze[ex+1][ey] != '$') {
//            ex++;
//        } 
//        else if (eop == 2 && maze[ex][ey-1] != '#'&& maze[ex][ey-1] != '$') {
//            ey--;
//        } 
//        else if (eop == 3 && maze[ex][ey+1] != '#'&& maze[ex][ey+1] != '$') {
//            ey++;
//        }
//        
//        maze[ex][ey] = 'T';
        if(g<=0){
            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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值