单词接龙(双人)
_Los
·
·
个人记录
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
struct Word{
string word,meaning;
bool used;
}w[10000];
string ans;
char last,foo;
int tot,r=1,sump1,sump2;
bool is_first=1,who=1;
void read();
void game();
int main(){
srand((unsigned)time(NULL));
read();
cout<<"*-----------------------------------------------*"<<endl;
cout<<"|Welcome to play the Word Solitaire!(By _Los) |"<<endl;
cout<<"|Make sure that you're using the Windows System!|"<<endl;
cout<<"|Tips:You can give up by inputing 'GIVEUP'! |"<<endl;
cout<<"| All the words in this game are lower case!|"<<endl;
cout<<"| You're playing the DOUBLE MODE! |"<<endl;
cout<<"*-----------------------------------------------*"<<endl;
cout<<"Press any key to continue..."<<endl;
foo=_getch();
game();
return 0;
}
void read(){
ifstream fin;
string buf;
bool flag=0;
fin.open("data.txt");fin>>buf;
while(buf!="@"){
w[tot].used=0;
for(int i=0;i<buf.length();i++){
if(buf[i]=='#'){
flag=!flag;
continue;
}
if(!flag)w[tot].word+=buf[i];
if(flag)w[tot].meaning+=buf[i];
}
tot++;
flag=0;
fin>>buf;
}
fin.close();
}
void game(){
string k1,k2;
bool e=1;
system("cls");
if(is_first)ans+=char('a'+rand()%26);
is_first=0;
cout<<"Round:"<<r<<endl;
cout<<"The score of Player1:"<<sump1<<endl;
cout<<"The score of Player2:"<<sump2<<endl;
if(!is_first)cout<<"The 'Dragon':"<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<ans<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"Now,it's Player1's turn:";
while(e){
cin>>k1;
if(k1=="GIVEUP"){
ofstream fout;
fout.open("ans(double).txt");
fout<<"Player1 gave up in Round "<<r<<".That's a pity!"<<endl;
cout<<"The score of Player1:"<<sump1<<endl;
cout<<"The score of Player2:"<<sump2<<endl<<ans<<endl;
fout.close();
system("cls");
cout<<"See you~~~"<<endl;
return;
}
for(int i=0;i<tot;i++)
if(w[i].word==k1 && !w[i].used && ans[ans.length()-1]==k1[0] ){
cout<<"Good!"<<endl;
cout<<"---------------Meaning--------------"<<endl<<w[i].meaning<<endl<<"------------------------------------"<<endl;
ans+="->"+k1;
r++;
e=0;
w[i].used=1;
last=k1[k1.length()-1];
sump1+=k1.length();
break;
}
if(e==1)cout<<"Wrong spelling!Please input again:";
}
if(!is_first)cout<<"The 'Dragon':"<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<ans<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<"Now,it's Player2's turn:";
e=1;
while(e){
cin>>k2;
if(k2=="GIVEUP"){
ofstream fout;
fout.open("ans(double).txt");
fout<<"Player2 gave up in Round "<<r<<".That's a pity!"<<endl;
cout<<"The score of Player1:"<<sump1<<endl;
cout<<"The score of Player2:"<<sump2<<endl<<ans<<endl;
fout.close();
system("cls");
cout<<"See you~~~"<<endl;
return;
}
for(int i=0;i<tot;i++)
if(w[i].word==k2 && !w[i].used && ans[ans.length()-1]==k2[0] ){
cout<<"Good!"<<endl;
cout<<"---------------Meaning--------------"<<endl<<w[i].meaning<<endl<<"------------------------------------"<<endl;
ans+="->"+k2;
r++;
e=0;
w[i].used=1;
last=k2[k2.length()-1];
sump2+=k2.length();
break;
}
if(e==1)cout<<"Wrong spelling!Please input again:";
}
cout<<"Press any key to continue another round..."<<endl;
foo=_getch();
game();
}
注意事项:同2.
上一篇:单词接龙(单人)
下一篇:简单的名字竞技场