From 7c29a4e8447abfc28904f88f4d4928d0720ece1a Mon Sep 17 00:00:00 2001 From: Shena Yoshida Date: Thu, 18 Jun 2015 22:28:48 -0400 Subject: [PATCH] Shena Yoshida Hangperson Homework --- .DS_Store | Bin 0 -> 6148 bytes HangPerson/.DS_Store | Bin 0 -> 6148 bytes HangPerson/HangPerson/main.m | 97 ++++++++++++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 6 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..e60d1efcd7977db0c50681f4b5df43a139ba0c3b GIT binary patch literal 6148 zcmeHKUu)Yi5I?2a=AJFiP(iLeq z51}w)3?YRAO3;w6M6=^xWPsML4R0XA6+49+>le?;Nu22z`+vuiOqEr)`%5&|nvWho z@mlS5D*n^<`*5shVHH)=au5~ArlpcJcJ?r;#!LG^>+IT&;zO0rM*j0%omY{{)8a(QuSI3#Z_MZ0{hf~7>Gl>K zIq&zo9r>#FaaAHcKnBQgWb!2L2n`-4O!3>?-L&DMbx{XSBElaK^$ zx=RpBhk?V|BKDvNn~G>tg}Y)1n~r|z;sS@YMVk)7%#7o>nT5Nd2s1nSr3nWSSmc@+ zU1r2i) gV=NuT8>mLmFUdd*9M%@mgTg-oh6b*ffqP}(515r^*8l(j literal 0 HcmV?d00001 diff --git a/HangPerson/.DS_Store b/HangPerson/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fee38d144572c9f65a6fdb8b302d952d82a75fcb GIT binary patch literal 6148 zcmeHK!AitH41Li(EQqiN4<6?W7WNOyQo*CJ7mrFSD`K}rUGUgX@HhM%|Hzj~lr8q4 z9z-;O$(zn3Gs%O_OaRDoTQ7hafGL}zXlF!pcywydjVDCOYnL^OJ=hIv5BBf`MS*KQq8PTV;A+7&;gT27-Zi2K0PLY>I_rZ ga-1h^K53tJg=251tLS)kC&oh{6A~&I_yGo90S5j)NdN!< literal 0 HcmV?d00001 diff --git a/HangPerson/HangPerson/main.m b/HangPerson/HangPerson/main.m index 948dd70..58e71de 100644 --- a/HangPerson/HangPerson/main.m +++ b/HangPerson/HangPerson/main.m @@ -1,18 +1,103 @@ // // main.m -// HangPerson +// BubbleSortHomework // -// Created by Michael Kavouras on 6/15/15. -// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// Created by Shena Yoshida on 2015-06-17. +// Copyright (c) 2015 Shena Yoshida. All rights reserved. // #import int main(int argc, const char * argv[]) { - @autoreleasepool { + + //I'm going to start by offering the user a little bit of context. + printf("*******************************************\n"); + printf("* * * * * * * *\n"); + printf("* HELLO WORLD!! *\n"); + printf("* * * * * * * *\n"); + printf("*******************************************\n\n"); + + + //And then slowing it down with usleep. + usleep(1e6); + printf("Let's play HANGPERSON!!!\n\n"); + usleep(1e6); + printf("Now, this word has SEVEN leters.\n"); + usleep(1e6); + printf("and you are only allowed TEN guesses.\n\n"); + usleep(1e6); + printf("*******************************************\n"); + printf("* * * * * * * *\n"); + printf("* LET'S BEGIN!! *\n"); + printf("* * * * * * * *\n"); + printf("*******************************************\n\n"); + usleep(1e6); + + + // array of chars with your secret word + char theWord[8] = "almonds"; + // array of chars that represents each letter in my secret word + char theUnderscores[8] = "_______"; + // char theUnderscores[8] = {'_','_','_','_','_','_','_','_'}; + // integer that represents the number of guesses a user can take before LOOSING. It's set for 10 in this game + int maxGuesses = 10; // changed from 10 + // this is the temporary placeholder for when we swap guesses with the underscores + char temp; + + + // AND now we begin to collect letters from the user, this should be in a "for" loop + // here we are setting up the values that will be used in the loop + // char that represents user imput for their letter guess + char guess; + // this is a loop variable that we used below to reference how many guesses the user has executed + int g; + // represents the number of correct guesses necessary to win the game + int swaps = 7; + // this is the for outer loop, it starts at 0, the user can has 10 chances + for (g = 0; g < maxGuesses; g++) { + printf("Please choose a letter: "); + // the computer reads the user's letter and commits it to memory + scanf("%c", &guess); + // this just tidies up rogue imput + char vanish; + scanf("%c", &vanish); - // code goes here... - + // this is the nested loop is going through the word "almonds" and the corresponding "underscores" + for (int i = 0; i < 7; i++) { + // checks to see if the imput character matches the character in the word at index i. If that is true, then the program will swap the correct letter for the corresponding underscore + if (guess == theWord[i]) { + // counts down to the remaining number of swaps until the user wins the game at 0 + swaps--; + // the following three lines swap correct guesses for corresponding underscores + temp = theWord[i]; + theWord[i] = theUnderscores[i]; + theUnderscores[i] = temp; + // shows the remining underscores left in the game + printf("%s\n",theUnderscores); + } + } + // we're breaking out of the outer loop when there are no swaps left (aka when the puzzle is solved) + if (swaps == 0) { + break; + } + } + // once 10 guesses have been used, you loose! + if (g == maxGuesses) { + usleep(1e6); + printf(" * * * * * * * * * * * * * \n"); + printf(" * YOU HAVE NO MORE GUESSES * \n"); + printf(" * * * * * * * * * * * * \n"); + printf(" * GAME OVER * \n"); + printf(" * * * * * * \n"); + + + // once there are no remaining swaps to execute, the puzzle has been solved and everyone is happy + } else { + printf("*******************************************\n"); + printf("* * * * * * * * * * * *\n"); + printf("* * HOORAY!! YOU WIN!! * *\n"); + printf("* * * * * * * * * * * *\n"); + printf("*******************************************\n\n"); } return 0; }