HANGMAN Created By: Will Matthau & Christian Stumpf.

Slides:



Advertisements
Similar presentations
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Advertisements

While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
True or false A variable of type char can hold the value 301. ( F )
Computer Science 1620 Loops.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Overview creating your own functions calling your own functions.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
C-Strings A C-string (also called a character string) is a sequence of contiguous characters in memory terminated by the NUL character '\0'. C-strings.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Programming Introduction to C++.
CS161 Topic #14 1 Today in CS161 Lecture #14 Practicing! Writing Programs to Practice Write a program that counts the number of vowels in a sentence, ended.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
1 Copyright (C) 2008 by Dennis A. Fairclough all rights reserved.
CS161 Topic #15 1 Today in CS161 Lecture #15 Practicing! Writing Programs to Practice Write a game program (1 player) of Mad Math Reuse the functions to.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Visual Basic Games: Prepare for Hangman
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Programming (in C++) Algorithms on sequences. Reasoning about loops: Invariants. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept.
Implementation of the Hangman Game in C++
CS161 Week #8 1 Today in CS161 Week #8 Practicing! Writing Programs to Practice Write a program that counts the number of vowels in a sentence, ended by.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
1 Chapter 9 Additional Control Structures Dale/Weems.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CSE1222: Lecture 7The Ohio State University1. logExample.cpp // example of log(k) for k = 1,2,..,8... int main() { cout
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Looping and Counting Lecture 3 Hartmut Kaiser
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline Introduction Arrays Declaring Arrays Examples Using Arrays.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Module 4: I/O and Strings #1 2000/01Scientific Computing in OOCourse code 3C59 Module 4: I/O In this module we will cover Keyboard/screen input and output.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 CS161 Introduction to Computer Science Topic #8.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
HANGMAN- Software/ Hardware Integration Project Idea was to design a working C++ program to play a Hangman word guessing game Idea was to design a working.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
Chapter 4 Repetition Structures
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
REPETITION CONTROL STRUCTURE
Chapter 1.2 Introduction to C++ Programming
Chapter 2.1 Control Structures (Selection)
Engineering Innovation Center
TOPIC 4: REPETITION CONTROL STRUCTURE
Value returning Functions
We’re moving on to more recap from other programming languages
Introduction to C++ Programming
Programming Introduction to C++.
Programming Fundamental
Presentation transcript:

HANGMAN Created By: Will Matthau & Christian Stumpf

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…

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()

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

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

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

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

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

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

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

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

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

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

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

<<"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

<<"* (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

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

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

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

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

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

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

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

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

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

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

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

}; 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

} 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

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

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

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

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

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

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

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;

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

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

<<" | \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

\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

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

Questions ?