运行下面代码后,为什么报“[Error] a function-definition is not allowed here before '{' token”和“[Error] expected '}' at end of input”这两个错?
#include<iterator>
#include<iostream>
#include<algorithm>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<windows.h>
#include<fstream>
#include<iomanip>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
using namespace std;
struct a{
string mz;
int ph;
}wj;
struct b{
int ph;
int fx;
}zj;
struct c{
int a1;
int a2;
int a3;
int a4;
int a5;
}bb;
string s1="1.进入赌局,2.进入商店,3.查看背包,4.退出游戏\n";
int kd=0,sd=0,zd=2;
int hh,whh,thh,rw,rw2,rw3,bj,rw4,rw5,rw6;
long long jb=1000;
int wsk(){
whh+1;
return 0;
}
int tsk(){
thh+1;
return 0;
}
int whz(){
wj.ph+1;
return 0;
}
int thz(){
zj.ph+1;
return 0;
}
int lb(){
if(zd==0){
sd-1;
zd=random(1);
return 0;
}else if(zd==1){
kd-1;
zd=random(1);
return 0;
}
}
int xd(){
bj=1;
return 0;
}
int fdj(){
cout<<"当前子弹是: ";
if(zd==0){
cout<<"实弹";
return 0;
}else if(zd==1){
cout<<"空弹";
return 0;
}
}
int abb(){
if(hh%2==0){
thh+=1;
return 0;
}else if(hh%2==1){
whh+=1;
return 0;
}
}
int sydj(){
for(;;){
cout<<"使用什么道具?\n0.退出\n1.手铐\n2.华子\n3.小刀\n4.放大镜\n5.雷碧";
cin>>rw6;
switch(rw6){
case 0:
cout<<"确定要退出?\n";
cout<<"1.是\n"<<"2.否\n";
cin>>rw3;
sleep(1);
system("cls");
if(rw3==1){
cout<<"感谢您的使用\n";
system("pause");
return 0;
break;
}else if(rw3==2){
cout<<"继续使用道具!\n";
system("pause");
system("cls");
}
break;
case 1:
if(bb.a1!=0){
cout<<"使用成功!!!";
wsk();
bb.a1=bb.a1-1;
system("pause");
system("cls");
}else{
cout<<"背包里该道具的数量为0!!!";
system("pause");
system("cls");
}
break;
case 2:
if(bb.a2!=0){
cout<<"使用成功!!!";
whz();
bb.a2=bb.a2-1;
system("pause");
system("cls");
}else{
cout<<"背包里该道具的数量为0!!!";
system("pause");
system("cls");
}
break;
case 3:
if(bb.a3!=0){
cout<<"使用成功!!!";
xd();
bb.a3=bb.a3-1;
system("pause");
system("cls");
}else{
cout<<"背包里该道具的数量为0!!!";
system("pause");
system("cls");
}
break;
case 4:
if(bb.a4!=0){
cout<<"使用成功!!!";
fdj();
bb.a4=bb.a4-1;
system("pause");
system("cls");
}else{
cout<<"背包里该道具的数量为0!!!";
system("pause");
system("cls");
}
break;
case 5:
if(bb.a5!=0){
cout<<"使用成功!!!";
lb();
bb.a5=bb.a5-1;
system("pause");
system("cls");
}else{
cout<<"背包里该道具的数量为0!!!";
system("pause");
system("cls");
}
break;
default:
cout<<"无效的符号!\n";
system("pause");
system("cls");
}
}
}
int dj1(){
srand(time(0));
cout<<"欢迎您来玩'赌枪'这款游戏,请您输入您的名字\n";
cin>>wj.mz;
sleep(1);
system("cls");
sd=rand()%10+1;
if(sd==0){
sd=sd+1;
}
kd=rand()%10+1;
if(kd==0){
kd=kd+1;
}
wj.ph=2;
zj.ph=2;
hh=1;
while(wj.ph!=0&&zj.ph!=0){
abb();
if(whh!=0){
cout<<"你的回合\n";
sleep(1);
system("cls");
zd=rand()%2;
cout<<"向谁开枪?\n1.'他'\n2.自己\n";
cin>>rw2;
sleep(1);
system("cls");
if(rw2==1){
if(zd==0&&sd!=0){
cout<<"实弹!!!!!!PH值-1!!!!!!!!!!!";
sleep(1);
system("cls");
zj.ph=zj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"唉,是空弹";
sleep(1);
system("cls");
kd=kd-1;
}
}else if(rw==2){
if(zd==0&&sd!=0){
cout<<"呜呜呜......是实弹......PH值-1......";
sleep(1);
system("cls");
wj.ph=wj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"是空弹!!!!!!!!!!!!!";
sleep(1);
system("cls");
kd=kd-1;
whh=whh+1;
}
}
whh=whh-1;
}else if(thh!=0){
cout<<"'他'的回合\n";
sleep(1);
system("cls");
zd=rand()%2;
zj.fx=rand()%2;
if(zj.fx==0){
cout<<"'他'要向你开枪!!!!!!";
if(zd==0&&sd!=0){
cout<<"呜呜呜......是实弹......PH值-1......";
sleep(1);
system("cls");
wj.ph=wj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"是空弹!!!!!!!!!!!!!";
sleep(1);
system("cls");
kd=kd-1;
}
}else if(zj.fx==1){
cout<<"'他'要向自己开枪";
if(zd==0&&sd!=0){
cout<<"实弹!!!!!!PH值-1!!!!!!!!!!!";
sleep(1);
system("cls");
zj.ph=zj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"唉,是空弹";
sleep(1);
system("cls");
kd=kd-1;
}
}
thh=thh-1;
}
hh=hh+1;
if(sd==0){
sd=rand()%10;
}else if(kd==0){
kd=rand()%10;
}
}
if(zj.ph==0){
cout<<" "<<wj.mz<<" "<<"赢了!!!!!!";
jb=5000;
sleep(1);
system("cls");
}else if(wj.ph==0){
cout<<"'他'赢了";
sleep(1);
system("cls");
}
return 0;
}
int dj2(){
srand(time(0));
sd=rand()%10+1;
if(sd==0){
sd=sd+1;
}
kd=rand()%10+1;
if(kd==0){
kd=kd+1;
}
wj.ph=2;
zj.ph=2;
hh=1;
while(wj.ph!=0&&zj.ph!=0){
abb();
if(whh!=0){
cout<<"你的回合\n";
sleep(1);
system("cls");
zd=rand()%2;
cout<<"向谁开枪?\n1.'他'\n2.自己\n";
cin>>rw2;
sleep(1);
system("cls");
if(rw2==1){
if(zd==0&&sd!=0){
cout<<"实弹!!!!!!PH值-1!!!!!!!!!!!";
sleep(1);
system("cls");
zj.ph=zj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"唉,是空弹";
sleep(1);
system("cls");
kd=kd-1;
}
}else if(rw==2){
if(zd==0&&sd!=0){
cout<<"呜呜呜......是实弹......PH值-1......";
sleep(1);
system("cls");
wj.ph=wj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"是空弹!!!!!!!!!!!!!";
sleep(1);
system("cls");
kd=kd-1;
whh=whh+1;
}
}
whh=whh-1;
}else if(thh!=0){
cout<<"'他'的回合\n";
sleep(1);
system("cls");
zd=rand()%2;
zj.fx=rand()%2;
if(zj.fx==0){
cout<<"'他'要向你开枪!!!!!!";
if(zd==0&&sd!=0){
cout<<"呜呜呜......是实弹......PH值-1......";
sleep(1);
system("cls");
wj.ph=wj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"是空弹!!!!!!!!!!!!!";
sleep(1);
system("cls");
kd=kd-1;
}
}else if(zj.fx==1){
cout<<"'他'要向自己开枪";
if(zd==0&&sd!=0){
cout<<"实弹!!!!!!PH值-1!!!!!!!!!!!";
sleep(1);
system("cls");
zj.ph=zj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"唉,是空弹";
sleep(1);
system("cls");
kd=kd-1;
}
}
thh=thh-1;
}
hh=hh+1;
if(sd==0){
sd=rand()%10;
}else if(kd==0){
kd=rand()%10;
}
}
if(zj.ph==0){
cout<<" "<<wj.mz<<" "<<"赢了!!!!!!";
jb=jb+1000;
sleep(1);
system("cls");
}else if(wj.ph==0){
cout<<"'他'赢了";
sleep(1);
system("cls");
}
return 0;
}
int sc(){
for(;;){
cout<<"+==============+\n";
cout<<"| 1.手铐 |\n";
cout<<"| 5000金币 |\n";
cout<<"+==============+\n";
cout<<"| 2.华子 |\n";
cout<<"| 2600金币 |\n";
cout<<"+==============+\n";
cout<<"| 3.小刀 |\n";
cout<<"| 9000金币 |\n";
cout<<"+==============+\n";
cout<<"| 4.放大镜 |\n";
cout<<"| 100000金币 |\n";
cout<<"+==============+\n";
cout<<"| 5.雷碧 |\n";
cout<<"| 200000金币 |\n";
cout<<"+==============+\n";
cout<<"( 0.退出 )\n";
cin>>rw4;
sleep(1);
system("cls");
switch(rw4){
case 0:
cout<<"确定要退出?\n";
cout<<"1.是\n"<<"2.否\n";
cin>>rw3;
sleep(1);
system("cls");
if(rw3==1){
cout<<"感谢您的使用\n";
system("pause");
return 0;
break;
}else if(rw3==2){
cout<<"继续购买!\n";
system("pause");
system("cls");
}
break;
case 1:
if(jb>=5000){
cout<<"购买成功!!!";
sleep(1);
system("cls");
bb.a1=bb.a1+1;
}else{
cout<<"钱不够!!!";
sleep(1);
system("cls");
}
break;
case 2:
if(jb>=2600){
cout<<"购买成功!!!";
sleep(1);
system("cls");
bb.a2=bb.a2+1;
}else{
cout<<"钱不够!!!";
sleep(1);
system("cls");
}
break;
case 3:
if(jb>=9000){
cout<<"购买成功!!!";
sleep(1);
system("cls");
bb.a3=bb.a3+1;
}else{
cout<<"钱不够!!!";
sleep(1);
system("cls");
}
break;
case 4:
if(jb>=100000){
cout<<"购买成功!!!";
sleep(1);
system("cls");
bb.a4=bb.a4+1;
}else{
cout<<"钱不够!!!";
sleep(1);
system("cls");
}
break;
case 5:
if(jb>=200000){
cout<<"购买成功!!!";
sleep(1);
system("cls");
bb.a5=bb.a5+1;
}else{
cout<<"钱不够!!!";
sleep(1);
system("cls");
}
break;
default:
cout<<"无效的符号!\n";
system("pause");
system("cls");
}
}
}
int dj3(){
srand(time(0));
sd=rand()%10+1;
if(sd==0){
sd=sd+1;
}
kd=rand()%10+1;
if(kd==0){
kd=kd+1;
}
wj.ph=2;
zj.ph=2;
hh=1;
while(wj.ph!=0&&zj.ph!=0){
abb();
if(whh!=0){
cout<<"你的回合\n";
sleep(1);
system("cls");
zd=rand()%2;
cout<<"干什么?\n1.使用道具\n2.开枪";
cin>>rw5;
sleep(1);
system("cls");
if(rw5==1){
sydj();
if(rw5==2){
cout<<"向谁开枪?\n1.'他'\n2.自己\n";
cin>>rw2;
sleep(1);
system("cls");
if(rw2==1){
if(zd==0&&sd!=0){
cout<<"实弹!!!!!!PH值-1!!!!!!!!!!!";
sleep(1);
system("cls");
zj.ph=zj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"唉,是空弹";
sleep(1);
system("cls");
kd=kd-1;
}
}else if(rw==2){
if(zd==0&&sd!=0){
cout<<"呜呜呜......是实弹......PH值-1......";
sleep(1);
system("cls");
wj.ph=wj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"是空弹!!!!!!!!!!!!!";
sleep(1);
system("cls");
kd=kd-1;
whh=whh+1;
}
}
whh=whh-1;
}
}else if(thh!=0){
cout<<"'他'的回合\n";
sleep(1);
system("cls");
zd=rand()%2;
zj.fx=rand()%2;
if(zj.fx==0){
cout<<"'他'要向你开枪!!!!!!";
if(zd==0&&sd!=0){
cout<<"呜呜呜......是实弹......PH值-1......";
sleep(1);
system("cls");
wj.ph=wj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"是空弹!!!!!!!!!!!!!";
sleep(1);
system("cls");
kd=kd-1;
}
}else if(zj.fx==1){
cout<<"'他'要向自己开枪";
if(zd==0&&sd!=0){
cout<<"实弹!!!!!!PH值-1!!!!!!!!!!!";
sleep(1);
system("cls");
zj.ph=zj.ph-1;
sd=sd-1;
}else if(zd==1&&kd!=0){
cout<<"唉,是空弹";
sleep(1);
system("cls");
kd=kd-1;
}
}
thh=thh-1;
}
hh=hh+1;
if(sd==0){
sd=rand()%10;
}else if(kd==0){
kd=rand()%10;
}
}
if(zj.ph==0){
cout<<" "<<wj.mz<<" "<<"赢了!!!!!!";
jb=jb+1000;
sleep(1);
system("cls");
}else if(wj.ph==0){
cout<<"'他'赢了";
sleep(1);
system("cls");
}
return 0;
}
int main(){
dj1();
for(;;){
for(int i=0;i<=s1.length();i++){
cout<<s1[i];
}
cin>>rw;
sleep(1);
system("cls");
switch(rw){
case 1:
dj2();
break;
case 2:
sc();
case 4:
cout<<"确定要退出?\n";
cout<<"1.是\n"<<"2.否\n";
cin>>rw3;
sleep(1);
system("cls");
if(rw3==1){
cout<<"感谢您的使用\n";
system("pause");
return 0;
break;
}else if(rw3==2){
cout<<"继续赌!\n";
system("pause");
system("cls");
}
break;
default:
cout<<"无效的符号!\n";
system("pause");
system("cls");
}
}
return 0;
}