吊死鬼
bellmenford · · 个人记录
#include<windows.h>
#include<iostream>
#include<conio.h>
#include<string>
#include<cstdio>
#include<time.h>
using namespace std;
int hp=9,len,fz[6]={10,10,12,5,5,3};
bool vis[105];
char words[105],wrong[105];
char words2[105][2]={{'m','y'},{'i','n'},{'o','n'},{'a','t'},{'b','y'},{'t','o'},{'h','i'},{'h','e'},{'i','s'},{'b','e'}};
char words3[105][3]={{'t','e','a'},{'s','e','a'},{'s','e','e'},{'b','y','e'},{'e','a','t'},{'l','i','e'},{'s','h','e'},{'b','i','g'},{'d','o','g'},{'p','i','g'}};
char words4[105][4]={{'l','o','s','t'},{'h','u','r','t'},{'t','e','l','l'},{'c','a','l','l'},{'t','a','l','l'},{'t','a','i','l'},{'d','e','s','k'},{'b','a','l','l'},{'f','i','n','d'},{'f','o','o','l'},{'m','a','r','k'},{'i','r','o','n'}};
char words5[105][5]={{'w','r','o','n','g'},{'h','e','a','r','t'},{'t','o','u','c','h'},{'t','e','a','c','h'},{'f','o','u','n','d'}};
char words6[105][6]={{'a','n','s','w','e','r'},{'d','o','u','b','l','e'},{'s','e','a','r','c','h'},{'m','a','g','n','e','t'},{'s','h','o','w','e','r'}};
char words11[105][11]={{'c','o','m','m','u','n','i','c','a','t','e'},{'o','p','p','o','r','t','u','n','i','t','y'},{'h','y','p','o','t','h','e','r','m','i','a'}};
void draw(){
if(hp==9){
printf(
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
" \n"
"----------------------------------------- \n");
}
if(hp==8){
printf(
" \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==6){
printf(
" ------------------------ \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==6){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==5){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | —— \n"
" | / \\ \n"
" | [ ] \n"
" | \\ / \n"
" | ---- \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==4){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | —— \n"
" | / \\ \n"
" | [ ] \n"
" | \\ / \n"
" | ---- \n"
" | | \n"
" | | \n"
" | | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==3){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | —— \n"
" | / \\ \n"
" | [ ] \n"
" | \\ / \n"
" | ---- \n"
" | | \n"
" | ------| \n"
" | | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==2){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | —— \n"
" | / \\ \n"
" | [ ] \n"
" | \\ / \n"
" | ---- \n"
" | | \n"
" | ------|------ \n"
" | | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==1){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | —— \n"
" | / \\ \n"
" | [ ] \n"
" | \\ / \n"
" | ---- \n"
" | | \n"
" | ------|------ \n"
" | | \n"
" | / \n"
" | / \n"
" | / \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
if(hp==0){
printf(
" ------------------------ \n"
" | | \n"
" | | \n"
" | —— \n"
" | / \\ \n"
" | [ ] \n"
" | \\ / \n"
" | ---- \n"
" | | \n"
" | ------|------ \n"
" | | \n"
" | / \\ \n"
" | / \\ \n"
" | / \\ \n"
" | \n"
" | \n"
" | \n"
"----------------------------------------- \n");
}
}
int main(){
srand((unsigned int)(time(NULL)));
int a=rand()%6;
srand((unsigned int)(time(NULL)));
int b=rand()%fz[a];
if(a==0){
len=2;
for(int i=0;i<2;i++){
words[i]=words2[b][i];
}
}
if(a==1){
len=3;
for(int i=0;i<3;i++){
words[i]=words3[b][i];
}
}
if(a==2){
len=4;
for(int i=0;i<4;i++){
words[i]=words4[b][i];
}
}
if(a==3){
len=5;
for(int i=0;i<5;i++){
words[i]=words5[b][i];
}
}
if(a==4){
len=6;
for(int i=0;i<6;i++){
words[i]=words6[b][i];
}
}
if(a==5){
len=11;
for(int i=0;i<11;i++){
words[i]=words11[b][i];
}
}
for(int i=0;i<len;i++){
cout<<(vis[i]==1?words[i]:' ')<<" ";
}
cout<<endl;
for(int i=0;i<len;i++){
cout<<"_"<<" ";
}
cout<<endl<<"wrong answer:";
for(int i=1;i<=wrong[0];i++){
cout<<wrong[i]<<" ";
}
cout<<endl;
draw();
char ch;
while(ch=getch()){
bool flag=0,flag1=1,flag2=0;
for(int i=1;i<=wrong[0];i++){
if(ch==wrong[i]){
flag2=1;
break;
}
}
if(flag2==1){
continue;
}
for(int i=0;i<len;i++){
if(ch==words[i]){
vis[i]=1;
flag=1;
}
}
if(flag==0){
wrong[0]++;
wrong[wrong[0]]=ch;
hp--;
}
system("cls");
for(int i=0;i<len;i++){
cout<<(vis[i]==1?words[i]:' ')<<" ";
}
cout<<endl;
for(int i=0;i<len;i++){
cout<<"_"<<" ";
}
cout<<endl<<"wrong answer:";
for(int i=1;i<=wrong[0];i++){
cout<<wrong[i]<<" ";
}
cout<<endl;
draw();
for(int i=0;i<len;i++){
if(vis[i]==0){
flag1=0;
break;
}
}
if(flag1==1){
cout<<"win!"<<endl;
return 0;
}
if(hp==0){
cout<<"lost!"<<endl<<"The correct answer is ";
for(int i=0;i<len;i++){
cout<<words[i];
}
cout<<endl;
return 0;
}
}
}