From fcefe95020fc15666328f6bb3621cebddc0fe650 Mon Sep 17 00:00:00 2001 From: Jonathan Allen Date: Wed, 9 Sep 2015 12:30:49 -0700 Subject: [PATCH 01/10] finished the player cpp and h --- .player.h.swp | Bin 0 -> 12288 bytes player.cpp | 20 ++++++++++++++++++++ player.h | 14 ++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 .player.h.swp create mode 100644 player.cpp create mode 100644 player.h diff --git a/.player.h.swp b/.player.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..e9f3a22862ac6781a104a644cb305e3eddadd90b GIT binary patch literal 12288 zcmeI&%SyvQ6b9g_d#iZaxEk$7kzTxj(u$}cUZ_y272Q~-$+V6%laNdbBI?#>a4)`q zzJzPH`UHYLf+uZMa8v27@(=tO<}f)7-!5coxx<}3zLZ&HG=>>_zWJz3BsiNLXY9KxWvkPW5MG){( z`hnsAi> literal 0 HcmV?d00001 diff --git a/player.cpp b/player.cpp new file mode 100644 index 0000000..6938326 --- /dev/null +++ b/player.cpp @@ -0,0 +1,20 @@ +#include +#include"player.h" +using namespace std; + +Player::Player() +{ + m_score = 0; +} + +Player::update_score(int turn_score) +{ + m_score = m_score + turn_score; + return m_score; +} + +Player::get_score() +{ + return m_score; +} + diff --git a/player.h b/player.h new file mode 100644 index 0000000..6f2158d --- /dev/null +++ b/player.h @@ -0,0 +1,14 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include +using namespace std; + +class Player +{ + public: + int update_score(int turn_score); + void get_score(); + private: + int m_score; +} From f85dc228ba7ad00fb45d787fa6a62534b368ddbd Mon Sep 17 00:00:00 2001 From: Sam Langon Date: Wed, 9 Sep 2015 12:33:24 -0700 Subject: [PATCH 02/10] Created game header and source --- game.cpp | 35 +++++++++++++++++++++++++++++++++++ game.h | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 game.cpp create mode 100644 game.h diff --git a/game.cpp b/game.cpp new file mode 100644 index 0000000..6256821 --- /dev/null +++ b/game.cpp @@ -0,0 +1,35 @@ +#include +#include "game.h" +#include "player.h" +using namespace std; + +Game::Game() +{ + Player player = new Player(); + Player computer = new Player(); +} + +void Game::turn(int roll, Player current_player) +{ + bool player_keeps_playing; + string userInput; + while (player_keeps_playing) + { + cout << "Would you like to roll again? (yes or no)" << endl; + cin >> userInput; + if (userInput == "yes") + player_keeps_playing == true; + else + { + total_score += round_score; + current_player.update_score(total_score); + player_keeps_playing = false; + return; + } + if (roll == 1) + { + round_score = 0; + return; + } + } +} \ No newline at end of file diff --git a/game.h b/game.h new file mode 100644 index 0000000..e4a1a89 --- /dev/null +++ b/game.h @@ -0,0 +1,19 @@ +#ifndef GAME_H +#define GAME_H + +#include +using namespace std; + +class Game +{ +public: + Game(); + void turn(); + + +private: + int round_score; + +}; + +#endif From 1a47cab35fb1b4aa025217bb6f3c92efbb39b730 Mon Sep 17 00:00:00 2001 From: Jonathan Allen Date: Wed, 9 Sep 2015 12:42:43 -0700 Subject: [PATCH 03/10] test --- player.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/player.cpp b/player.cpp index 6938326..28c3c6d 100644 --- a/player.cpp +++ b/player.cpp @@ -5,6 +5,7 @@ using namespace std; Player::Player() { m_score = 0; + //test } Player::update_score(int turn_score) From abe95eb13fdddf96570f66d42c9d8e7512b1e51e Mon Sep 17 00:00:00 2001 From: Jonathan Allen Date: Wed, 9 Sep 2015 12:45:19 -0700 Subject: [PATCH 04/10] testing new bnranch --- player.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/player.cpp b/player.cpp index 28c3c6d..6938326 100644 --- a/player.cpp +++ b/player.cpp @@ -5,7 +5,6 @@ using namespace std; Player::Player() { m_score = 0; - //test } Player::update_score(int turn_score) From 42789bf7fa0b563fe02473fe62f4211813eb2f03 Mon Sep 17 00:00:00 2001 From: Chumbeto Date: Wed, 9 Sep 2015 12:46:25 -0700 Subject: [PATCH 05/10] adding die.h and die.cpp with a working roll() class that returns a different int every time it is called from 1-6 --- die.cpp | 16 ++++++++++++++++ die.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 die.cpp create mode 100644 die.h diff --git a/die.cpp b/die.cpp new file mode 100644 index 0000000..b26e047 --- /dev/null +++ b/die.cpp @@ -0,0 +1,16 @@ +/* + * die.cpp + * date - 9/9/2015 +*/ +#include "die.h" +#include +#include +#include + + +int Die::roll() +{ +srand(time(0)); +die_result = (rand() % 6 + 1); +return die_result; +} diff --git a/die.h b/die.h new file mode 100644 index 0000000..9660cdf --- /dev/null +++ b/die.h @@ -0,0 +1,18 @@ +#ifndef DIE_H +#define DIE_H +#include +using namespace std; + +class Die +{ + public: + + int roll(); // returns a random number from 1-6 + + + private: + + int die_result; // actual die roll value + +}; +#endif From f38ae41de5ffe7abe6db0c20158d3a99c257aaf9 Mon Sep 17 00:00:00 2001 From: Chumbeto Date: Mon, 14 Sep 2015 11:16:43 -0700 Subject: [PATCH 06/10] updated die.h and die.cpp --- die.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/die.cpp b/die.cpp index b26e047..f75bf3b 100644 --- a/die.cpp +++ b/die.cpp @@ -10,7 +10,8 @@ int Die::roll() { -srand(time(0)); +//srand(time(0)); //needs to be called in main once +//and not in a loop die_result = (rand() % 6 + 1); return die_result; } From 9fa811fc2233532551d9a7d61d6941700235e7f7 Mon Sep 17 00:00:00 2001 From: Chumbeto Date: Mon, 14 Sep 2015 11:27:11 -0700 Subject: [PATCH 07/10] Added constructor to Die class --- die.cpp | 14 +++++++++----- die.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/die.cpp b/die.cpp index f75bf3b..9e24839 100644 --- a/die.cpp +++ b/die.cpp @@ -1,17 +1,21 @@ /* * die.cpp * date - 9/9/2015 -*/ + */ #include "die.h" #include #include #include +Die::Die() +{ +} + int Die::roll() { -//srand(time(0)); //needs to be called in main once -//and not in a loop -die_result = (rand() % 6 + 1); -return die_result; + //srand(time(0)); //needs to be called in main once + //and not in a loop + die_result = (rand() % 6 + 1); + return die_result; } diff --git a/die.h b/die.h index 9660cdf..8e94aa0 100644 --- a/die.h +++ b/die.h @@ -8,6 +8,7 @@ class Die public: int roll(); // returns a random number from 1-6 + Die(); // Die ctor private: From 6b574861d43bb0b7b9b56eaa346a395275ed7120 Mon Sep 17 00:00:00 2001 From: JakeDame Date: Mon, 14 Sep 2015 11:31:00 -0700 Subject: [PATCH 08/10] changed update_score to return bool, types added to functions --- .player.h.swp | Bin 12288 -> 0 bytes player.cpp | 11 +++++++---- player.h | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) delete mode 100644 .player.h.swp diff --git a/.player.h.swp b/.player.h.swp deleted file mode 100644 index e9f3a22862ac6781a104a644cb305e3eddadd90b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&%SyvQ6b9g_d#iZaxEk$7kzTxj(u$}cUZ_y272Q~-$+V6%laNdbBI?#>a4)`q zzJzPH`UHYLf+uZMa8v27@(=tO<}f)7-!5coxx<}3zLZ&HG=>>_zWJz3BsiNLXY9KxWvkPW5MG){( z`hnsAi> diff --git a/player.cpp b/player.cpp index 6938326..2074c88 100644 --- a/player.cpp +++ b/player.cpp @@ -1,4 +1,3 @@ -#include #include"player.h" using namespace std; @@ -7,13 +6,17 @@ Player::Player() m_score = 0; } -Player::update_score(int turn_score) +bool Player::update_score(int turn_score) { m_score = m_score + turn_score; - return m_score; + + if(m_score >= 100) + return true; + else + return false; } -Player::get_score() +int Player::get_score() { return m_score; } diff --git a/player.h b/player.h index 6f2158d..9cac17c 100644 --- a/player.h +++ b/player.h @@ -1,14 +1,13 @@ #ifndef PLAYER_H #define PLAYER_H -#include using namespace std; class Player { public: - int update_score(int turn_score); - void get_score(); + bool update_score(int turn_score); + int get_score(); private: int m_score; } From fea8b6dba98e510fd95a36e572ae7cecd31df5b9 Mon Sep 17 00:00:00 2001 From: Sam Langon Date: Mon, 14 Sep 2015 11:35:19 -0700 Subject: [PATCH 09/10] Reworked the logic for turns --- .player.h.swp | Bin 12288 -> 0 bytes game.cpp | 49 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) delete mode 100644 .player.h.swp diff --git a/.player.h.swp b/.player.h.swp deleted file mode 100644 index e9f3a22862ac6781a104a644cb305e3eddadd90b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&%SyvQ6b9g_d#iZaxEk$7kzTxj(u$}cUZ_y272Q~-$+V6%laNdbBI?#>a4)`q zzJzPH`UHYLf+uZMa8v27@(=tO<}f)7-!5coxx<}3zLZ&HG=>>_zWJz3BsiNLXY9KxWvkPW5MG){( z`hnsAi> diff --git a/game.cpp b/game.cpp index 6256821..3d04611 100644 --- a/game.cpp +++ b/game.cpp @@ -1,35 +1,52 @@ #include #include "game.h" #include "player.h" +#include "die.h" using namespace std; Game::Game() { Player player = new Player(); Player computer = new Player(); + Die die = new Die(); } -void Game::turn(int roll, Player current_player) +void Game::turn(Player current_player) { bool player_keeps_playing; string userInput; while (player_keeps_playing) + { + cout << "Would you like to roll again? (yes or no)" << endl; + cin >> userInput; + if (userInput == "yes") { - cout << "Would you like to roll again? (yes or no)" << endl; - cin >> userInput; - if (userInput == "yes") - player_keeps_playing == true; + player_keeps_playing == true; + roll = die.roll(); + round_score += roll; + } + else + { + total_score += round_score; + current_player.update_score(total_score); + player_keeps_playing = false; + } + if (roll == 1) + { + round_score = 0; + player_keeps_playing = false; + } + else if (update_score(current_player) == true) + { + if (current_player == computer) + cout << "Game over! Computer beat you!" << endl; else - { - total_score += round_score; - current_player.update_score(total_score); - player_keeps_playing = false; - return; - } - if (roll == 1) - { - round_score = 0; - return; - } + cout << "Game over! You beat a computer, you should be proud of yourself." << endl; } + } + if (current_player == player) + current_player = computer; + else + current_player = player; + turn(current_player); } \ No newline at end of file From 2cc46e87693292ac683e4f41900e0e670b6dc11f Mon Sep 17 00:00:00 2001 From: Sam Langon Date: Mon, 14 Sep 2015 15:39:48 -0700 Subject: [PATCH 10/10] Pushed everyone's changes to master, not compiling just yet --- Makefile | 13 +++++++++++++ game.cpp | 32 +++++++++++--------------------- game.h | 10 ++++++---- main.cpp | 28 ++++++++++++++++++++++++++++ player.cpp | 4 ++-- player.h | 9 +++++---- 6 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 Makefile create mode 100644 main.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c4ec412 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +pigs: Game.o Die.o Player.o Main.o + +Main.o: main.cpp game.h die.h player.h + g++ -c main.cpp + +Game.o: game.cpp game.h die.h player.h + g++ -c game.cpp + +Die.o: die.cpp die.h + g++ -c die.cpp + +Player.o: player.cpp player.h + g++ -c player.cpp \ No newline at end of file diff --git a/game.cpp b/game.cpp index 3d04611..8626cd7 100644 --- a/game.cpp +++ b/game.cpp @@ -1,52 +1,42 @@ #include #include "game.h" -#include "player.h" -#include "die.h" + using namespace std; Game::Game() { - Player player = new Player(); - Player computer = new Player(); - Die die = new Die(); } void Game::turn(Player current_player) { bool player_keeps_playing; string userInput; + int roll; + Die *test = new Die(); + while (player_keeps_playing) { cout << "Would you like to roll again? (yes or no)" << endl; cin >> userInput; if (userInput == "yes") { - player_keeps_playing == true; - roll = die.roll(); - round_score += roll; + player_keeps_playing = true; + roll = test->roll(); + turn_score += roll; } else { - total_score += round_score; - current_player.update_score(total_score); + current_player.update_score(current_player, turn_score); player_keeps_playing = false; } if (roll == 1) { - round_score = 0; + turn_score = 0; player_keeps_playing = false; } - else if (update_score(current_player) == true) + else if (current_player.update_score(current_player, turn_score) == true) { - if (current_player == computer) - cout << "Game over! Computer beat you!" << endl; - else - cout << "Game over! You beat a computer, you should be proud of yourself." << endl; + return; } } - if (current_player == player) - current_player = computer; - else - current_player = player; - turn(current_player); } \ No newline at end of file diff --git a/game.h b/game.h index e4a1a89..d32125f 100644 --- a/game.h +++ b/game.h @@ -1,6 +1,9 @@ #ifndef GAME_H #define GAME_H +#include "player.h" +#include "die.h" + #include using namespace std; @@ -8,12 +11,11 @@ class Game { public: Game(); - void turn(); - + void turn(Player current_player); private: - int round_score; - + int turn_score; + }; #endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..deadbda --- /dev/null +++ b/main.cpp @@ -0,0 +1,28 @@ +#include "game.h" +#include "player.h" + +using namespace std; + +int main() +{ + Game game; + + Player *player = new Player(); + Player *computer = new Player(); + Player *current_player = player; + + while (player->get_score() < 100 || computer->get_score() < 100) + { + if (current_player == player) + current_player = computer; + else + current_player = player; + game.turn(current_player); + } + if (current_player == computer) + cout << "Game over! Computer beat you!" << endl; + else + cout << "Game over! You beat a computer, you should be proud of yourself." << endl; + + return 0; +} \ No newline at end of file diff --git a/player.cpp b/player.cpp index 2074c88..71940bc 100644 --- a/player.cpp +++ b/player.cpp @@ -6,11 +6,11 @@ Player::Player() m_score = 0; } -bool Player::update_score(int turn_score) +bool Player::update_score(Player ¤t_player, int turn_score) { m_score = m_score + turn_score; - if(m_score >= 100) + if(current_player.get_score() >= 100) return true; else return false; diff --git a/player.h b/player.h index 9cac17c..870f230 100644 --- a/player.h +++ b/player.h @@ -1,13 +1,14 @@ #ifndef PLAYER_H #define PLAYER_H -using namespace std; - class Player { public: - bool update_score(int turn_score); + Player(); + bool update_score(Player ¤t_player, int turn_score); int get_score(); private: int m_score; -} +}; + +#endif