From 8fa1c87da04062bae280ac523b61522903fdde6f Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 27 Nov 2016 17:25:52 -0600 Subject: [PATCH 1/7] Initial commit - C++ --- .gitignore | 4 +++ CMakeLists.txt | 5 ++++ README.md | 19 ++++++++++++ ngg.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100755 README.md create mode 100755 ngg.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6bac6fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vs/ +.vscode/ +build/ +.kdev4/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..af5e951 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required (VERSION 3.1) +set (CMAKE_CXX_STANDARD 11) +project (NumberGuessingGame) +add_executable(NumberGuessingGame ngg.cpp) + diff --git a/README.md b/README.md new file mode 100755 index 0000000..1a8cb1f --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Number-Guessing Game +---------------------- +## Gameplay: +1. Computer generates random number +2. Computer starts "I'm thinking of a number..." +3. Player inputs number +4. Computer responds higher, lower, or exact for input +5. 2 & 3 repeat until player guesses number +6. Computer says how many guesses it took + +## Requirements: +* player + * ability to give input + * player's guessed numbers +* computer + * computer's random number + * ability to receive input + * number comparison calculations + * give reply on number diff --git a/ngg.cpp b/ngg.cpp new file mode 100755 index 0000000..f1330c5 --- /dev/null +++ b/ngg.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include + +int getRandomNum() +{ + srand(time(0)); + return rand() % 100 + 1; +} + +int playGame() +{ + // Set up initial values + int playerGuess = 0, computerNum = 0, totalGuesses = 0; + computerNum = getRandomNum(); + std::cout << "I'm thinking of a number between 1 and 100..." << std::endl; + while (playerGuess != computerNum) { + std::cout << "Enter a number: "; + if (std::cin >> playerGuess) { + if (playerGuess > 100 || playerGuess < 1) { + std::cout << "You do know what \"between 1 and 100\" means, right?" << std::endl; + } + else if (playerGuess > computerNum) { + std::cout << "That number is too big!" << std::endl; + } + else if (playerGuess < computerNum) { + std::cout << "That number is too small!" << std::endl; + } + } + else { + std::cout << "Dafuq is that?" << std::endl; + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + } + totalGuesses++; + } + std::cout << "You won! It took you " << totalGuesses << " tries to guess the right number!" << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); + return 0; +} + +int playAgain() +{ + int playAgain = 0; + std::string playerResponse = ""; + while (playAgain == 0) { + std::cout << "Would you like to play again? (Yes/No)" << std::endl; + if (std::cin >> playerResponse) { + std::string::iterator it; + for (it = playerResponse.begin(); it < playerResponse.end(); it++) { + *it = std::tolower(*it); + } + if (playerResponse == "yes" || playerResponse == "y") { + playGame(); + } + else if (playerResponse == "no" || playerResponse == "n") { + break; + } + else { + std::cout << "wut?" << std::endl; + } + } + else { + std::cout << "Dafuq is that?" << std::endl; + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + } + } +} + +int main() +{ + playGame(); + playAgain(); + return 0; +} From 38e3bb899acf64c11f05a7aa6e65ae8e2f8ec24c Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 27 Nov 2016 18:24:52 -0600 Subject: [PATCH 2/7] Moved C++ code to own branch --- CMakeLists.txt | 5 ---- ngg.cpp | 79 -------------------------------------------------- 2 files changed, 84 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100755 ngg.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index af5e951..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required (VERSION 3.1) -set (CMAKE_CXX_STANDARD 11) -project (NumberGuessingGame) -add_executable(NumberGuessingGame ngg.cpp) - diff --git a/ngg.cpp b/ngg.cpp deleted file mode 100755 index f1330c5..0000000 --- a/ngg.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int getRandomNum() -{ - srand(time(0)); - return rand() % 100 + 1; -} - -int playGame() -{ - // Set up initial values - int playerGuess = 0, computerNum = 0, totalGuesses = 0; - computerNum = getRandomNum(); - std::cout << "I'm thinking of a number between 1 and 100..." << std::endl; - while (playerGuess != computerNum) { - std::cout << "Enter a number: "; - if (std::cin >> playerGuess) { - if (playerGuess > 100 || playerGuess < 1) { - std::cout << "You do know what \"between 1 and 100\" means, right?" << std::endl; - } - else if (playerGuess > computerNum) { - std::cout << "That number is too big!" << std::endl; - } - else if (playerGuess < computerNum) { - std::cout << "That number is too small!" << std::endl; - } - } - else { - std::cout << "Dafuq is that?" << std::endl; - std::cin.clear(); - std::cin.ignore(std::numeric_limits::max(), '\n'); - } - totalGuesses++; - } - std::cout << "You won! It took you " << totalGuesses << " tries to guess the right number!" << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - return 0; -} - -int playAgain() -{ - int playAgain = 0; - std::string playerResponse = ""; - while (playAgain == 0) { - std::cout << "Would you like to play again? (Yes/No)" << std::endl; - if (std::cin >> playerResponse) { - std::string::iterator it; - for (it = playerResponse.begin(); it < playerResponse.end(); it++) { - *it = std::tolower(*it); - } - if (playerResponse == "yes" || playerResponse == "y") { - playGame(); - } - else if (playerResponse == "no" || playerResponse == "n") { - break; - } - else { - std::cout << "wut?" << std::endl; - } - } - else { - std::cout << "Dafuq is that?" << std::endl; - std::cin.clear(); - std::cin.ignore(std::numeric_limits::max(), '\n'); - } - } -} - -int main() -{ - playGame(); - playAgain(); - return 0; -} From 71df0736ff95f8198cdaacf0dbf1570f03e65946 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 27 Nov 2016 18:26:22 -0600 Subject: [PATCH 3/7] Cleaned up C++ remainders --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6bac6fe..0000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.vs/ -.vscode/ -build/ -.kdev4/ From f24ea5a242984cbd8f1cc160a6ba7c7ae2244b46 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 27 Nov 2016 18:27:04 -0600 Subject: [PATCH 4/7] Added a simple description to the readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1a8cb1f..7cc57d4 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Number-Guessing Game ---------------------- + +A simple game where the computer picks a number and the player must guess what it is. + ## Gameplay: 1. Computer generates random number 2. Computer starts "I'm thinking of a number..." From 44d2595e0bc11ee8f4cd46f91510d4ff1b741507 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Mon, 28 Nov 2016 02:52:40 -0600 Subject: [PATCH 5/7] Added future challenges --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7cc57d4..bbe035e 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -# Number-Guessing Game ----------------------- - +Number-Guessing Game +-------------------- A simple game where the computer picks a number and the player must guess what it is. ## Gameplay: @@ -20,3 +19,10 @@ A simple game where the computer picks a number and the player must guess what i * ability to receive input * number comparison calculations * give reply on number + +## Future Challenges +* ~~Ask player if they want to play again~~ +* Reverse roles: human picks number and AI guesses +* Multiplayer: play with two humans +* Spectator: play with two AIs +* Menu: select between different game modes \ No newline at end of file From f43515647cece8cf0cf697ee48374b8f8ccd5724 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Mon, 28 Nov 2016 02:55:16 +0000 Subject: [PATCH 6/7] Added another challenge to the README --- README.md | 57 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index bbe035e..cee967c 100755 --- a/README.md +++ b/README.md @@ -1,28 +1,29 @@ -Number-Guessing Game --------------------- -A simple game where the computer picks a number and the player must guess what it is. - -## Gameplay: -1. Computer generates random number -2. Computer starts "I'm thinking of a number..." -3. Player inputs number -4. Computer responds higher, lower, or exact for input -5. 2 & 3 repeat until player guesses number -6. Computer says how many guesses it took - -## Requirements: -* player - * ability to give input - * player's guessed numbers -* computer - * computer's random number - * ability to receive input - * number comparison calculations - * give reply on number - -## Future Challenges -* ~~Ask player if they want to play again~~ -* Reverse roles: human picks number and AI guesses -* Multiplayer: play with two humans -* Spectator: play with two AIs -* Menu: select between different game modes \ No newline at end of file +Number-Guessing Game +-------------------- +A simple game where the computer picks a number and the player must guess what it is. + +## Gameplay: +1. Computer generates random number +2. Computer starts "I'm thinking of a number..." +3. Player inputs number +4. Computer responds higher, lower, or exact for input +5. 2 & 3 repeat until player guesses number +6. Computer says how many guesses it took + +## Requirements: +* player + * ability to give input + * player's guessed numbers +* computer + * computer's random number + * ability to receive input + * number comparison calculations + * give reply on number + +## Future Challenges +* ~~Ask player if they want to play again~~ +* Reverse roles: human picks number and AI guesses +* Multiplayer: play with two humans +* Spectator: play with two AIs +* Menu: select between different game modes +* Build a GUI \ No newline at end of file From 8f7e9fbf26e64ae81cd2774fdc37900996c5fe47 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Tue, 29 Nov 2016 12:05:05 -0600 Subject: [PATCH 7/7] Added git commands reference to README --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cee967c..f76020d 100755 --- a/README.md +++ b/README.md @@ -26,4 +26,40 @@ A simple game where the computer picks a number and the player must guess what i * Multiplayer: play with two humans * Spectator: play with two AIs * Menu: select between different game modes -* Build a GUI \ No newline at end of file +* Build a GUI + +## Contribution +Add the files you changed: +``` +git add ngg.php +``` + +Commit the new changes: +``` +git commit -m "Fixed syntax error" +``` + +Push the changes +``` +git push +``` + +Get the latest code +``` +git pull +``` + +See the changes you've made since your last commit (press Q to exit if it's long enough to scroll) +``` +git diff +``` + +See which branch you're on now +``` +git branch +``` + +Switch to a different branch to see that language's work: +``` +git checkout php +``` \ No newline at end of file