Skip to content

Instantly share code, notes, and snippets.

@AndrewS097
Created March 10, 2019 08:22
Show Gist options
  • Save AndrewS097/32e88b16dc98404775bc9bd821355591 to your computer and use it in GitHub Desktop.
Save AndrewS097/32e88b16dc98404775bc9bd821355591 to your computer and use it in GitHub Desktop.
Hang Man Game
#include <iostream>
using namespace std;
//declarations
char name [8] = {'_','_','_','_','_','_','_','_'};
char table [8];
char guess;
int mistake;
int x;
//function that shows table
void showtable3(){
for(int row=0; row < 3; row++ ){
cout << name [row] <<" ";}}
void showtable4(){
for(int row=0; row < 4; row++ ){
cout << name [row] <<" "; }}
void showtable5(){
for(int row=0; row < 5; row++ ){
cout << name [row] <<" ";}}
void showtable6(){
for(int row=0; row < 6; row++ ){
cout << name [row] <<" ";}}
void showtable7(){
for(int row=0; row < 7; row++ ){
cout << name [row] <<" ";}}
void showtable8(){
for(int row=0; row < 8; row++ ){
cout << name [row] <<" ";}}
//functions that accepts insputs for the word and sets the remaining unused values to 0
void picked3() {
if (x== 3) {
cout << "Please pick a word 3 letter word."<< endl;
cin >> table [0];
cin >> table [1];
cin >> table [2];
table [3] =0;
table [4] =0;
table [5] = 0;
table [6]= 0;
table [7]=0;
name [3]=0;
name [4]=0;
name [5]=0;
name [6]=0;
name [7]=0;
}
}
void picked4() {
if (x== 4) {
cout << "Please pick a word 4 letter word."<< endl;
cin >> table [0];
cin >> table [1];
cin >> table [2];
cin >> table [3];
table [4]=0;
table [5] = 0;
table [6]= 0;
table [7]=0;
name [4]=0;
name [5]=0;
name [6]=0;
name [7]=0;
}
}
void picked5() {
if (x== 5) {
cout << "Please pick a word 5 letter word."<< endl;
cin >> table [0];
cin >> table [1];
cin >> table [2];
cin >> table [3];
cin >> table [4];
table [5]=0;
table [6]= 0;
table [7]=0;
name [5]=0;
name [6]=0;
name [7]=0;
}
}
void picked6() {
if (x== 6) {
cout << "Please pick a word 6 letter word."<< endl;
cin >> table [0];
cin >> table [1];
cin >> table [2];
cin >> table [3];
cin >> table [4];
cin >> table [5];
table [6]=0;
table [7]=0;
name [6]=0;
name [7]=0;
}
}
void picked7() {
if (x== 7) {
cout << "Please pick a word 7 letter word."<< endl;
cin >> table [0];
cin >> table [1];
cin >> table [2];
cin >> table [3];
cin >> table [4];
cin >> table [5];
cin >>table [6];
table [7]=0;
name [7]=0;
}
}
void picked8() {
if (x== 8) {
cout << "Please pick a word 8 letter word."<< endl;
cin >> table [0];
cin >> table [1];
cin >> table [2];
cin >> table [3];
cin >> table [4];
cin >> table [5];
cin >>table [6];
cin >> table [7];
}
}
//the hanging man picture function
void mistakef(){
if (mistake==0)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
}
if (mistake==1)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | 0 |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
}
if (mistake ==2)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | 0 |"<<endl;
cout << " | | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
}
if (mistake ==3)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | 0 |"<<endl;
cout << " | /| |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
}
if (mistake ==4)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | 0 |"<<endl;
cout << " | /|\\ |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
}
if (mistake ==5)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | 0 |"<<endl;
cout << " | /|\\ |"<<endl;
cout << " | / |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
}
if (mistake ==6)
{
cout << " ________________________________________"<<endl;
cout << " | THE HANGING MAN |"<<endl;
cout << " |----------------------------------------|"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | | |"<<endl;
cout << " | 0 |"<<endl;
cout << " | /|\\ |"<<endl;
cout << " | / \\ |"<<endl;
cout << " | |"<<endl;
cout << " | |"<<endl;
cout << " ________________________________________ "<<endl;
cout << "You lose GG" << endl;
exit(0);
}
}
//tests whether or not the guess matches a letter
void pguess() { cout << "Guess a letter" <<endl;
cin >> guess;
int answer_correct = 0;
if (guess == table [0])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [0]=table [0];
answer_correct = 1;}
if (guess == table [1])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [1]=table [1];
answer_correct = 1;}
if (guess == table [2])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [2]=table [2];
answer_correct = 1;}
if (guess == table [3])
{
cout <<"You got a letter correct the guy lives another day" << endl;
name [3]=table [3];
answer_correct = 1;}
if (guess == table [4])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [4]=table [4];
answer_correct = 1;}
if (guess == table [5])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [5]=table [5];
answer_correct = 1;}
if (guess == table [6])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [6]=table [6];
answer_correct = 1;}
if (guess == table [7])
{
cout << "You got a letter correct the guy lives another day" << endl;
name [7]=table [7];
answer_correct = 1;}
else if (answer_correct ==0) { cout << "Your guess was wrong" << endl;
mistake += 1;
}
}
int main(){
int win = 0;
cout << "Please pick the amount of characters for your hangman game" << endl;
cin >> x;
if (x==3) {picked3();
}
if (x==4) {picked4();
}
if (x==5) {picked5();
}
if (x==6) {picked6();
}
if (x==7) {picked7();
}
if (x==8) {picked8();
}
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
cout << " " <<endl;
while (win == 0){
if (x==3) {showtable3();
}
if (x==4) {showtable4();
}
if (x==5) {showtable5();
}
if (x==6) {showtable6();
}
if (x==7) {showtable7();
}
if (x==8) {showtable8();
}
pguess();
mistakef();
if (table [0] == name [0]&& table [1] == name [1] && table [2] == name [2] && table [3] == name [3]&& table [4] == name [4] &&
table [5] == name[5] && table [6] == name [6] && table [7] == name[7])
{
cout << "You win good job my dude" << endl;
exit(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment