From 206bdfcb39147ffb52ea27b4b05e213c3c06d1a4 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 19 Jun 2015 21:45:12 -0400 Subject: [PATCH] Lauren Caponong commit hang person --- .DS_Store | Bin 0 -> 6148 bytes HangPerson/.DS_Store | Bin 0 -> 6148 bytes HangPerson/HangPerson/main.m | 67 +++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 HangPerson/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3ed36b3e9938c14e2eda7ee37a79cfe41d7e2db9 GIT binary patch literal 6148 zcmeHK&1xGl5FXiXvbHZ9(u6`Tx)yw}OOrOYjq5-!1%r!CsEfPHF15hy8t=L$7{i|X z0DXYwr+tl*zC@p-*Um_av2lAUlwxMY=o^hRTJ#AtI{+Y>)35>H0)T@`SSVxn8=-m9 z4JlZUKt#no+7Q76Qb-`)Sj~?Akpa593cLg#Z|wc*{ROjh9E_3x=YIy{kxH|A{f8(N zOAmH-opPm0&E2cK?F^GyC-bvu+Vm%H^hkwKVC}Y_4e#yONitg6e$Z9XY~Vh8k;Iv= z;%KrG+V812OlHkw8i#4WWA^K*FdGisgZ3o)fT3+aj=CyUff}jo(kW9LxQFxklbUSQ zPZu>gf8Kanlh00077O>2;~YIcK6`aBUVQv~b$xUDm$g8Tfk!=zWl=gr3FRpnf{A(3}KrTl;X z=lXv=h)2u-Gq6<*h*GQ5YT}V>ZrwN>QFgHh z^&sLVFnQCNWF~pgnF#<{^z|H=0hqEWigrdshexM&+;~Eiyv8Xmaff@fxE)#OFAiz! z`#8Y`BVJ)W{v$l1VkR|n>X=oF>zmblS+z}PiJZND$G2(AvhE)$;N`hL$SZt#-=?j9 z?Au+f$NXfWhYkjUfnXpQ*k%TJXRA#23_}M4!9XzZ!GN9*iA}L^91Qc(L6u7YqCTUu zu&=d*`XtA~aWLczMa-3GuHq$zm^;Ul+ZB$3p}9l6_z>Uuy?BwlJJ(Oy98wsD4hDjO zO$K)DbEfzIF@KrSB7f5*zJh^Z;GZ!dlX6)un3UhGpVHI2HnE+vsi@tc9SZv!j{tt? hIdYgMZ9ZwAc7@|$sH^CBb|=O|AQKWQ82AMS-T(svKL`K- literal 0 HcmV?d00001 diff --git a/HangPerson/HangPerson/main.m b/HangPerson/HangPerson/main.m index 948dd70..ec511b0 100644 --- a/HangPerson/HangPerson/main.m +++ b/HangPerson/HangPerson/main.m @@ -6,13 +6,74 @@ // Copyright (c) 2015 Mike Kavouras. All rights reserved. // +// LAUREN CAPONONG HW - 06-19-15 + + #import + int main(int argc, const char * argv[]) { @autoreleasepool { - // code goes here... - + // Your job is to create a game called "Hang Person" where a user has to guess a predetermined word(s). + // + // Here are the rules: + // + // 1. After every guess, you must print out the current state of the game. (e.g. _ _ n _ n _) + // 2. You must determine a maximun number of wrong guesses. If the player guesses too many incorrect letters, they lose and the game ends. + // 3. If the player looses, provide a message letting them know that they lost. + // 4. If they win, provide a message letting them know that they won. + + + + //INITIALIZING VARIABLES + + char word[] = {'l', 'e', 'o', 'p', 'a', 'r', 'd'}; // array of type 'char' for the word leopard + int maxGuesses = 7; // define # of guesses possible + char dashes[7] = {'-', '-', '-', '-', '-', '-', '-'}; + int currentGuess; + char userGuess, letterGuess; + int correctGuesses = 0; + int lives = 7; + + + //PRINT INTRODUCTION + + printf("Your word is: _ _ _ _ _ _ _ \n"); + printf("You can only guess 7 times.\n "); + + + //FOR LOOP + + for (currentGuess = 0; currentGuess < maxGuesses; currentGuess++) { + + printf("\nEnter a character: "); // enter character + scanf(" %c", &userGuess); // scanning user input + + + for (letterGuess = 0; letterGuess < maxGuesses; letterGuess++) + { + if (userGuess == word[letterGuess]) { // if user enters a character in one index of j, + dashes[letterGuess] = userGuess; // the index of DASHES array equals to whatever the user guesses + correctGuesses = correctGuesses + 1; // if user gets another correct guess add +1 + } + } + + printf("Result: %s \n", dashes); // prints out the result in dashes array + + lives--; + + if (lives == 0 && correctGuesses < 7) { + printf("\nYou lost, sorry. Try again later."); + } else if (lives > 0) { + printf("\nYou have %d tries left \n", lives); + } else { + printf("\nYou won, thanks for playing!"); + } + // + // + } } + return 0; -} +} \ No newline at end of file