Presentation is loading. Please wait.

Presentation is loading. Please wait.

HANGMAN Created By: Will Matthau & Christian Stumpf.

Similar presentations


Presentation on theme: "HANGMAN Created By: Will Matthau & Christian Stumpf."— Presentation transcript:

1 HANGMAN Created By: Will Matthau & Christian Stumpf

2 Overall Design Introduce the game menu Prompts user for a difficulty level from 1 – 5 User selects difficulty level Difficulty level triggers a random number to pick from 10 words and stores it in that word in the secret_word string –(5 Difficulty Levels, 10 words per level, 50 words) display_word character array is created based upon the length of secret_word and is comprised of only blanks Prints out a picture based on how many wrong guesses the user has from the picture function Prompts user for a guess which is stored in letter letter_check checks whether the letter entered is in secret_word and puts it into display_word and updates it Then it loops and lets the user guess again…

3 Functions explained: 1.void introduction() 2.void pick_difficulty() 3.void make_display_word() 4.void picture() 5.void letter_check() 6.void guess_a_letter()

4 void introduction() This function simply does what it looks like it would – it introduces the program and displays the main menu

5 void pick_difficulty() This function also does what it looks like it would – it prompts the user for the difficulty level that the user wants to try and play at –The difficulty directly relates to the size of the word being chosen Level 1 = easy short words ↨ Level 5 = longer harder words –The difficulty chosen will then correlate to the set of the 10 words that a random number will choose inside the function

6 void make_display_word() The for loop allows this function to display underscores with spaces in between them corresponding to the size of the secret_word chosen in pick_difficulty

7 void picture() This function does what it might appear to do – it outputs the correct picture corresponding to the wrong_guess_count the user has at the current time

8 void letter_check() This function is labeled letter_check since the function checks whether or not the letter guess the user chooses is in the secret_word string –If the function figures out that the letter is in fact in the secret_word, then it places it in the character array where it belongs It does this by utilizing flags and changing their values –If not, then the function does nothing with the display_word array and increments the wrong_guess_count integer

9 void guess_a_letter() This function like the rest of the functions in the project does what it looks like it might – it asks the user to choose a letter from the alphabet to see if its in the secret_word

10 Source Code Included In Project: Hangman.h Hangman.cpp Main.cpp Hangman.ppt Readme.txt Game.exe Other Files Included In Project:

11 Header //hangman.h #include using std::string; using namespace std; class Hangman { Hangman.hPage 1 / 2

12 Header public: Hangman(); void pick_difficulty(); void make_display_word(); void introduction(); //hangman.h void picture(); void guess_a_letter(); void letter_check(); string secret_word; char display_word[50]; char letter; private: //protection is unnecessary in this project }; Hangman.hPage 2 / 2

13 Source // Hangman.cpp #include using std::string; #include using namespace std; #include "Hangman.h" Hangman::Hangman() { //wrong_guess_count =0; //max_guess_count =6; }; Hangman.cppPage 1 / 23

