here's the complete code so you guys don't have to wonder what i have in it anymore
main.cpp
Code:
#include <iostream>
#include <windows.h>
#include <string.h>
#include "Hangman.h"
using namespace std;
int main()
{
cout<<"|-| /-\\ |\\| G |\\/| /-\\ |\\|"<<endl;
hang.LoopProgram();
return 0;
}
hangman.cpp
Code:
#include <iostream.h>
#include <string.h>
#include <windows.h>
#include "Hangman.h"
struct hangman hang;
//Hangman Constructor
hangman::hangman()
{
hang.loopvar=true;
hang.PickWord();
hang.length=strlen(hang.word);
hang.spaces = new char[ hang.length ];
for(short x=0; x<hang.length; x++)
{
spaces[x]='_';
}
}
//Hangman Destructor
hangman::~hangman()
{
delete[] spaces;
}
//Function that loops the program until told to stop
void hangman::LoopProgram()
{
while(hang.loopvar!=false)
{
hang.BlankSpaces();
hang.Guess();
hang.Check();
}
}
//Function that picks a random word
void hangman::PickWord()
{
srand(GetTickCount());
short random=rand()%15;
switch(random)
{
case 0:
strcpy(hang.word, "corndog");
break;
case 1:
strcpy(hang.word, "computer");
break;
case 2:
strcpy(hang.word, "telephone");
break;
case 3:
strcpy(hang.word, "electric");
break;
case 4:
strcpy(hang.word, "stereo");
break;
case 5:
strcpy(hang.word, "oreo");
break;
case 6:
strcpy(hang.word, "microphone");
break;
case 7:
strcpy(hang.word, "cat");
break;
case 8:
strcpy(hang.word, "moose");
break;
case 9:
strcpy(hang.word, "internet");
break;
case 10:
strcpy(hang.word, "cow");
break;
case 11:
strcpy(hang.word, "potato");
break;
case 12:
strcpy(hang.word, "card");
break;
case 13:
strcpy(hang.word, "oven");
break;
case 14:
strcpy(hang.word, "speakers");
break;
default:
strcpy(hang.word, "earthquake");
}
}
//Function that draws all of the spaces
void hangman::BlankSpaces()
{
for(short x=0; x<hang.length; x++)
{
system("cls");
cout<<spaces[x]<<" ";
}
}
//Function that gets the user's guess
void hangman::Guess()
{
cout<<endl<<"What's your guess?: ";
cin>>hang.letter;
}
//Function that checks to see if the letter is in the word, if the word is complete, or the... man is hanged
//or however you want to put it. Also adds another number to the NumGuesses variable.
void hangman::Check()
{
//Check to see if letter guess is in word
for(short x=0;x<hang.length;x++)
{
if(hang.word[x]==hang.letter)
{
hang.spaces[x]=hang.letter;
}
}
//Check to see if the word is complete
if(strcmp(hang.spaces,hang.word)==0)
{
MessageBox(NULL, "You Won!", hang.word, MB_OK);
hang.loopvar=false;
}
}
hangman.h
Code:
extern struct hangman
{
bool loopvar;
char word[10];
int length;
char letter;
char* spaces;
hangman();
~hangman();
void LoopProgram();
void PickWord();
void BlankSpaces();
void Guess();
void Check();
}hang;
Hope this helps... oh wait, I'm the one who needs help here. NM...