From dad6e4281ac67819299d16a225bc44bc98df8f6a Mon Sep 17 00:00:00 2001 From: maldonadoguitar Date: Fri, 19 Jun 2015 18:36:47 -0400 Subject: [PATCH 1/2] Christian Maldonado/HangMan --- HangPerson/HangPerson/main.m | 66 +++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/HangPerson/HangPerson/main.m b/HangPerson/HangPerson/main.m index 948dd70..501ffd0 100644 --- a/HangPerson/HangPerson/main.m +++ b/HangPerson/HangPerson/main.m @@ -11,8 +11,66 @@ int main(int argc, const char * argv[]) { @autoreleasepool { - // code goes here... - - } - return 0; + // print instructions + printf("Time for HANGMAN!!!!\n"); + printf("hint word is....Galactica\n"); + + //my word to be guessed + char secretWord[] = "battlestar"; + //plce for my guessed word + char guessedWord[] = "__________"; + //number of wrong attemps + + int count = sizeof(secretWord); + + int totalGuesses = 11; + //for loop better than while loop. this is what's giving the player his/her 11 guesses + + + for (int x = 0; x < totalGuesses; x++) { + // process guesses from the user + printf("Please guess a letter\n"); + + char guessAttempt; + scanf("%c", &guessAttempt); + + printf("%c\n", guessAttempt); + fpurge(stdin); + + for (int i = 0; i < count; i++) { + // i goes from 0 -> 9 + char currentCharacter = secretWord[i]; + if (guessAttempt == currentCharacter) + + { + // this needs to happen `count` times in order to win + guessedWord[i] = currentCharacter; + } + } + + int stop = 1; + + // loop over guessedWord and see if there are still any underscores + // if not, then the user has won the game + for (int j=0; j < count; j++){ + if (guessedWord[j] == '_') { + stop = 0; + break; + } + } + + // if the game is not still going, then break + if (stop == 1){ + printf("%s\n",guessedWord); + printf("YOU WIN!!!!!"); + break; + + + } + + // print out the guessedWord + printf("%s",guessedWord); + } + return 0; + } } From 523d3a2ce86ded3c22f4c310397ba615f35eda69 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 1 Oct 2015 19:18:53 -0400 Subject: [PATCH 2/2] wow been a while since i used C --- HangPerson/.DS_Store | Bin 0 -> 6148 bytes HangPerson/HangPerson/main.m | 87 ++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 HangPerson/.DS_Store diff --git a/HangPerson/.DS_Store b/HangPerson/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c4857c982c3d00c844ad40bba506e43540c55558 GIT binary patch literal 6148 zcmeHKu}Z{15PhRp9N1i8VY!v1aJ@x1B3KId0V;`{h%rGuuuS8BSouHxk#BZJxnK&l z5YZXfd7Ist-I)j3-2otrbv*}W0H$n;qMZ@Z;nArrH=YnBuW^D4+~N)`ZblaRjYAsy zE{<`|h*#K*{{RoDm`Tl?I%d`4>UuR_R&CQ+BBzgE@on0&tk?Gy@bbKWm{<7pzD-+y z+qb*ijQPnz4;>5y1HnKr@Shprovkw6F$^6H1OvgqI|F(?BsRsuu{X>|2URWsi297q z!oJoL>XRG`$KH@L6fsw#xr&zJD4Ez8Cufsb&asU7T literal 0 HcmV?d00001 diff --git a/HangPerson/HangPerson/main.m b/HangPerson/HangPerson/main.m index 948dd70..a822d3f 100644 --- a/HangPerson/HangPerson/main.m +++ b/HangPerson/HangPerson/main.m @@ -6,13 +6,98 @@ // Copyright (c) 2015 Mike Kavouras. All rights reserved. // + #import int main(int argc, const char * argv[]) { @autoreleasepool { - // code goes here... + + + char *Words[] = {"album","music","strat","dooky","guitar","animal","battlestar","galactica","pegasus"}; + + int count = sizeof(Words)/sizeof(char*) - 1; + + int randomNumber = arc4random_uniform(count); + + char *randomizeWord = Words[randomNumber]; + + + long lengthOfWord = strlen(randomizeWord); + + int numberOfLives = 6; + + int correctNum = 0; + int oldCorrect = 0; + int letterGuessed[11] = { 0,0,0,0,0,0,0,0,0,0,0 }; + + int quit = 0; + + + char guess[16]; + char userInput; + + printf("Time For Hangman"); + + + while ( correctNum < lengthOfWord ) { + printf("\nGuess NOW mofo!!!\nThe word is:"); + for (int i = 0; i < lengthOfWord; i++) { + if (letterGuessed[i] == 1) { + printf("%c", Words[randomNumber][i]); + } + else { + printf("_ "); + } + } + + printf("\n"); + + + printf("Enter a new letter here:"); + + fgets(guess, 16, stdin); + if (strncmp(guess, "quit", 4) == 0) { + quit = 1; + break; + } + + userInput = guess[0]; + printf("You entered: %c\n", userInput); + + oldCorrect = correctNum; + for (int i = 0; i < lengthOfWord; i++) { + if (letterGuessed[i] == 1) { + continue; + } + + if (userInput == Words[randomNumber][i]) { + letterGuessed[i] = 1; + correctNum++; + } + } + if (oldCorrect == correctNum) { + numberOfLives--; + printf("Sorry, wrong letter.\n"); + if (numberOfLives == 0){ + break; + } + }else{ + printf("Correct letter!\n"); + } + } + + if (quit == 1) { + printf("You quit!Good Bye.\n"); + } + else if (numberOfLives == 0){ + printf("\n Man you suck...LOSER!!! The word was: %s...Hello!\n",Words[randomNumber]); + } + else{ + printf("\nYOU WON!!! The word is %s!!!\n", Words[randomNumber]); + } + } return 0; }