C++小游戏免费战列舰(重发)

 当二站结束,硝烟散去——


2024,6月之前,《战列舰》正式出版!

库:

#include <bits/stdc++.h>
#include <windows.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

定义与函数:

using namespace std;
short z[5],f[15];
short dd1[5],dd2[15];
short ma[10][10];
int xx1,xx2,ssssss=1,n=2;
void gz()
{
    cout<<" 1>>   主炮射击%5  命中率"<<endl<<" -   52500~62500伤害  z+Enter+主炮编号"<<endl<<" (4门   每门间隔2次操作换弹)"<<endl<<endl;
    cout<<" 2>>   副炮射击%50 命中率"<<endl<<" -1500~2500 伤害  f+Enter+副炮编号"<<endl<<" (15门  每门间隔1次操作换弹)"<<endl<<endl;
    cout<<" 3>>   [w][s][a][d]左右xy坐标移动"<<endl<<endl;
}
bool pd(int n)
{
    if(n<=0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
void fj(int a,int b)
{
    int jx;
    cout<<"敌方反击!"<<endl;
    for(int i=1; i<=n; i++)
    {
        sleep(1);
        cout<<endl<<"*"<<i<<endl;
        if(a<=3000&&b<=3000)
        {
            jx=rand()%2000+5000;
            if(pd(a)==true)
            {
                a=0,b=0;
                cout<<"旗舰:"<<a<<endl;
                cout<<"辅舰:"<<b<<endl;
                sleep(2);
                system("CLS");
                cout<<"                                      -----------------"<<endl;
                cout<<"                                      |     LOSE      |"<<endl;
                cout<<"                                      -----------------"<<endl;
                sleep(2);
                ssssss=0;
                return;
            }
            else
            {
                b-=jx;
                cout<<"旗舰:"<<a<<endl;
                cout<<"辅舰:"<<b<<endl;
                sleep(1);
            }
        }
        else
        {
            short sj=rand()%2;
            if(sj==1)
            {
                cout<<"主炮射击!%10";
                sleep(1);
                cout<<'\n';
                int jz=rand()%10;
                srand(time(0));
                if(jz==7)
                {
                    cout<<"--  未击中  --"<<endl;
                    cout<<"旗舰:"<<a<<endl;
                    cout<<"辅舰:"<<b<<endl;
                    sleep(1);
                    srand(time(0));    
                } 
                else
                {
                    
                    short jl=(rand()%6000+1000)*3*(rand()%5+1);
                    srand(time(0));
                    if(b-jl>=100)
                    {
                        b-=jl;
                    }
                    else
                    {
                        b=0;
                        a-=jl;
                    }
                    if(pd(a)==true)
                    {
                        a=0,b=0;
                        cout<<"旗舰:"<<a<<endl;
                        cout<<"辅舰:"<<b<<endl;
                        sleep(2);
                        system("CLS");
                        cout<<"                                      -----------------"<<endl;
                        cout<<"                                      |     LOSE      |"<<endl;
                        cout<<"                                      -----------------"<<endl;
                        sleep(2);
                        ssssss=0;
                        return;
                    }
                    else
                    {
                        cout<<"旗舰:"<<a<<endl;
                        cout<<"辅舰:"<<b<<endl;
                        sleep(1);
                    }
                }
            }
            else
            {
                cout<<"副炮射击!%100";
                sleep(1);
                cout<<'\n';
                int jl=(rand()%800+50)*(rand()%15+10);
                if(b-jl>=5000)
                {
                    b=b-jl;
                }
                else
                {
                    a=a-jl;
                }
                if(pd(a)==true)
                {
                    a=0,b=0;
                    cout<<"旗舰:"<<a<<endl;
                    cout<<"辅舰:"<<b<<endl;
                    sleep(2);
                    system("CLS");
                    cout<<"                                      -----------------"<<endl;
                    cout<<"                                      |     LOSE      |"<<endl;
                    cout<<"                                      -----------------"<<endl;
                    sleep(2);
                    ssssss=0;
                    return; 
                }
                else
                {
                    cout<<"旗舰:"<<a<<endl;
                    cout<<"辅舰:"<<b<<endl;
                    sleep(1);
                }    
            }
        }    
    }
    xx1=a,xx2=b;
}

using namespace std;
short z[5],f[15];
short dd1[5],dd2[15];
short ma[10][10];
int xx1,xx2,ssssss=1,n=2;
void gz()
{
	cout<<" 1>>   主炮射击%5  命中率"<<endl<<" -   52500~62500伤害  z+Enter+主炮编号"<<endl<<" (4门   每门间隔2次操作换弹)"<<endl<<endl;
	cout<<" 2>>   副炮射击%50 命中率"<<endl<<" -1500~2500 伤害  f+Enter+副炮编号"<<endl<<" (15门  每门间隔1次操作换弹)"<<endl<<endl;
	cout<<" 3>>   [w][s][a][d]左右xy坐标移动"<<endl<<endl;
}
bool pd(int n)
{
	if(n<=0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
void fj(int a,int b)
{
	int jx;
	cout<<"敌方反击!"<<endl;
	for(int i=1; i<=n; i++)
	{
		sleep(1);
		cout<<endl<<"*"<<i<<endl;
		if(a<=3000&&b<=3000)
		{
			jx=rand()%2000+5000;
			if(pd(a)==true)
			{
				a=0,b=0;
				cout<<"旗舰:"<<a<<endl;
				cout<<"辅舰:"<<b<<endl;
				sleep(2);
				system("CLS");
				cout<<"                                      -----------------"<<endl;
				cout<<"                                      |     LOSE      |"<<endl;
				cout<<"                                      -----------------"<<endl;
				sleep(2);
				ssssss=0;
				return;
			}
			else
			{
				b-=jx;
				cout<<"旗舰:"<<a<<endl;
				cout<<"辅舰:"<<b<<endl;
				sleep(1);
			}
		}
		else
		{
			short sj=rand()%2;
			if(sj==1)
			{
				cout<<"主炮射击!%10";
				sleep(1);
				cout<<'\n';
				int jz=rand()%10;
				srand(time(0));
				if(jz==7)
				{
					cout<<"--  未击中  --"<<endl;
					cout<<"旗舰:"<<a<<endl;
					cout<<"辅舰:"<<b<<endl;
					sleep(1);
					srand(time(0));	
				} 
				else
				{
					
					short jl=(rand()%6000+1000)*3*(rand()%5+1);
					srand(time(0));
					if(b-jl>=100)
					{
						b-=jl;
					}
					else
					{
						b=0;
						a-=jl;
					}
					if(pd(a)==true)
					{
						a=0,b=0;
						cout<<"旗舰:"<<a<<endl;
						cout<<"辅舰:"<<b<<endl;
						sleep(2);
						system("CLS");
						cout<<"                                      -----------------"<<endl;
						cout<<"                                      |     LOSE      |"<<endl;
						cout<<"                                      -----------------"<<endl;
						sleep(2);
						ssssss=0;
						return;
					}
					else
					{
						cout<<"旗舰:"<<a<<endl;
						cout<<"辅舰:"<<b<<endl;
						sleep(1);
					}
				}
			}
			else
			{
				cout<<"副炮射击!%100";
				sleep(1);
				cout<<'\n';
				int jl=(rand()%800+50)*(rand()%15+10);
				if(b-jl>=5000)
				{
					b=b-jl;
				}
				else
				{
					a=a-jl;
				}
				if(pd(a)==true)
				{
					a=0,b=0;
					cout<<"旗舰:"<<a<<endl;
					cout<<"辅舰:"<<b<<endl;
					sleep(2);
					system("CLS");
					cout<<"                                      -----------------"<<endl;
					cout<<"                                      |     LOSE      |"<<endl;
					cout<<"                                      -----------------"<<endl;
					sleep(2);
					ssssss=0;
					return; 
				}
				else
				{
					cout<<"旗舰:"<<a<<endl;
					cout<<"辅舰:"<<b<<endl;
					sleep(1);
				}	
			}
		}	
	}
	xx1=a,xx2=b;
}

int main() :

int main()
{
    srand(time(0));
    int nl;
    memset(dd1,0,sizeof(dd1));
    memset(dd2,0,sizeof(dd2));
    memset(ma,0,sizeof(ma));
    printf("能量值:(50000~150000)");
    cin>>nl;
    while(nl<50000||nl>150000)
    {
        cout<<"Error!"<<endl;
        cin>>nl;
    }
    int z1=rand()%300000+5000,z2=rand()%150000+5000;
    z1+=50000,z2+=50000;
    z1=abs(z1),z2=abs(z2);
    string xz;
    int fz;
    printf("辅助舰艇能量: (50000~100000)");
    cin>>fz;
    cout<<"[1]敌方旗舰能量:"<<z1<<endl<<"[2]敌方僚舰能量:"<<z2<<endl;
    sleep(2);
    while(fz<50000||fz>100000)
    {
        cout<<"Error!"<<endl;
        cin>>fz;
    }
    system("CLS");
    cout<<"* * * * * * * * * * * * * * * * * * *正式战斗* * * * * * * * * * * * * * * * * * *"<<endl<<endl;
    string pt;
    int x1=rand()%5+1,y1=rand()%5+1;
    srand(time(0));
    int dx=rand()%5,dy=rand()%5;
    int dx2=dx+5,dy2=dy+5;
    int x2=x1+5,y2=y1+5;
    gz();
    printf("操作:");
    while(cin>>pt)
    {
        srand(time(0));
        int x;
        if(pt=="z")
        {
            printf("主炮编号:");
            cin>>x;
            if(dd1[x]>0)
            {
                cout<<"装填未完成!!!"<<endl;
            }
            else
            {
                dd1[x]=3;
                int sj1=rand();
                sj1%=20;
                if(sj1==3)
                {
                    int kk=rand()%2;
                    kk++;
                    srand(time(0));
                    printf("命中!");
                    if(kk==1)
                    {
                        int jj=rand()%10000*abs((rand()%3+1));
                        jj+=17500*3;//62500 52500
                        z1-=jj;
                        if(pd(z1)==true)
                        {
                            cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"               WIN!"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
                            srand(time(0));
                        }
                    }
                    else
                    {
                        int jj=rand()%1250;
                        jj*=3;
                        jj+=1750*3;
                        z1-=jj;
                        if(pd(z2)==true)
                        {
                            cout<<"敌方僚舰被击沉!"<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"               WIN!"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
                            srand(time(0));
                        }
                    }
                }
                else
                {
                    printf("未击中!");
                    srand(time(0));
                }
            }
            dd1[1]--;
            dd1[2]--;
            dd1[3]--;
            dd1[4]--;
            srand(time(0));
        }
        else if(pt=="f")
        {
            srand(time(0));
            printf("副炮编号:");
            cin>>x;
            if(dd2[x]>0)
            {
                cout<<"装填未完成!!!"<<endl;
                srand(time(0));
            }
            else
            {
                int jjj=rand()%2;
                if(jjj==0)
                {
                    dd2[x]=2;
                    int kk=rand()%2;
                    kk++;
                    srand(time(0));
                    printf("命中!");
                    srand(time(0));
                    if(kk==1)
                    {
                        int jj=rand()%2000;
                        jj+=1500*3*abs(rand()%15+1);
                        z1-=jj;
                        if(pd(z1)==true)
                        {
                            cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"               WIN!"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
                        }
                    }
                    else
                    {
                        z2-=(rand()%100+100)*2;
                        if(pd(z2)==true)
                        {
                            cout<<"敌方僚舰被击沉!"<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"                                      -----------------"<<endl;
                                cout<<"                                      |      WIN      |"<<endl;
                                cout<<"                                      -----------------"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
                        }
                    }
                }
                else
                {
                    printf("未击中!");
                    srand(time(0));
                }
                for(int i=1; i<=15; i++)
                {
                    dd2[i]--;
                    srand(time(0));
                }
                srand(time(0));    
            }
                
        }
        else if(pt=="w")
        {
            printf("上");
            cout<<'\n';
            x1--;
        }
        else if(pt=="s")
        {
            printf("下");
            cout<<'\n';
            x1++;
        }
        else if(pt=="a")
        {
            printf("左");
            cout<<'\n';
            y1--;
        }
        else if(pt=="d")
        {
            printf("右");
            cout<<'\n';
            y1++;
        }
        else
        {
            cout<<"ERROR!"<<endl;
        }
        cout<<"地图:  z(你) f(辅助) 0(无舰艇) K/k(敌军)"<<endl;
        for(int i=1; i<=10; i++)
        {
            for(int j=1; j<=10; j++)
            {
                if(i==x1&&j==y1&&nl>0)
                {
                    cout<<"z ";
                }
                else if(i==x2&&j==x2&&fz>0)
                {
                    cout<<"f ";
                }
                else if(i==dx&&j==dy&&z2>0)
                {
                    cout<<"k ";
                }
                else if(i==dx2&&j==dy2&&z1>0)
                {
                    cout<<"K ";
                }
                else
                {
                    cout<<"0 ";
                }
            }
            cout<<'\n';
        }
        nl+=10,fz+=10;
        fj(nl,fz);
        nl=xx1,fz=xx2;
        if(nl<=0||ssssss==0)
        {
            system("CLS");
            cout<<"                                      -----------------"<<endl;
            cout<<"                                      |   GAME OVER   |"<<endl;
            cout<<"                                      -----------------"<<endl;
            return 0;
        }
        if(fz<=0)
        {
            fz=0;
        }
        sleep(5);
        system("CLS");
        gz();
        printf("操作:");
        srand(time(0));
    }
    srand(time(0));
    return 0;
}

int main()
{
	srand(time(0));
	int nl;
	memset(dd1,0,sizeof(dd1));
	memset(dd2,0,sizeof(dd2));
	memset(ma,0,sizeof(ma));
	printf("能量值:(50000~150000)");
	cin>>nl;
	while(nl<50000||nl>150000)
	{
		cout<<"Error!"<<endl;
		cin>>nl;
	}
	int z1=rand()%300000+5000,z2=rand()%150000+5000;
	z1+=50000,z2+=50000;
	z1=abs(z1),z2=abs(z2);
	string xz;
	int fz;
	printf("辅助舰艇能量: (50000~100000)");
	cin>>fz;
	cout<<"[1]敌方旗舰能量:"<<z1<<endl<<"[2]敌方僚舰能量:"<<z2<<endl;
	sleep(2);
	while(fz<50000||fz>100000)
	{
		cout<<"Error!"<<endl;
		cin>>fz;
	}
	system("CLS");
	cout<<"* * * * * * * * * * * * * * * * * * *正式战斗* * * * * * * * * * * * * * * * * * *"<<endl<<endl;
	string pt;
	int x1=rand()%5+1,y1=rand()%5+1;
	srand(time(0));
	int dx=rand()%5,dy=rand()%5;
	int dx2=dx+5,dy2=dy+5;
	int x2=x1+5,y2=y1+5;
	gz();
	printf("操作:");
	while(cin>>pt)
	{
		srand(time(0));
		int x;
		if(pt=="z")
		{
			printf("主炮编号:");
			cin>>x;
			if(dd1[x]>0)
			{
				cout<<"装填未完成!!!"<<endl;
			}
			else
			{
				dd1[x]=3;
				int sj1=rand();
				sj1%=20;
				if(sj1==3)
				{
					int kk=rand()%2;
					kk++;
					srand(time(0));
					printf("命中!");
					if(kk==1)
					{
						int jj=rand()%10000*abs((rand()%3+1));
						jj+=17500*3;//62500 52500
						z1-=jj;
						if(pd(z1)==true)
						{
							cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"               WIN!"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
							srand(time(0));
						}
					}
					else
					{
						int jj=rand()%1250;
						jj*=3;
						jj+=1750*3;
						z1-=jj;
						if(pd(z2)==true)
						{
							cout<<"敌方僚舰被击沉!"<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"               WIN!"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
							srand(time(0));
						}
					}
				}
				else
				{
					printf("未击中!");
					srand(time(0));
				}
			}
			dd1[1]--;
			dd1[2]--;
			dd1[3]--;
			dd1[4]--;
			srand(time(0));
		}
		else if(pt=="f")
		{
			srand(time(0));
			printf("副炮编号:");
			cin>>x;
			if(dd2[x]>0)
			{
				cout<<"装填未完成!!!"<<endl;
				srand(time(0));
			}
			else
			{
				int jjj=rand()%2;
				if(jjj==0)
				{
					dd2[x]=2;
					int kk=rand()%2;
					kk++;
					srand(time(0));
					printf("命中!");
					srand(time(0));
					if(kk==1)
					{
						int jj=rand()%2000;
						jj+=1500*3*abs(rand()%15+1);
						z1-=jj;
						if(pd(z1)==true)
						{
							cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"               WIN!"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
						}
					}
					else
					{
						z2-=(rand()%100+100)*2;
						if(pd(z2)==true)
						{
							cout<<"敌方僚舰被击沉!"<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"                                      -----------------"<<endl;
								cout<<"                                      |      WIN      |"<<endl;
								cout<<"                                      -----------------"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
						}
					}
				}
				else
				{
					printf("未击中!");
					srand(time(0));
				}
				for(int i=1; i<=15; i++)
				{
					dd2[i]--;
					srand(time(0));
				}
				srand(time(0));	
			}
				
		}
		else if(pt=="w")
		{
			printf("上");
			cout<<'\n';
			x1--;
		}
		else if(pt=="s")
		{
			printf("下");
			cout<<'\n';
			x1++;
		}
		else if(pt=="a")
		{
			printf("左");
			cout<<'\n';
			y1--;
		}
		else if(pt=="d")
		{
			printf("右");
			cout<<'\n';
			y1++;
		}
		else
		{
			cout<<"ERROR!"<<endl;
		}
		cout<<"地图:  z(你) f(辅助) 0(无舰艇) K/k(敌军)"<<endl;
		for(int i=1; i<=10; i++)
		{
			for(int j=1; j<=10; j++)
			{
				if(i==x1&&j==y1&&nl>0)
				{
					cout<<"z ";
				}
				else if(i==x2&&j==x2&&fz>0)
				{
					cout<<"f ";
				}
				else if(i==dx&&j==dy&&z2>0)
				{
					cout<<"k ";
				}
				else if(i==dx2&&j==dy2&&z1>0)
				{
					cout<<"K ";
				}
				else
				{
					cout<<"0 ";
				}
			}
			cout<<'\n';
		}
		nl+=10,fz+=10;
		fj(nl,fz);
		nl=xx1,fz=xx2;
		if(nl<=0||ssssss==0)
		{
			system("CLS");
			cout<<"                                      -----------------"<<endl;
			cout<<"                                      |   GAME OVER   |"<<endl;
			cout<<"                                      -----------------"<<endl;
			return 0;
		}
		if(fz<=0)
		{
			fz=0;
		}
		sleep(5);
		system("CLS");
		gz();
		printf("操作:");
		srand(time(0));
	}
	srand(time(0));
	return 0;
}

源码全部:

#include <bits/stdc++.h>
#include <windows.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
using namespace std;
short z[5],f[15];
short dd1[5],dd2[15];
short ma[10][10];
int xx1,xx2,ssssss=1,n=2;
void gz()
{
    cout<<" 1>>   主炮射击%5  命中率"<<endl<<" -   52500~62500伤害  z+Enter+主炮编号"<<endl<<" (4门   每门间隔2次操作换弹)"<<endl<<endl;
    cout<<" 2>>   副炮射击%50 命中率"<<endl<<" -1500~2500 伤害  f+Enter+副炮编号"<<endl<<" (15门  每门间隔1次操作换弹)"<<endl<<endl;
    cout<<" 3>>   [w][s][a][d]左右xy坐标移动"<<endl<<endl;
}
bool pd(int n)
{
    if(n<=0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
void fj(int a,int b)
{
    int jx;
    cout<<"敌方反击!"<<endl;
    for(int i=1; i<=n; i++)
    {
        sleep(1);
        cout<<endl<<"*"<<i<<endl;
        if(a<=3000&&b<=3000)
        {
            jx=rand()%2000+5000;
            if(pd(a)==true)
            {
                a=0,b=0;
                cout<<"旗舰:"<<a<<endl;
                cout<<"辅舰:"<<b<<endl;
                sleep(2);
                system("CLS");
                cout<<"                                      -----------------"<<endl;
                cout<<"                                      |     LOSE      |"<<endl;
                cout<<"                                      -----------------"<<endl;
                sleep(2);
                ssssss=0;
                return;
            }
            else
            {
                b-=jx;
                cout<<"旗舰:"<<a<<endl;
                cout<<"辅舰:"<<b<<endl;
                sleep(1);
            }
        }
        else
        {
            short sj=rand()%2;
            if(sj==1)
            {
                cout<<"主炮射击!%10";
                sleep(1);
                cout<<'\n';
                int jz=rand()%10;
                srand(time(0));
                if(jz==7)
                {
                    cout<<"--  未击中  --"<<endl;
                    cout<<"旗舰:"<<a<<endl;
                    cout<<"辅舰:"<<b<<endl;
                    sleep(1);
                    srand(time(0));    
                } 
                else
                {
                    
                    short jl=(rand()%6000+1000)*3*(rand()%5+1);
                    srand(time(0));
                    if(b-jl>=100)
                    {
                        b-=jl;
                    }
                    else
                    {
                        b=0;
                        a-=jl;
                    }
                    if(pd(a)==true)
                    {
                        a=0,b=0;
                        cout<<"旗舰:"<<a<<endl;
                        cout<<"辅舰:"<<b<<endl;
                        sleep(2);
                        system("CLS");
                        cout<<"                                      -----------------"<<endl;
                        cout<<"                                      |     LOSE      |"<<endl;
                        cout<<"                                      -----------------"<<endl;
                        sleep(2);
                        ssssss=0;
                        return;
                    }
                    else
                    {
                        cout<<"旗舰:"<<a<<endl;
                        cout<<"辅舰:"<<b<<endl;
                        sleep(1);
                    }
                }
            }
            else
            {
                cout<<"副炮射击!%100";
                sleep(1);
                cout<<'\n';
                int jl=(rand()%800+50)*(rand()%15+10);
                if(b-jl>=5000)
                {
                    b=b-jl;
                }
                else
                {
                    a=a-jl;
                }
                if(pd(a)==true)
                {
                    a=0,b=0;
                    cout<<"旗舰:"<<a<<endl;
                    cout<<"辅舰:"<<b<<endl;
                    sleep(2);
                    system("CLS");
                    cout<<"                                      -----------------"<<endl;
                    cout<<"                                      |     LOSE      |"<<endl;
                    cout<<"                                      -----------------"<<endl;
                    sleep(2);
                    ssssss=0;
                    return; 
                }
                else
                {
                    cout<<"旗舰:"<<a<<endl;
                    cout<<"辅舰:"<<b<<endl;
                    sleep(1);
                }    
            }
        }    
    }
    xx1=a,xx2=b;
}
int main()
{
    srand(time(0));
    int nl;
    memset(dd1,0,sizeof(dd1));
    memset(dd2,0,sizeof(dd2));
    memset(ma,0,sizeof(ma));
    printf("能量值:(50000~150000)");
    cin>>nl;
    while(nl<50000||nl>150000)
    {
        cout<<"Error!"<<endl;
        cin>>nl;
    }
    int z1=rand()%300000+5000,z2=rand()%150000+5000;
    z1+=50000,z2+=50000;
    z1=abs(z1),z2=abs(z2);
    string xz;
    int fz;
    printf("辅助舰艇能量: (50000~100000)");
    cin>>fz;
    cout<<"[1]敌方旗舰能量:"<<z1<<endl<<"[2]敌方僚舰能量:"<<z2<<endl;
    sleep(2);
    while(fz<50000||fz>100000)
    {
        cout<<"Error!"<<endl;
        cin>>fz;
    }
    system("CLS");
    cout<<"* * * * * * * * * * * * * * * * * * *正式战斗* * * * * * * * * * * * * * * * * * *"<<endl<<endl;
    string pt;
    int x1=rand()%5+1,y1=rand()%5+1;
    srand(time(0));
    int dx=rand()%5,dy=rand()%5;
    int dx2=dx+5,dy2=dy+5;
    int x2=x1+5,y2=y1+5;
    gz();
    printf("操作:");
    while(cin>>pt)
    {
        srand(time(0));
        int x;
        if(pt=="z")
        {
            printf("主炮编号:");
            cin>>x;
            if(dd1[x]>0)
            {
                cout<<"装填未完成!!!"<<endl;
            }
            else
            {
                dd1[x]=3;
                int sj1=rand();
                sj1%=20;
                if(sj1==3)
                {
                    int kk=rand()%2;
                    kk++;
                    srand(time(0));
                    printf("命中!");
                    if(kk==1)
                    {
                        int jj=rand()%10000*abs((rand()%3+1));
                        jj+=17500*3;//62500 52500
                        z1-=jj;
                        if(pd(z1)==true)
                        {
                            cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"               WIN!"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
                            srand(time(0));
                        }
                    }
                    else
                    {
                        int jj=rand()%1250;
                        jj*=3;
                        jj+=1750*3;
                        z1-=jj;
                        if(pd(z2)==true)
                        {
                            cout<<"敌方僚舰被击沉!"<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"               WIN!"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
                            srand(time(0));
                        }
                    }
                }
                else
                {
                    printf("未击中!");
                    srand(time(0));
                }
            }
            dd1[1]--;
            dd1[2]--;
            dd1[3]--;
            dd1[4]--;
            srand(time(0));
        }
        else if(pt=="f")
        {
            srand(time(0));
            printf("副炮编号:");
            cin>>x;
            if(dd2[x]>0)
            {
                cout<<"装填未完成!!!"<<endl;
                srand(time(0));
            }
            else
            {
                int jjj=rand()%2;
                if(jjj==0)
                {
                    dd2[x]=2;
                    int kk=rand()%2;
                    kk++;
                    srand(time(0));
                    printf("命中!");
                    srand(time(0));
                    if(kk==1)
                    {
                        int jj=rand()%2000;
                        jj+=1500*3*abs(rand()%15+1);
                        z1-=jj;
                        if(pd(z1)==true)
                        {
                            cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"               WIN!"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
                        }
                    }
                    else
                    {
                        z2-=(rand()%100+100)*2;
                        if(pd(z2)==true)
                        {
                            cout<<"敌方僚舰被击沉!"<<endl<<endl;
                            srand(time(0));
                            n--;
                            if(n==0)
                            {
                                system("CLS");
                                cout<<"                                      -----------------"<<endl;
                                cout<<"                                      |      WIN      |"<<endl;
                                cout<<"                                      -----------------"<<endl;
                                return 0;
                            }
                        }
                        else
                        {
                            cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
                        }
                    }
                }
                else
                {
                    printf("未击中!");
                    srand(time(0));
                }
                for(int i=1; i<=15; i++)
                {
                    dd2[i]--;
                    srand(time(0));
                }
                srand(time(0));    
            }
                
        }
        else if(pt=="w")
        {
            printf("上");
            cout<<'\n';
            x1--;
        }
        else if(pt=="s")
        {
            printf("下");
            cout<<'\n';
            x1++;
        }
        else if(pt=="a")
        {
            printf("左");
            cout<<'\n';
            y1--;
        }
        else if(pt=="d")
        {
            printf("右");
            cout<<'\n';
            y1++;
        }
        else
        {
            cout<<"ERROR!"<<endl;
        }
        cout<<"地图:  z(你) f(辅助) 0(无舰艇) K/k(敌军)"<<endl;
        for(int i=1; i<=10; i++)
        {
            for(int j=1; j<=10; j++)
            {
                if(i==x1&&j==y1&&nl>0)
                {
                    cout<<"z ";
                }
                else if(i==x2&&j==x2&&fz>0)
                {
                    cout<<"f ";
                }
                else if(i==dx&&j==dy&&z2>0)
                {
                    cout<<"k ";
                }
                else if(i==dx2&&j==dy2&&z1>0)
                {
                    cout<<"K ";
                }
                else
                {
                    cout<<"0 ";
                }
            }
            cout<<'\n';
        }
        nl+=10,fz+=10;
        fj(nl,fz);
        nl=xx1,fz=xx2;
        if(nl<=0||ssssss==0)
        {
            system("CLS");
            cout<<"                                      -----------------"<<endl;
            cout<<"                                      |   GAME OVER   |"<<endl;
            cout<<"                                      -----------------"<<endl;
            return 0;
        }
        if(fz<=0)
        {
            fz=0;
        }
        sleep(5);
        system("CLS");
        gz();
        printf("操作:");
        srand(time(0));
    }
    srand(time(0));
    return 0;
}

#include <bits/stdc++.h>
#include <windows.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
using namespace std;
short z[5],f[15];
short dd1[5],dd2[15];
short ma[10][10];
int xx1,xx2,ssssss=1,n=2;
void gz()
{
	cout<<" 1>>   主炮射击%5  命中率"<<endl<<" -   52500~62500伤害  z+Enter+主炮编号"<<endl<<" (4门   每门间隔2次操作换弹)"<<endl<<endl;
	cout<<" 2>>   副炮射击%50 命中率"<<endl<<" -1500~2500 伤害  f+Enter+副炮编号"<<endl<<" (15门  每门间隔1次操作换弹)"<<endl<<endl;
	cout<<" 3>>   [w][s][a][d]左右xy坐标移动"<<endl<<endl;
}
bool pd(int n)
{
	if(n<=0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
void fj(int a,int b)
{
	int jx;
	cout<<"敌方反击!"<<endl;
	for(int i=1; i<=n; i++)
	{
		sleep(1);
		cout<<endl<<"*"<<i<<endl;
		if(a<=3000&&b<=3000)
		{
			jx=rand()%2000+5000;
			if(pd(a)==true)
			{
				a=0,b=0;
				cout<<"旗舰:"<<a<<endl;
				cout<<"辅舰:"<<b<<endl;
				sleep(2);
				system("CLS");
				cout<<"                                      -----------------"<<endl;
				cout<<"                                      |     LOSE      |"<<endl;
				cout<<"                                      -----------------"<<endl;
				sleep(2);
				ssssss=0;
				return;
			}
			else
			{
				b-=jx;
				cout<<"旗舰:"<<a<<endl;
				cout<<"辅舰:"<<b<<endl;
				sleep(1);
			}
		}
		else
		{
			short sj=rand()%2;
			if(sj==1)
			{
				cout<<"主炮射击!%10";
				sleep(1);
				cout<<'\n';
				int jz=rand()%10;
				srand(time(0));
				if(jz==7)
				{
					cout<<"--  未击中  --"<<endl;
					cout<<"旗舰:"<<a<<endl;
					cout<<"辅舰:"<<b<<endl;
					sleep(1);
					srand(time(0));	
				} 
				else
				{
					
					short jl=(rand()%6000+1000)*3*(rand()%5+1);
					srand(time(0));
					if(b-jl>=100)
					{
						b-=jl;
					}
					else
					{
						b=0;
						a-=jl;
					}
					if(pd(a)==true)
					{
						a=0,b=0;
						cout<<"旗舰:"<<a<<endl;
						cout<<"辅舰:"<<b<<endl;
						sleep(2);
						system("CLS");
						cout<<"                                      -----------------"<<endl;
						cout<<"                                      |     LOSE      |"<<endl;
						cout<<"                                      -----------------"<<endl;
						sleep(2);
						ssssss=0;
						return;
					}
					else
					{
						cout<<"旗舰:"<<a<<endl;
						cout<<"辅舰:"<<b<<endl;
						sleep(1);
					}
				}
			}
			else
			{
				cout<<"副炮射击!%100";
				sleep(1);
				cout<<'\n';
				int jl=(rand()%800+50)*(rand()%15+10);
				if(b-jl>=5000)
				{
					b=b-jl;
				}
				else
				{
					a=a-jl;
				}
				if(pd(a)==true)
				{
					a=0,b=0;
					cout<<"旗舰:"<<a<<endl;
					cout<<"辅舰:"<<b<<endl;
					sleep(2);
					system("CLS");
					cout<<"                                      -----------------"<<endl;
					cout<<"                                      |     LOSE      |"<<endl;
					cout<<"                                      -----------------"<<endl;
					sleep(2);
					ssssss=0;
					return; 
				}
				else
				{
					cout<<"旗舰:"<<a<<endl;
					cout<<"辅舰:"<<b<<endl;
					sleep(1);
				}	
			}
		}	
	}
	xx1=a,xx2=b;
}
int main()
{
	srand(time(0));
	int nl;
	memset(dd1,0,sizeof(dd1));
	memset(dd2,0,sizeof(dd2));
	memset(ma,0,sizeof(ma));
	printf("能量值:(50000~150000)");
	cin>>nl;
	while(nl<50000||nl>150000)
	{
		cout<<"Error!"<<endl;
		cin>>nl;
	}
	int z1=rand()%300000+5000,z2=rand()%150000+5000;
	z1+=50000,z2+=50000;
	z1=abs(z1),z2=abs(z2);
	string xz;
	int fz;
	printf("辅助舰艇能量: (50000~100000)");
	cin>>fz;
	cout<<"[1]敌方旗舰能量:"<<z1<<endl<<"[2]敌方僚舰能量:"<<z2<<endl;
	sleep(2);
	while(fz<50000||fz>100000)
	{
		cout<<"Error!"<<endl;
		cin>>fz;
	}
	system("CLS");
	cout<<"* * * * * * * * * * * * * * * * * * *正式战斗* * * * * * * * * * * * * * * * * * *"<<endl<<endl;
	string pt;
	int x1=rand()%5+1,y1=rand()%5+1;
	srand(time(0));
	int dx=rand()%5,dy=rand()%5;
	int dx2=dx+5,dy2=dy+5;
	int x2=x1+5,y2=y1+5;
	gz();
	printf("操作:");
	while(cin>>pt)
	{
		srand(time(0));
		int x;
		if(pt=="z")
		{
			printf("主炮编号:");
			cin>>x;
			if(dd1[x]>0)
			{
				cout<<"装填未完成!!!"<<endl;
			}
			else
			{
				dd1[x]=3;
				int sj1=rand();
				sj1%=20;
				if(sj1==3)
				{
					int kk=rand()%2;
					kk++;
					srand(time(0));
					printf("命中!");
					if(kk==1)
					{
						int jj=rand()%10000*abs((rand()%3+1));
						jj+=17500*3;//62500 52500
						z1-=jj;
						if(pd(z1)==true)
						{
							cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"               WIN!"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
							srand(time(0));
						}
					}
					else
					{
						int jj=rand()%1250;
						jj*=3;
						jj+=1750*3;
						z1-=jj;
						if(pd(z2)==true)
						{
							cout<<"敌方僚舰被击沉!"<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"               WIN!"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
							srand(time(0));
						}
					}
				}
				else
				{
					printf("未击中!");
					srand(time(0));
				}
			}
			dd1[1]--;
			dd1[2]--;
			dd1[3]--;
			dd1[4]--;
			srand(time(0));
		}
		else if(pt=="f")
		{
			srand(time(0));
			printf("副炮编号:");
			cin>>x;
			if(dd2[x]>0)
			{
				cout<<"装填未完成!!!"<<endl;
				srand(time(0));
			}
			else
			{
				int jjj=rand()%2;
				if(jjj==0)
				{
					dd2[x]=2;
					int kk=rand()%2;
					kk++;
					srand(time(0));
					printf("命中!");
					srand(time(0));
					if(kk==1)
					{
						int jj=rand()%2000;
						jj+=1500*3*abs(rand()%15+1);
						z1-=jj;
						if(pd(z1)==true)
						{
							cout<<"敌方旗舰被击沉!"<<endl<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"               WIN!"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方旗舰现有能量:"<<z1<<endl<<endl;
						}
					}
					else
					{
						z2-=(rand()%100+100)*2;
						if(pd(z2)==true)
						{
							cout<<"敌方僚舰被击沉!"<<endl<<endl;
							srand(time(0));
							n--;
							if(n==0)
							{
								system("CLS");
								cout<<"                                      -----------------"<<endl;
								cout<<"                                      |      WIN      |"<<endl;
								cout<<"                                      -----------------"<<endl;
								return 0;
							}
						}
						else
						{
							cout<<"敌方僚舰现有能量:"<<z2<<endl<<endl;
						}
					}
				}
				else
				{
					printf("未击中!");
					srand(time(0));
				}
				for(int i=1; i<=15; i++)
				{
					dd2[i]--;
					srand(time(0));
				}
				srand(time(0));	
			}
				
		}
		else if(pt=="w")
		{
			printf("上");
			cout<<'\n';
			x1--;
		}
		else if(pt=="s")
		{
			printf("下");
			cout<<'\n';
			x1++;
		}
		else if(pt=="a")
		{
			printf("左");
			cout<<'\n';
			y1--;
		}
		else if(pt=="d")
		{
			printf("右");
			cout<<'\n';
			y1++;
		}
		else
		{
			cout<<"ERROR!"<<endl;
		}
		cout<<"地图:  z(你) f(辅助) 0(无舰艇) K/k(敌军)"<<endl;
		for(int i=1; i<=10; i++)
		{
			for(int j=1; j<=10; j++)
			{
				if(i==x1&&j==y1&&nl>0)
				{
					cout<<"z ";
				}
				else if(i==x2&&j==x2&&fz>0)
				{
					cout<<"f ";
				}
				else if(i==dx&&j==dy&&z2>0)
				{
					cout<<"k ";
				}
				else if(i==dx2&&j==dy2&&z1>0)
				{
					cout<<"K ";
				}
				else
				{
					cout<<"0 ";
				}
			}
			cout<<'\n';
		}
		nl+=10,fz+=10;
		fj(nl,fz);
		nl=xx1,fz=xx2;
		if(nl<=0||ssssss==0)
		{
			system("CLS");
			cout<<"                                      -----------------"<<endl;
			cout<<"                                      |   GAME OVER   |"<<endl;
			cout<<"                                      -----------------"<<endl;
			return 0;
		}
		if(fz<=0)
		{
			fz=0;
		}
		sleep(5);
		system("CLS");
		gz();
		printf("操作:");
		srand(time(0));
	}
	srand(time(0));
	return 0;
}

顺便问一句,想要升级版吗? 

猜:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值