Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ xcuserdata
# Carthage/Checkouts

Carthage/Build
.DS_Store
71 changes: 69 additions & 2 deletions HangPerson/HangPerson/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,75 @@
int main(int argc, const char * argv[]) {
@autoreleasepool {

// code goes here...

// I would like to add the option of playing again
// Some other words:
// Coconut
// Tropical
// Strawberry

//I would also like to add a maximum number of guesses


char guessedLetter;
char secretWord1[7] = "unicorn";
char blankSpaces1[7] = "_______";

int secretWord1Length = sizeof(secretWord1) / sizeof(char);


printf ("Let's play hangperson!\n\n");


int wordComplete = 0;

while(true) {

//print current state of blank spaces
for (int k = 0; k < secretWord1Length; k++) {
printf("%c ", blankSpaces1[k]);
}

// if all letters have been guessed. Game has been won.
if (wordComplete == 1){
printf("\n\nYou're awesome. You got it.");
break;
}

//print prompt, scan for user input
printf("\n\nGuess a letter:");
scanf("%c", &guessedLetter);

//set an integer to declare if any matches are found between the user's input and the secret word
int matches = 0;
wordComplete = 1;

//compare user input to secret word, compare secret word to the current state of blank spaces
for (int i = 0; i < secretWord1Length; i++) {

if (guessedLetter == secretWord1[i]){
blankSpaces1[i] = guessedLetter;
matches = 1;
}
if (blankSpaces1[i] != secretWord1[i]){
wordComplete = 0;
}
}

if (matches == 1){
printf("\nNice!\n");
}

if (matches == 0){
printf("\nSorry, no '%c'\n\n", guessedLetter);
}


scanf("%c", &guessedLetter);
}




}
return 0;
}