14 void Hangman::make_display_word() { int word_size = secret_word.size(); for (int i = 0; i < word_size*2; i+=2) { display_word[i] = '_'; display_word[i+1] = ' '; } for (i=0; i < word_size*2; i++) { cout << display_word[i]; } cout << "\n"; }; void Hangman::pick_difficulty() { cout <<"\n" Hangman.cppPage 2 / 23Source

15 <<"Please Enter A Level Selection: "; // Reads user's level selectison int difficulty; cin >> difficulty; // Puts one lines after the input to space the results cout << endl; // While loop statement if an incorrect selection of difficulty is made by the user while(difficulty != 1 && difficulty != 2 && difficulty != 3 && difficulty != 4 && difficulty != 5) { cout <<"You have made an invalid selection.\n" <<"Valid selections include: 1, 2, 3, 4, 5.\n" <<"\n" <<"Please reselect your level of difficulty:\n" <<"*********************************\n" <<"**\n" SourceHangman.cppPage 3 / 23

16 <<"* (1) LEVEL 1 - Beginner*\n" <<"* (2) LEVEL 2 - Intermediate*\n" <<"* (3) LEVEL 3 - Experienced*\n" <<"* (4) LEVEL 4 - Good*\n" <<"* (5) LEVEL 5 - Master*\n" <<"**\n" <<"*********************************\n" <<"\n" <<"Please Re-Enter A Level Selection: "; // Reads user's level selection cin >> difficulty; } srand(time(0)); int random_number = rand()%10; SourceHangman.cppPage 4 / 23

17 if (difficulty==1) { switch(random_number) { case 0: secret_word ="cat"; break; case 1: secret_word ="book"; break; case 2: secret_word ="desk"; break; case 3: secret_word ="game"; break; case 4: secret_word ="sun"; break; SourceHangman.cppPage 5 / 23

18 case 5: secret_word ="shoe"; break; case 6: secret_word ="eye"; break; case 7: secret_word ="cup"; break; case 8: secret_word ="volt"; break; case 9: secret_word ="rib"; break; } SourceHangman.cppPage 6 / 23

19 else if (difficulty==2) { switch(random_number) { case 0: secret_word ="light"; break; case 1: secret_word ="cloud"; break; case 2: secret_word ="board"; break; case 3: secret_word ="paper"; break; case 4: secret_word ="whale"; break; SourceHangman.cppPage 7 / 23

20 case 5: secret_word ="river"; break; case 6: secret_word ="clock"; break; case 7: secret_word ="butt"; break; case 8: secret_word ="disk"; break; case 9: secret_word ="chip"; break; } SourceHangman.cppPage 8 / 23

21 else if (difficulty==3) { switch(random_number) { case 0: secret_word ="strong"; break; case 1: secret_word ="answer"; break; case 2: secret_word ="songs"; break; case 3: secret_word ="apple"; break; case 4: secret_word ="garage"; break; SourceHangman.cppPage 9 / 23

22 case 5: secret_word ="dollar"; break; case 6: secret_word ="monkey"; break; case 7: secret_word ="pursue"; break; case 8: secret_word ="budget"; break; case 9: secret_word ="please"; break; } else if (difficulty==4) { SourceHangman.cppPage 10 / 23

23 switch(random_number) { case 0: secret_word ="computer"; break; case 1: secret_word ="backpack"; break; case 2: secret_word ="textbook"; break; case 3: secret_word ="bookcase"; break; case 4: secret_word ="carpet"; break; case 5: secret_word ="diamond"; break; SourceHangman.cppPage 11 / 23

24 case 6: secret_word ="buffer"; break; case 7: secret_word ="diameter"; break; case 8: secret_word ="picture"; break; case 9: secret_word ="rabbit"; break; } else if (difficulty==5) { switch(random_number) { SourceHangman.cppPage 12 / 23

25 case 0: secret_word ="tortoise"; break; case 1: secret_word ="volunteer"; break; case 2: secret_word ="enrollment"; break; case 3: secret_word ="horseshoe"; break; case 4: secret_word ="reception"; break; case 5: secret_word ="maximum"; break; SourceHangman.cppPage 13 / 23

26 case 6: secret_word ="necktie"; break; case 7: secret_word ="stranger"; break; case 8: secret_word ="communication"; break; case 9: secret_word ="collaboration"; break; } }; void Hangman::introduction() { SourceHangman.cppPage 14 / 23

27 cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" __|__ | \n" <<" | | \n" <<" | | | \n" <<" | \n" <<" ---\n" <<" \n" <<" *** WELCOME TO HANGMAN ***\n" <<" \n" <<"Please select your level of difficulty:\n" <<"*********************************\n" <<"**\n" <<"* (1) LEVEL 1 - Beginner*\n" <<"* (2) LEVEL 2 - Intermediate*\n" <<"* (3) LEVEL 3 - Experienced*\n" <<"* (4) LEVEL 4 - Good*\n" <<"* (5) LEVEL 5 - Master*\n" <<"**\n" <<"*********************************\n"; SourceHangman.cppPage 15 / 23

28 }; void Hangman::guess_a_letter() { cout << "Enter a letter for your guess: "; cin >> letter; system("cls"); }; void Hangman::letter_check() { extern int chance_init; extern bool winner; int flag = 0; for (int i=0; i < secret_word.size(); i++) { if (letter == secret_word[i]) { display_word[i*2] = letter; flag = 1; SourceHangman.cppPage 16 / 23

29 } if (flag == 0){ chance_init++; } for (i=0; i < secret_word.size()*2; i++) { cout << display_word [i]; } cout << "\n"; int flag1 = 1; for (i=0; i < secret_word.size(); i++) { if (display_word[i*2] != secret_word[i]) { flag1 = 0; } SourceHangman.cppPage 17 / 23

30 if (flag1 == 1) { winner = true; } }; void Hangman::picture() { extern int chance_init; extern int chance_max; cout << "Max Guesses = " << chance_max << endl; cout << "Guesses Remaining = " << chance_max - chance_init << endl; if (chance_init < chance_max) { switch (chance_init) { case 0: cout <<" _____ \n" <<" | | \n" <<" | \n" SourceHangman.cppPage 18 / 23

31 <<" | \n" <<" ---\n"; break; case 1: cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" | \n" <<" ---\n"; break; SourceHangman.cppPage 19 / 23

32 case 2: cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" | | \n" <<" | \n" <<" ---\n"; break; case 3: cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" __| | \n" <<" | | \n" <<" | \n" SourceHangman.cppPage 20 / 23

33 <<" | \n" <<" ---\n"; break; case 4: cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" __|__ | \n" <<" | | \n" <<" | \n" <<" ---\n"; break; case 5: SourceHangman.cppPage 21 / 23

34 cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" __|__ | \n" <<" | | \n" <<" | \n" <<" ---\n"; break; case 6: cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" __|__ | \n" <<" | | \n" <<" | | | \n" SourceHangman.cppPage 22 / 23

35 <<" | \n" <<" ---\n“; break; } }; SourceHangman.cppPage 23 / 23

36 SourceMain.cppPage 1 / 5 //main.cpp #include using std::cout; using std::endl; #include "Hangman.h" //class definition int play_again; int chance_init; int chance_max = 6; bool winner; int main() { do { system("cls"); chance_init = 0;

37 winner = false; Hangman myHangman; myHangman.introduction(); myHangman.pick_difficulty(); system("cls"); myHangman.make_display_word(); while(chance_init < chance_max) { myHangman.picture(); myHangman.guess_a_letter(); myHangman.letter_check(); if (winner == true) { cout << "You win!!!" << endl; cout << "Play again? \n" << "Press 1 To play again! \n" << "Press 2 To quit! \n"; SourceMain.cppPage 2 / 5

38 cin >> play_again; break; } if (winner == false) { cout << "You LOSE!!!! \n" << "You are stupid!!!" << endl; cout << "Play again? \n" << "Press 1 To play again! \n" << "Press 2 To quit! \n"; cin >> play_again; cout <<" _____ \n" <<" | | \n" <<" O | \n" <<" __|__ | \n" <<" | | \n" <<" | | | \n" SourceMain.cppPage 3 / 5

39 <<" | \n" <<" --- \n" <<" \n" <<" *** HANGMAN *** \n" <<" \n" <<" Creator: Will Matthau 2006 \n" <<" Paul Christian 2006 \n" <<" \n" <<"SPECIAL THANKS: \n" <<"*************************************\n" <<"* * \n" <<"* (1) NOAH BURTON * \n" <<"* (2) PAT MARINELI * \n" <<"* (3) DAEWON SONG * SourceMain.cppPage 4 / 5

40 \n" <<"* (4) RONG LI * \n" <<"* (5) ALL OTHERS WHO GAVE US ADVICE *\n" <<"* * \n" <<"*************************************\n"; cin.ignore(); } } while ( play_again = 1 && play_again !=2); return 0; } SourceMain.cppPage 5 / 5

41 Problems Experienced: random_number was not actually random –The number was always 1, or 41 –Therefore, the first case was always chosen rather then randomly choosing a case for each difficulty level We initially didn’t have globals set so certain functions were not given access to the maximum guess count that we initially set as well as the current users wrong guess count

42 Questions ?


Download ppt "HANGMAN Created By: Will Matthau & Christian Stumpf."

Similar presentations


Ads by Google