#include<iostream> //Standard input/output
#include<string> //String manipulation
#include<cctype> //Character manipulation and testing
#include<fstream> //File stream
#include<cstdlib> //Used for random function
#include<time.h> //Used for better random number
#include"draw.h" //run the draw.h file
using namespace std;
//Function declerations
void instruction(int& choice); //Give instructions and gets choice
void usergame(int i); /瞎孙散/Plays 2nd user game
void compgame(int i); //Plays against computer
//Tests current letter and raplaces starred word
void test(string word,char letter,int& numwrong,string& temp,int i);
//Checks current letter and adds it to letters chosen output if not entered already
void lchosen(char letter,string& letterchosen,int& check,int& chosencounter,int i);
void rnd(string& word,int i); //Gets random word from file
void drawman(int numguess,int numwrong,int i); //Draws hangman
inline istream& Flush(istream& stream); //Flushses cin stream
//Start of main
int main()
{
int i=0; /磨氏/Counter variable for loops
int exit=0; //Main loop exit variable
int choice; //users input choice for type of game or to exit
//Main control loop
do{ //while exit!=1
system("cls"); //执行系统命令清屏
instruction(choice);//Give instructions
switch(choice)
{
case 1:
usergame(i);//Calls user game
break;
case 2:
compgame(i);//Calls computer game
break;
case 3:
cout<<"Goodbye"<<endl;
exit=1;
break;
default:
cerr<<"Invalid choice---try again"<<endl;
}
}while(exit!=1);
//End main loop
system("pause"); //执行系统命令:暂停
return 0;
}
//End main
void instruction(int& choice)
{
cout<<"凯厅 --Hangman--"<<endl<<endl;
cout<<" Created by laser"<<endl<<endl;
cout<<"*************************************************"<<endl;
cout<<endl;
cout<<"Enter --1--to play against user"<<endl;
cout<<"Enter --2--to play against computer"<<endl;
cout<<"Enter --3--to quit"<<endl;
cout<<endl;
cout<<"*************************************************"<<endl<<endl;
cout<<"Choice: ";
cin&
c++小游戏
于 2024-08-22 17:53:04 首次发布