[其它]名字競技場C++


自己寫的,dalao勿噴

 

V1.1 有了名字判重系統,以及可以循環玩游戲了!

 

V1.2 可以多人玩游戲了!

 

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
struct note{
    char a[10];
    int hp;
    int gj;
};
note player[16];
int hit1,hit2,g[11],pdh1=0,pdh2=0,n;
void shuru();
void gj();
void youxi();
void slowsay(char a[]){
    for(int i=0;i<strlen(a);i++){
        cout<<a[i];
        Sleep(25);
    }
}
int main(){
    srand((unsigned)time(NULL));
    slowsay("歡迎來到名字競技場! by Steve_bm");
    cout<<endl;
    slowsay("V 1.2");
    cout<<endl;
    cout<<"請輸入人數:";
    cin>>n;
    shuru();
    youxi();
    return 0;
}
void gj(){
    int op1,op2;
    op1=rand()%n+1;
    op2=rand()%n+1;
    if((op1==op2)||(player[op1].hp==0||player[op2].hp==0)){
        while(1){
            op1=rand()%n+1;
            op2=rand()%n+1;
            if((op1!=op2)&&(player[op1].hp!=0&&player[op2].hp!=0)) break;
        }
    }
    hit1=rand()%player[op1].gj+1;
    player[op2].hp-=hit1;
       if(player[op2].hp<=0) player[op2].hp=0;
    cout<<player[op1].a<<""<<player[op2].a<<"發起了攻擊"<<endl;
    Sleep(500);
    if(hit1>=((player[op1].gj/3)*2)) cout<<player[op1].a<<"暴擊!"<<endl;
    cout<<player[op2].a<<"受到了"<<hit1<<"點傷害"<<endl;
    Sleep(250);
    cout<<player[op2].a<<"現在的生命值是"<<player[op2].hp<<endl;
    cout<<endl;
}
void youxi(){
    Sleep(1200);
    for(int t=1;t<=n;t++){
        int n1=player[t].a[0]+200;
        int q1=player[t].a[strlen(player[t].a)-1];
        player[t].hp=(rand()%n1+30)*9;
        player[t].gj=(rand()%q1+30)*7;
    }
    system("cls");
    for(int b=1;b<=n;b++){
        cout<<player[b].a<<" "<<"HP:"<<player[b].hp<<" "<<"攻擊力:"<<player[b].gj<<endl;
        cout<<endl;
    }
    cout<<endl;
    Sleep(3000);
    cout<<"現在開始!"<<endl;
    Sleep(1500);
    int w;
    int f=0;
    while(1){
        gj();
        Sleep(1000);
        cout<<endl;
        for(int i=1;i<=n;i++){
            if(player[i].hp==0) f++;
            if(player[i].hp>0) w=i;
        }
        if(f==n-1) break;
        f=0;
    }
    Sleep(1500);
    cout<<"勝利者是";
    cout<<player[w].a<<"!"<<endl;
    for(int m=1;m<=n;m++){
        if(player[m].hp==0){
        cout<<player[m].a<<"完敗!"<<endl;
        }
    }
    char l;
    Sleep(3000);
    cout<<"Do you want to play again?(Y/N)"<<endl;
    cin>>l;
    if(l=='Y'||l=='y'){
        system("cls");
        for(int h=1;h<=n;h++){
            memset(player[h].a,0,sizeof(player[h].a));
        }
        youxi();
    }
    else{
        exit(0);
    }
}
void shuru(){
    for(int l=1;l<=n;l++){
        cout<<"請輸入玩家"<<l<<"的名字(名字不超過10字符,最小3字符,不能有漢字!):"<<endl;
    scanf("%s",player[l].a);
    }
    int yy[11]={0};
    for(int i=1;i<n;i++){
        for(int o=i+1;o<=n;o++){
            for(int q=0;q<strlen(player[i].a);q++){
                if(player[i].a[q]==player[o].a[q]) yy[i]++;
            }
        }
    }
    for(int u=1;u<=n;u++){
        if(yy[u]==strlen(player[u].a)){
            system("cls");
              cout<<"輸入的名字不能相同!"<<endl;
               Sleep(100);
               cout<<"請重新輸入!"<<endl;
              shuru();
        }
        else youxi();
    }
}

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM