Small Instance Hangman game

Source: Internet
Author: User

Code
#include <bits/stdc++.h>using namespace Std;int bk[110];string sj (int t) {string ans= "";    for (int i=0;i<t;i++) Ans=ans+char ((rand ()%26) + ' a '); return ans;}    Main () {Srand (time (0));    cout<< "Hangman game total of 6 times to guess the opportunity, you can choose the difficulty \ n";    cout<< "easy--5 letters consisting of words \nnormal--8 letters consisting of \nhard--12 letters consisting of a word \nlunatic--26 letters" \ n ";        while (1) {int sum;        cout<< "The difficulty you choose is \ n Please enter Easy,normal,hard or lunatic\n";        F1:string e;        cin>>e;        if (e== "easy") sum=5;        else if (e== "normal") sum=8;        else if (e== "hard") sum=12;        else if (e== "lunatic") sum=26; else {cout<< "you entered the illegal option please re-enter!!!"            \ n ";         Goto F1;        } string A=SJ (sum);        int num=6;        memset (bk,0,sizeof (BK));        cout<<a<<endl;    cout<< "Please enter a letter \ n";        while (1) {f2:string T;        cin>>t; if (T.size () >1) {Cout<< "Enter more than one letter, please re-enter \ n";        Goto F2;        } int f,ff;        f=1;        ff=0;            for (int i=0;i<a.size (); i++) if (A[i]==t[0]) {bk[i]++;            if (bk[i]==1) f=0;        else ff=1;        } int ac=1;            for (int i=0;i<a.size (); i++) if (bk[i]==0) {ac=0;        Break            if (AC) {cout<< "--------------------------------------------\ n"; cout<< "Congratulations on your complete guess!!!            You also have the remaining << "<<num<<" >> opportunity \ n ";            cout<< "The original word is \ n";                for (int i=0;i<a.size (); i++) {if (bk[i]!=0) cout<<a[i]<< "";            else cout<< "_";            } cout<<endl;            cout<< "--------------------------------------------\ n";          Break            } if (f) {num--; cout<< "--------------------------------------------\ n"; if (F&AMP;&AMP;!FF) cout<< "The letter you guessed did not appear in the original word!!!            \ n "; else if (FF) cout<< "you guessed the right letter you've guessed!!!             \ n ";            if (!num) {cout<< "--------------------------------------------\ n"; cout<< "You have failed!!! Hangman has been completed!!!            \ n ";            cout<< "The original word is \ n";            for (int i=0;i<a.size (); i++) cout<<a[i]<< "";            cout<<endl;            cout<< "What you finally guessed is \ n";                for (int i=0;i<a.size (); i++) {if (bk[i]!=0) cout<<a[i]<< "";            else cout<< "_";            } cout<< "\ n";            cout<< "--------------------------------------------\ n";        Break            } cout<< "The number of times left is <<" <<num<< ">> times \ n"; cout<< "--------------------------------------------\ n ";        cout<< "Please enter a letter \ n";            } else {cout<< "--------------------------------------------\ n";            cout<< "Congratulations you guessed the right letter, the word is \ n";                for (int i=0;i<a.size (); i++) {if (bk[i]!=0) cout<<a[i]<< "";            else cout<< "_";            } cout<<endl<<endl;            cout<< "--------------------------------------------\ n";        cout<< "Please enter a letter \ n"; }    }    }}

Small instance Hangman game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.