Console Based Hangman game

Aatif Ishtiaq

119-BSCS-2010
Section B

Introduction

This is a console based game I developed in 2nd semester. The core language is c++. In this game user enters a word and ask another user to guess that word, for every wrong alphabet, A man will start to appear, and if all the lives run out then, eventually that man will be hanged.

Background

This game is a traditional one, More like Ludo etc. Many develepors have spent hours on its concept. My aim ehilr developomg this game was to practice my c++ skills.

In the code:

It is implemented in structred base programming rather then OOP.
It contains following methods.


void show_word();
void guess_word();
void head();
void arms();
void tummy();
void leg1();
void leg2();
void hang();
void set_position();


void head()
{
cout<<"  , ,  ";gotoxy(wherex()-7,wherey()+1);
cout<<"( o o )";gotoxy(wherex()-7,wherey()+1);
cout<<"!  ^  !";
}

void arms()
{
for(int i=0;i<8;i++)
cout<<"_";
}

void tummy()
{
for(int i=0;i<3;i++)
{
cout<<"|";
gotoxy(wherex()-1,wherey()-1);
}
}

void leg1()
{
for(int i=0;i<5;i++)
{
cout<<"|";
gotoxy(wherex()-2,wherey()+1);
}
}

void leg2()
{
for(int i=0;i<5;i++)
{
cout<<"|";
gotoxy(wherex(),wherey()+1);
}
}

void hang()
{
cout<<"-------";gotoxy(wherex()-7,wherey());
for(int i=0;i<6;i++)
{
gotoxy(wherex()-1,wherey()-1);
cout<<"|";
}
}

  1. Enter a word.
    Capture
    Capture1
  2. Guess the word.
    Capture3
  3. In case you choose a wrong word.
    Capture4

Summary

When the user submits a word, it is saved into an array of chars. Then when user guesses the word, each word is compared with the already submited word. If all the alphabets are correct user wins otherwise user is hanged.

Comments are closed.