-
Notifications
You must be signed in to change notification settings - Fork 25
Kaira_hangPerson_hw_06-19 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kairarobot
wants to merge
2
commits into
accesscode-2-2:master
Choose a base branch
from
kairarobot:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,188 @@ | ||
| // | ||
| // main.m | ||
| // HangPerson | ||
| // hangMan-homework | ||
| // | ||
| // Created by Michael Kavouras on 6/15/15. | ||
| // Copyright (c) 2015 Mike Kavouras. All rights reserved. | ||
| // Created by Kaira Villanueva on 6/16/15. | ||
| // Copyright (c) 2015 apps. All rights reserved. | ||
| // | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
|
|
||
| int main(int argc, const char * argv[]) { | ||
| @autoreleasepool { | ||
|
|
||
| // code goes here... | ||
|
|
||
| // ** prints out different levels | ||
| printf("////*** HANGMAN ***////"); | ||
| printf("\n\nAre you ready to play?\n"); | ||
| printf("\n '1' for Level 1 -- UNLOCKED"); | ||
| printf("\n '2' for Level 2 -- LOCKED"); | ||
| printf("\n '3' for Level 3 -- LOCKED"); | ||
| printf("\n '4' for Level 4 -- LOCKED"); | ||
| printf("\n '5' for Level 5 -- LOCKED\n"); | ||
| printf("\nENTER: "); | ||
|
|
||
| // ** asks the user for a level | ||
| int levelSelect; | ||
| scanf("%d", &levelSelect); | ||
|
|
||
| if(levelSelect == 1){ | ||
|
|
||
| // LEVEL 1 | ||
|
|
||
|
|
||
| printf("\nYOU HAVE CHOSEN LEVEL 1"); | ||
| printf("\n\nHINT: ADJECTIVE"); | ||
|
|
||
| char levelOne[6] = { 'h', 'a', 'p', 'p', 'y', '\0'}; | ||
| char empty[6]; | ||
| char levelOneMatch[6]; | ||
| char levelOneGuesses[100]; | ||
| int count; | ||
| count = sizeof(levelOne)/sizeof(char); | ||
|
|
||
| // VARAIBLES | ||
|
|
||
| int tries = 0; | ||
| int maxTries = 7; | ||
| int match = 0; | ||
| int counterWrong = 0; | ||
| char *s; // same char 2x | ||
| BOOL gameOver = NO; | ||
|
|
||
| // START GAME | ||
|
|
||
| while (!gameOver){ | ||
|
|
||
| // ** asks for user input | ||
| printf("\n\nENTER LETTER: "); | ||
| char guessLetter; | ||
| scanf(" %c", &guessLetter); | ||
| char emptyTwo[100]; | ||
| printf("LETTER ENTERED: "); | ||
|
|
||
|
|
||
| // ** converts uppercase letter to lower case | ||
| char c; | ||
| c = guessLetter; | ||
| if (isupper(c)) c=tolower(c); | ||
|
|
||
|
|
||
| // ** checks if player guessed the same char twice | ||
| if (!(memchr(levelOne, c, sizeof(levelOne)))){ | ||
| printf("WRONG GUESS!\n"); | ||
| counterWrong++; | ||
| switch (counterWrong) { | ||
| case 1: | ||
| printf(" _________ \n"); | ||
| printf("\n"); | ||
| break; | ||
| case 2: | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("\n"); | ||
| break; | ||
| case 3: | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("| 0 \n"); | ||
| printf("\n"); | ||
| break; | ||
| case 4: | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("| 0 \n"); | ||
| printf("| /|\\ \n"); | ||
| printf("\n"); | ||
| break; | ||
| case 5: | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("| 0 \n"); | ||
| printf("| /|\\ \n"); | ||
| printf("| / \\ \n"); | ||
| printf("\n"); | ||
| break; | ||
| case 6: | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("| 0 \n"); | ||
| printf("| /|\\ \n"); | ||
| printf("| / \\ \n"); | ||
| printf("| \n"); | ||
| printf("\n"); | ||
| break; | ||
| case 7: | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("| 0 \n"); | ||
| printf("| /|\\ \n"); | ||
| printf("| / \\ \n"); | ||
| printf("| \n"); | ||
| printf("| \n"); | ||
| printf("\n"); | ||
| break; | ||
| default: | ||
| printf("..."); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // ** checks for the correct match | ||
| for (int i = 0; i < count; i++){ | ||
| if (c == levelOne[i]){ | ||
| //printf("There is a match!\n"); | ||
| //printf("Guess: %c matches %c \n", c, levelOne[i]); | ||
| match++; | ||
| //printf("match number: %d", match); | ||
| levelOneMatch[i] = c; | ||
| tries--; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // ** prints out the correct matches | ||
| for (int i = 0; i < count; i++){ | ||
| printf("%c ", levelOneMatch[i]); | ||
| } | ||
|
|
||
|
|
||
| // ** checks if player guessed the same char twice | ||
| levelOneGuesses[tries] = c; | ||
| s = strstr(levelOneGuesses, &c); | ||
| if (s != NULL){ | ||
| printf("You already guessed this letter!\nPlease pick another letter.\n"); | ||
| } | ||
|
|
||
|
|
||
| // ** increases the count for tries | ||
| tries++; | ||
| printf("\n\nYou have %d tries left\n", maxTries - tries); | ||
|
|
||
|
|
||
|
|
||
| // ** checks to see if the user's array matches the OG word's array | ||
| if ( levelOneMatch[0] == levelOne[0] && levelOneMatch[1] == levelOne[1] && levelOneMatch[2] == levelOne[2] && levelOneMatch[3] == levelOne[3] && levelOneMatch[4] == levelOne[4] && levelOneMatch[5] == levelOne[5] ){ | ||
| printf("\nYOU WON!\n%s", levelOneMatch); | ||
| } | ||
|
|
||
|
|
||
| // ** this is the game state that puts the player into game over if exceeded tries | ||
| if (tries == maxTries){ | ||
| gameOver = YES; | ||
| printf(" _________ \n"); | ||
| printf("| | \n"); | ||
| printf("| 0 \n"); | ||
| printf("| /|\\ \n"); | ||
| printf("| / \\ \n"); | ||
| printf("| \n"); | ||
| printf("| \n"); | ||
| printf("| GAME OVER! \n"); | ||
| } | ||
|
|
||
| } // while loop game end | ||
|
|
||
| } // level select 1 end | ||
|
|
||
| } | ||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one thing I would suggest is that you make this more general. Use a for loop and compare within the loop...