From 4bf4cbeae19f966d2d2c792235f4e53ebb1adc47 Mon Sep 17 00:00:00 2001 From: JohnnyTurbo Date: Wed, 9 Sep 2015 12:46:57 -0700 Subject: [PATCH 01/24] Adding header files for player and computer. --- computer.h | 13 +++++++++++++ player.h | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 computer.h create mode 100644 player.h diff --git a/computer.h b/computer.h new file mode 100644 index 0000000..a708594 --- /dev/null +++ b/computer.h @@ -0,0 +1,13 @@ +#ifndef COMPUTER_H +#define COMPUTER_H + +class Computer{ + + public: + int targetScore; + int turnScore; + int overallScore; + +}; + +#endif diff --git a/player.h b/player.h new file mode 100644 index 0000000..08f6ade --- /dev/null +++ b/player.h @@ -0,0 +1,12 @@ +#ifndef PLAYER_H +#define PLAYER_H + +class Player{ + + public: + int overallScore; + int turnScore; + +}; + +#endif From da523743cfce1ecdafb5eafab7bbb710d1eb484c Mon Sep 17 00:00:00 2001 From: Kendra's Old Date: Wed, 9 Sep 2015 12:48:07 -0700 Subject: [PATCH 02/24] player class --- pigsgame.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pigsgame.h diff --git a/pigsgame.h b/pigsgame.h new file mode 100644 index 0000000..c57f8f4 --- /dev/null +++ b/pigsgame.h @@ -0,0 +1,17 @@ +#ifndef PIGSGAME_H +#define PIGSGAME_H + + +#include +using namespace std; + +class Player +{ + public: + string roll; + string hold; + int score; + string choice; +}; + +#endif From b33d9183bff9e5e01a041fd4814601327fe35a74 Mon Sep 17 00:00:00 2001 From: Kendra's Old Date: Wed, 9 Sep 2015 12:48:20 -0700 Subject: [PATCH 03/24] implemented header file --- pigsgame.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 pigsgame.cpp diff --git a/pigsgame.cpp b/pigsgame.cpp new file mode 100644 index 0000000..b792d9c --- /dev/null +++ b/pigsgame.cpp @@ -0,0 +1,13 @@ +#include "pigsgame.h" + +#include +using namespace std; + +int main() +{ + + + + return 0; + + } From f6a2f73d3e9080935cf49ff46f7d91cf7314d4bc Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 11:09:46 -0700 Subject: [PATCH 04/24] test commit --- pig.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 pig.cpp diff --git a/pig.cpp b/pig.cpp new file mode 100644 index 0000000..751cc4a --- /dev/null +++ b/pig.cpp @@ -0,0 +1 @@ +#include From 57a86e65ac205a65606edc55736094a02a3d26ff Mon Sep 17 00:00:00 2001 From: JohnnyTurbo Date: Mon, 14 Sep 2015 11:25:15 -0700 Subject: [PATCH 05/24] Added in header and cpp files for the computer class. --- computer.cpp | 25 +++++++++++++++++++++++++ computer.h | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 computer.cpp diff --git a/computer.cpp b/computer.cpp new file mode 100644 index 0000000..539f6b2 --- /dev/null +++ b/computer.cpp @@ -0,0 +1,25 @@ +#include +#include "computer.h" +#include +#include "stdlib.h" + +using namespace std; + +void Date::turn(){ + + int diceSides = 6; + + while(turnScore <= targetScore){ + int thisRoll = rand()%diceSides; + if(thisRoll == 0){ + turnScore = 0; + break; + } + else{ + turnScore += thisRoll; + } + } + + overallScore += turnScore; + +} diff --git a/computer.h b/computer.h index a708594..f92dbc2 100644 --- a/computer.h +++ b/computer.h @@ -4,10 +4,14 @@ class Computer{ public: + Date(int i) {targetScore = i; turnScore = 0; overallScore = 0;} int targetScore; int turnScore; int overallScore; + private: + void turn(); + }; #endif From d06038c1c42857dac1e585f2a7a952dd06f2452c Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 11:31:06 -0700 Subject: [PATCH 06/24] made class --- pig.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pig.cpp b/pig.cpp index 751cc4a..ac94b71 100644 --- a/pig.cpp +++ b/pig.cpp @@ -1 +1,12 @@ +#include "Person.h" + #include +#include + +using namespace std; + +int main() +{ + Person p1; + p1.play_game(); +} From ea8adae2189d3ea9a9ab9c76eb3153995d631db2 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 11:32:22 -0700 Subject: [PATCH 07/24] made class --- Person.cpp | 35 +++++++++++++++++++++++++++++++++++ Person.h | 14 ++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Person.cpp create mode 100644 Person.h diff --git a/Person.cpp b/Person.cpp new file mode 100644 index 0000000..22ff81a --- /dev/null +++ b/Person.cpp @@ -0,0 +1,35 @@ +#include "Person.h" + +#include +#include +#include + +using namespace std; + + +Person::Person() +{ + player_total_score = 0; +} + +void Person::play_game() +{ + string user_input; + + cout << "Player, would you to roll, or will you hold?" << endl; + cin >> user_input; + + if(user_input == "roll") + { + cout << "Player rolled" << endl; + } + else if(user_input == "hold") + { + cout << "player decided to hold" << endl; + } + else + { + cout << "not an option" << endl; + } +} + diff --git a/Person.h b/Person.h new file mode 100644 index 0000000..5302361 --- /dev/null +++ b/Person.h @@ -0,0 +1,14 @@ +#include + + +class Person +{ + public: + Person(); + void play_game(); + int player_roll(); + + private: + int player_total_score; + +}; From 2aff0b01631c9fbc0a5e0b845b6131aab7546ea0 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 12:04:11 -0700 Subject: [PATCH 08/24] renamed the main file to match others --- pig.cpp | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 pig.cpp diff --git a/pig.cpp b/pig.cpp deleted file mode 100644 index ac94b71..0000000 --- a/pig.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "Person.h" - -#include -#include - -using namespace std; - -int main() -{ - Person p1; - p1.play_game(); -} From dc59954c2d2c60723b2e27fe55239f0239c631e1 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 12:05:42 -0700 Subject: [PATCH 09/24] renamed the main file to match others --- pigsgame.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 pigsgame.cpp diff --git a/pigsgame.cpp b/pigsgame.cpp new file mode 100644 index 0000000..ac94b71 --- /dev/null +++ b/pigsgame.cpp @@ -0,0 +1,12 @@ +#include "Person.h" + +#include +#include + +using namespace std; + +int main() +{ + Person p1; + p1.play_game(); +} From be1d73b0eb462d2f0612b4c2e05e68b071d1d768 Mon Sep 17 00:00:00 2001 From: Joey Date: Mon, 14 Sep 2015 12:10:34 -0700 Subject: [PATCH 10/24] test commit --- pigsgame.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pigsgame.cpp b/pigsgame.cpp index b792d9c..1d482c0 100644 --- a/pigsgame.cpp +++ b/pigsgame.cpp @@ -5,8 +5,10 @@ using namespace std; int main() { - - + while(1) + { + + } return 0; From fc93351ba16a43ec5f30c54764c52d74e88a5f8f Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 12:29:53 -0700 Subject: [PATCH 11/24] added functionality to player_roll function --- Person.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Person.cpp b/Person.cpp index 22ff81a..db0a9a3 100644 --- a/Person.cpp +++ b/Person.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include using namespace std; @@ -21,7 +23,7 @@ void Person::play_game() if(user_input == "roll") { - cout << "Player rolled" << endl; + cout << "Player rolled a:" << player_roll() << endl; } else if(user_input == "hold") { @@ -31,5 +33,13 @@ void Person::play_game() { cout << "not an option" << endl; } +} + +int Person::player_roll() +{ + int dice_roll; + srand(time(NULL)); + dice_roll = (rand()%6) + 1; + return dice_roll; } From 0a4c7d666f165241cefcac2d96d439e1628aa38c Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 14:13:47 -0700 Subject: [PATCH 12/24] player can roll and hold, adds running total and doesnt add anything if 1 is rolled --- Person.cpp | 62 ++++++++++++++++++++++++++++++++++++++---------------- Person.h | 2 +- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/Person.cpp b/Person.cpp index db0a9a3..2a6878e 100644 --- a/Person.cpp +++ b/Person.cpp @@ -11,28 +11,54 @@ using namespace std; Person::Person() { - player_total_score = 0; + *player_total_score = 0; } void Person::play_game() { - string user_input; - - cout << "Player, would you to roll, or will you hold?" << endl; - cin >> user_input; - - if(user_input == "roll") - { - cout << "Player rolled a:" << player_roll() << endl; - } - else if(user_input == "hold") - { - cout << "player decided to hold" << endl; - } - else - { - cout << "not an option" << endl; - } + string initial_input; + int roll_value = 0; + int current_roll = 0; + int running_total = 0; + + + cout << "Player, your total score is: " << *player_total_score << endl; + cout << "Player, would you like to roll, or will you hold?" << endl; + getline(cin, initial_input); + + while(initial_input != "hold" && current_roll == 0) + { + cout << "Player, your total score is: " << *player_total_score << endl; + current_roll = player_roll(); + + cout << "You rolled a: " << current_roll << endl; + if(current_roll == 1) + { + break; + } + running_total += current_roll; + + cout << "So far, your score for this round is: " << running_total << endl; + cout << "Player, would you like to roll, or will you hold?" << endl; + getline(cin, initial_input); + current_roll = 0; + continue; + } + + if(current_roll == 1) + { + cout << "You rolled a 1, no points added for current turn" << endl; + running_total = 0; + *player_total_score += running_total; + cout << "Your score is still: " << *player_total_score << endl; + } + + if(initial_input == "hold") + { + cout << "player decided to hold" << endl; + *player_total_score += running_total; + cout << "Your score is: " << *player_total_score << endl; + } } int Person::player_roll() diff --git a/Person.h b/Person.h index 5302361..12aa6ec 100644 --- a/Person.h +++ b/Person.h @@ -9,6 +9,6 @@ class Person int player_roll(); private: - int player_total_score; + int *player_total_score; }; From 8343b295a636e0897972ace18afb2a1f05187787 Mon Sep 17 00:00:00 2001 From: Isaac Beadle Ramirez Date: Mon, 14 Sep 2015 14:57:11 -0700 Subject: [PATCH 13/24] Delete pigsgame.cpp --- pigsgame.cpp | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 pigsgame.cpp diff --git a/pigsgame.cpp b/pigsgame.cpp deleted file mode 100644 index b792d9c..0000000 --- a/pigsgame.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "pigsgame.h" - -#include -using namespace std; - -int main() -{ - - - - return 0; - - } From a8a0ddb4ce8bb282ea199933c07ee7d70d9464c0 Mon Sep 17 00:00:00 2001 From: Isaac Beadle Ramirez Date: Mon, 14 Sep 2015 14:57:24 -0700 Subject: [PATCH 14/24] Delete pigsgame.h --- pigsgame.h | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 pigsgame.h diff --git a/pigsgame.h b/pigsgame.h deleted file mode 100644 index c57f8f4..0000000 --- a/pigsgame.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef PIGSGAME_H -#define PIGSGAME_H - - -#include -using namespace std; - -class Player -{ - public: - string roll; - string hold; - int score; - string choice; -}; - -#endif From db5708a5acb43a7296a02cc08d36bd86384eedfe Mon Sep 17 00:00:00 2001 From: Isaac Beadle Ramirez Date: Mon, 14 Sep 2015 14:57:31 -0700 Subject: [PATCH 15/24] Delete player.h --- player.h | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 player.h diff --git a/player.h b/player.h deleted file mode 100644 index 08f6ade..0000000 --- a/player.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PLAYER_H -#define PLAYER_H - -class Player{ - - public: - int overallScore; - int turnScore; - -}; - -#endif From 7c51f29ba1b6ec7bec1101463d2198402e6e9300 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 15:28:28 -0700 Subject: [PATCH 16/24] created Makefile and renamed Person.h and .cpp to person.h and .cpp --- Makefile | 16 ++++++++++++++++ computer.cpp | 33 ++++++++++++++------------------- computer.h | 15 +++++++-------- Person.cpp => person.cpp | 10 ++++++++-- Person.h => person.h | 5 +++++ pigsgame.cpp | 2 +- 6 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 Makefile rename Person.cpp => person.cpp (92%) rename Person.h => person.h (76%) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c3f79b2 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +all: pig + +pig: pigsgame.o person.o computer.o + g++ pigsgame.o person.o computer.o -o pig + +pigsgame.o: pigsgame.cpp + g++ -c pigsgame.cpp + +person.o: person.cpp + g++ -c person.cpp + +computer.o: computer.cpp + g++ -c computer.cpp + +clean: + rm *o pig diff --git a/computer.cpp b/computer.cpp index 539f6b2..ed50c69 100644 --- a/computer.cpp +++ b/computer.cpp @@ -1,25 +1,20 @@ -#include #include "computer.h" -#include -#include "stdlib.h" +#include "person.h" -using namespace std; +#include +#include +#include +#include -void Date::turn(){ - - int diceSides = 6; +using namespace std; - while(turnScore <= targetScore){ - int thisRoll = rand()%diceSides; - if(thisRoll == 0){ - turnScore = 0; - break; - } - else{ - turnScore += thisRoll; - } - } - - overallScore += turnScore; +Computer::Computer() +{ + computer_total_score = 0; +} +void Computer::play_game() +{ + cout << "Computer is now playing!" << endl; + cout << "Computers score is: " << computer_total_score << endl; } diff --git a/computer.h b/computer.h index f92dbc2..133fe81 100644 --- a/computer.h +++ b/computer.h @@ -1,16 +1,15 @@ #ifndef COMPUTER_H #define COMPUTER_H -class Computer{ - +class Computer +{ public: - Date(int i) {targetScore = i; turnScore = 0; overallScore = 0;} - int targetScore; - int turnScore; - int overallScore; - + Computer(); + void play_game(); + int computer_roll; + private: - void turn(); + int *computer_total_score; }; diff --git a/Person.cpp b/person.cpp similarity index 92% rename from Person.cpp rename to person.cpp index 2a6878e..31f8a92 100644 --- a/Person.cpp +++ b/person.cpp @@ -1,4 +1,5 @@ -#include "Person.h" +#include "person.h" +#include "computer.h" #include #include @@ -28,7 +29,6 @@ void Person::play_game() while(initial_input != "hold" && current_roll == 0) { - cout << "Player, your total score is: " << *player_total_score << endl; current_roll = player_roll(); cout << "You rolled a: " << current_roll << endl; @@ -51,6 +51,9 @@ void Person::play_game() running_total = 0; *player_total_score += running_total; cout << "Your score is still: " << *player_total_score << endl; + + Computer c1; + c1.play_game(); } if(initial_input == "hold") @@ -58,6 +61,9 @@ void Person::play_game() cout << "player decided to hold" << endl; *player_total_score += running_total; cout << "Your score is: " << *player_total_score << endl; + + Computer c1; + c1.play_game(); } } diff --git a/Person.h b/person.h similarity index 76% rename from Person.h rename to person.h index 12aa6ec..b2b0d8b 100644 --- a/Person.h +++ b/person.h @@ -1,3 +1,6 @@ +#ifndef PERSON_H +#define PERSON_H + #include @@ -12,3 +15,5 @@ class Person int *player_total_score; }; + +#endif diff --git a/pigsgame.cpp b/pigsgame.cpp index ac94b71..6573e79 100644 --- a/pigsgame.cpp +++ b/pigsgame.cpp @@ -1,4 +1,4 @@ -#include "Person.h" +#include "person.h" #include #include From c10728c7e4632733c34bb257fba980e1ad928ed5 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 17:49:41 -0700 Subject: [PATCH 17/24] added functionality to computer_roll() function --- computer.cpp | 9 +++++++++ computer.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/computer.cpp b/computer.cpp index ed50c69..a11ecd5 100644 --- a/computer.cpp +++ b/computer.cpp @@ -17,4 +17,13 @@ void Computer::play_game() { cout << "Computer is now playing!" << endl; cout << "Computers score is: " << computer_total_score << endl; + cout << "Computers initial roll is: " << computer_roll() << endl; +} + +int Computer::computer_roll() +{ + int dice_roll; + srand(time(NULL)); + dice_roll = (rand()%6) + 1; + return dice_roll; } diff --git a/computer.h b/computer.h index 133fe81..2c5db56 100644 --- a/computer.h +++ b/computer.h @@ -6,7 +6,7 @@ class Computer public: Computer(); void play_game(); - int computer_roll; + int computer_roll(); private: int *computer_total_score; From e89ecb22334be69ea386693edde48d5ef5634e06 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 18:51:37 -0700 Subject: [PATCH 18/24] test --- computer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/computer.cpp b/computer.cpp index a11ecd5..aca141d 100644 --- a/computer.cpp +++ b/computer.cpp @@ -15,9 +15,15 @@ Computer::Computer() void Computer::play_game() { + int roll_value = 0; + int current_roll = 0; + int running_total = 0; + cout << "Computer is now playing!" << endl; cout << "Computers score is: " << computer_total_score << endl; - cout << "Computers initial roll is: " << computer_roll() << endl; + + current_roll = computer_roll(); + } int Computer::computer_roll() From 3f0ece966c22addcfcaa60c4a9b0762793b30568 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 18:56:55 -0700 Subject: [PATCH 19/24] testing --- computer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/computer.cpp b/computer.cpp index ed50c69..c699f4a 100644 --- a/computer.cpp +++ b/computer.cpp @@ -17,4 +17,5 @@ void Computer::play_game() { cout << "Computer is now playing!" << endl; cout << "Computers score is: " << computer_total_score << endl; + cout << "time to roll" << endl; } From 3733cf1e31068bb7ff1a3ba9b748c3a0182b1a00 Mon Sep 17 00:00:00 2001 From: Isaac Beadle Ramirez Date: Mon, 14 Sep 2015 19:05:03 -0700 Subject: [PATCH 20/24] Delete pigsgame.cpp --- pigsgame.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 pigsgame.cpp diff --git a/pigsgame.cpp b/pigsgame.cpp deleted file mode 100644 index 04bf16f..0000000 --- a/pigsgame.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "person.h" - -#include -#include - -using namespace std; - -int main() -{ -<<<<<<< HEAD - while(1) - { - - } - - return 0; - - } -======= - Person p1; - p1.play_game(); -} ->>>>>>> c10728c7e4632733c34bb257fba980e1ad928ed5 From 62945ce574555de21dbf803f4a7890874b214eb4 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 19:20:03 -0700 Subject: [PATCH 21/24] made comment person.h --- person.h | 1 + 1 file changed, 1 insertion(+) diff --git a/person.h b/person.h index b2b0d8b..95263e5 100644 --- a/person.h +++ b/person.h @@ -7,6 +7,7 @@ class Person { public: + // entered comment Person(); void play_game(); int player_roll(); From dfaef41236746c88629575b37b59b30072c7dcba Mon Sep 17 00:00:00 2001 From: JohnnyTurbo Date: Mon, 14 Sep 2015 19:24:34 -0700 Subject: [PATCH 22/24] Completed the computer AI and modified the person and pigsgame files to properly play the game. --- computer.cpp | 64 +++++++++++++++++++++++++++++++++------------ computer.h | 16 ++++++------ person.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ person.h | 20 ++++++++++++++ pigsgame.cpp | 31 ++++++++++++++++------ 5 files changed, 172 insertions(+), 32 deletions(-) create mode 100644 person.cpp create mode 100644 person.h diff --git a/computer.cpp b/computer.cpp index 539f6b2..07d8854 100644 --- a/computer.cpp +++ b/computer.cpp @@ -1,25 +1,57 @@ -#include #include "computer.h" -#include -#include "stdlib.h" +#include "person.h" + +#include +#include +#include +#include using namespace std; -void Date::turn(){ +Computer::Computer() +{ + computer_total_score = 0; + target_score = 12; +} + +void Computer::play_game() +{ + + int this_roll; + int this_turn = 0; + bool playing = true; + + cout << "Computer is now playing!" << endl; + + while(playing){ + this_roll = computer_roll(); + this_turn += this_roll; - int diceSides = 6; + if(this_roll == 1){ + this_turn = 0; + cout << "Computer rolled a 1, no points were added for the current turn" + << endl; + playing = false; + } - while(turnScore <= targetScore){ - int thisRoll = rand()%diceSides; - if(thisRoll == 0){ - turnScore = 0; - break; - } - else{ - turnScore += thisRoll; - } + else if (this_turn >= target_score){ + cout << "Computer rolled a: " << this_roll << endl + << "Computer decided to hold" << endl; + playing = false; } - - overallScore += turnScore; + else{ + cout << "Computer rolled a: " << this_roll << endl + << "Computer's score for this round is: " << this_turn << endl; + } + } + computer_total_score += this_turn; + cout << "Computer's total score is: " << computer_total_score << endl; +} +int Computer::computer_roll() +{ + int dice_roll; + srand(time(NULL)); + dice_roll = (rand()%6) + 1; + return dice_roll; } diff --git a/computer.h b/computer.h index f92dbc2..74e31bc 100644 --- a/computer.h +++ b/computer.h @@ -1,16 +1,16 @@ #ifndef COMPUTER_H #define COMPUTER_H -class Computer{ - +class Computer +{ public: - Date(int i) {targetScore = i; turnScore = 0; overallScore = 0;} - int targetScore; - int turnScore; - int overallScore; - + Computer(); + void play_game(); + int computer_roll(); + int getScore(){return computer_total_score;} private: - void turn(); + int computer_total_score; + int target_score; }; diff --git a/person.cpp b/person.cpp new file mode 100644 index 0000000..0d35e59 --- /dev/null +++ b/person.cpp @@ -0,0 +1,73 @@ +#include "person.h" +#include "computer.h" + +#include +#include +#include +#include +#include + +using namespace std; + + +Person::Person() +{ + *player_total_score = 0; +} + +void Person::play_game() +{ + string initial_input; + int roll_value = 0; + int current_roll = 0; + int running_total = 0; + + + cout << "Player, your total score is: " << *player_total_score << endl; + cout << "Player, would you like to roll, or will you hold?" << endl; + getline(cin, initial_input); + + while(initial_input != "hold" && current_roll == 0) + { + current_roll = player_roll(); + + cout << "You rolled a: " << current_roll << endl; + if(current_roll == 1) + { + break; + } + running_total += current_roll; + + cout << "So far, your score for this round is: " << running_total << endl; + cout << "Player, would you like to roll, or will you hold?" << endl; + getline(cin, initial_input); + current_roll = 0; + continue; + } + + if(current_roll == 1) + { + cout << "You rolled a 1, no points added for current turn" << endl; + running_total = 0; + *player_total_score += running_total; + cout << "Your score is still: " << *player_total_score << endl; + + } + + if(initial_input == "hold") + { + cout << "player decided to hold" << endl; + *player_total_score += running_total; + cout << "Your score is: " << *player_total_score << endl; + + } +} + +int Person::player_roll() +{ + int dice_roll; + srand(time(NULL)); + dice_roll = (rand()%6) + 1; + return dice_roll; +} + diff --git a/person.h b/person.h new file mode 100644 index 0000000..e9ee05c --- /dev/null +++ b/person.h @@ -0,0 +1,20 @@ +#ifndef PERSON_H +#define PERSON_H + +#include + + +class Person +{ + public: + Person(); + void play_game(); + int player_roll(); + int getScore(){return *player_total_score;} + + private: + int *player_total_score; + +}; + +#endif diff --git a/pigsgame.cpp b/pigsgame.cpp index b792d9c..1eab380 100644 --- a/pigsgame.cpp +++ b/pigsgame.cpp @@ -1,13 +1,28 @@ -#include "pigsgame.h" +#include "person.h" +#include "computer.h" + +#include +#include -#include using namespace std; int main() { - - - - return 0; - - } + Person p1; + Computer c1; + bool playing = true; + + while(playing){ + p1.play_game(); + if(p1.getScore() >= 100){ + cout << "Congradulations you beat the computer!" << endl; + playing = false; + break; + } + c1.play_game(); + if(c1.getScore() >= 100){ + cout << "Too bad the computer beat you! Try again!" << endl; + playing = false; + } + } +} From 89f7405109f16d4e8d1464cd76163b504dd0a220 Mon Sep 17 00:00:00 2001 From: icebramz Date: Mon, 14 Sep 2015 19:25:06 -0700 Subject: [PATCH 23/24] int i in person.h --- person.h | 1 + 1 file changed, 1 insertion(+) diff --git a/person.h b/person.h index 95263e5..e41e095 100644 --- a/person.h +++ b/person.h @@ -14,6 +14,7 @@ class Person private: int *player_total_score; + int i; }; From 3e92e0ca70894eef84b9dfb6770d8a1f858dbe9f Mon Sep 17 00:00:00 2001 From: icebramz Date: Tue, 15 Sep 2015 17:18:38 -0700 Subject: [PATCH 24/24] fixed initialization issue that was causing segfault --- person.cpp | 12 ++++++------ person.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/person.cpp b/person.cpp index 5459fa4..1bcdaff 100644 --- a/person.cpp +++ b/person.cpp @@ -12,7 +12,7 @@ using namespace std; Person::Person() { - *player_total_score = 0; + player_total_score = 0; } void Person::play_game() @@ -23,7 +23,7 @@ void Person::play_game() int running_total = 0; - cout << "Player, your total score is: " << *player_total_score << endl; + cout << "Player, your total score is: " << player_total_score << endl; cout << "Player, would you like to roll, or will you hold?" << endl; getline(cin, initial_input); @@ -49,15 +49,15 @@ void Person::play_game() { cout << "You rolled a 1, no points added for current turn" << endl; running_total = 0; - *player_total_score += running_total; - cout << "Your score is still: " << *player_total_score << endl; + player_total_score += running_total; + cout << "Your score is still: " << player_total_score << endl; } if(initial_input == "hold") { cout << "player decided to hold" << endl; - *player_total_score += running_total; - cout << "Your score is: " << *player_total_score << endl; + player_total_score += running_total; + cout << "Your score is: " << player_total_score << endl; } } diff --git a/person.h b/person.h index e9ee05c..b23b08f 100644 --- a/person.h +++ b/person.h @@ -10,10 +10,10 @@ class Person Person(); void play_game(); int player_roll(); - int getScore(){return *player_total_score;} + int getScore(){return player_total_score;} private: - int *player_total_score; + int player_total_score; };