-
-
Save codecademydev/a8c24fe1fbb1844e14bfa706ee51530d to your computer and use it in GitHub Desktop.
Codecademy export
This file contains 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
#include <iostream> | |
#include "ufo_functions.hpp" | |
int main() { | |
greet(); | |
//It counts number of misses | |
int misses=0; | |
//The codeword that we want the user to enter | |
std::string codeword="codecademy"; | |
//Codeword that user enters and is displayed to the user | |
std::string answer="__________"; | |
//Calling the functions greet(); for the intro paragraph of this game | |
greet(); | |
//while loop that runs till answer is not equal to true and misses is less than 7(letters in codeword) | |
while (answer != codeword && misses < 7) { | |
// code for each turn will go here | |
misses++; | |
} | |
end_game(answer, codeword); | |
} |
This file contains 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
#include <iostream> | |
#include <vector> | |
// Define functions | |
void greet() { | |
std::cout << "=============\n"; | |
std::cout << "UFO: The Game\n"; | |
std::cout << "=============\n"; | |
std::cout << "Instructions: save your friend from alien abduction by guessing the letters in the codeword.\n"; | |
} | |
void display_misses(int misses) { | |
if (misses == 0 || misses == 1) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " / \\ ( Send help! ) \n"; | |
std::cout << " / 0 \\ / `-----------' \n"; | |
std::cout << " / --|-- \\ / \n"; | |
std::cout << " / | \\ \n"; | |
std::cout << " / / \\ \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
else if (misses == 2) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " / 0 \\ ( Send help! ) \n"; | |
std::cout << " / --|-- \\ / `-----------' \n"; | |
std::cout << " / | \\ / \n"; | |
std::cout << " / / \\ \\ \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
else if (misses == 3) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " /--|--\\ ( Send help! ) \n"; | |
std::cout << " / | \\ / `-----------' \n"; | |
std::cout << " / / \\ \\ / \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
else if (misses == 3) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " /--|--\\ ( Send help! ) \n"; | |
std::cout << " / | \\ / `-----------' \n"; | |
std::cout << " / / \\ \\ / \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
else if (misses == 4) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " / | \\ ( Send help! ) \n"; | |
std::cout << " / / \\ \\ / `-----------' \n"; | |
std::cout << " / \\ / \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
else if (misses == 5) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " / / \\ \\ ( Send help! )\n"; | |
std::cout << " / \\ / `-----------' \n"; | |
std::cout << " / \\ / \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
else if (misses == 6) { | |
std::cout << " . \n"; | |
std::cout << " | \n"; | |
std::cout << " .-\"^\"-. \n"; | |
std::cout << " /_....._\\ \n"; | |
std::cout << " .-\"` `\"-. \n"; | |
std::cout << " ( ooo ooo ooo ) \n"; | |
std::cout << " '-.,_________,.-' ,-----------. \n"; | |
std::cout << " / \\ ( Send help! ) \n"; | |
std::cout << " / \\ / `-----------' \n"; | |
std::cout << " / \\ / \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
std::cout << " / \\ \n"; | |
} | |
void end_game(std::string answer, std::string codeword) { | |
if (answer == codeword) { | |
std::cout << "Hooray! You saved the person and earned a medal of honor!\n"; | |
} else { | |
std::cout << "Oh no! The UFO just flew away with another person!\n"; | |
} | |
} | |
} |
This file contains 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
#include <vector> | |
void display_misses(int misses); | |
// Declare functions | |
void greet(); | |
void end_game(std::string answer, std::string codeword); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment