diff --git a/AI.cpp b/AI.cpp new file mode 100644 index 0000000..609ec6d --- /dev/null +++ b/AI.cpp @@ -0,0 +1,26 @@ +#include "AI.h" + +int AI::RollDie(Dice *Die) +{ + int RolledNumber = Die->RollDice(); + + if (RolledNumber == 1) + { + TempScore = 0; + Hold = true; + } + else + { + TempScore += RolledNumber; + if (OverallScore + TempScore >= 100) + { + Set_Hold(true); + } + else if (TempScore > 12) + { + Set_Hold(true); + } + } + + return RolledNumber; +} \ No newline at end of file diff --git a/AI.h b/AI.h new file mode 100644 index 0000000..38beafa --- /dev/null +++ b/AI.h @@ -0,0 +1,13 @@ +#ifndef __AI__ +#define __AI__ + +#include "Player.h" + +class AI : public Player +{ +private: +public: + int RollDie(Dice *Die); +}; + +#endif \ No newline at end of file diff --git a/Dice.cpp b/Dice.cpp new file mode 100644 index 0000000..82183ea --- /dev/null +++ b/Dice.cpp @@ -0,0 +1,13 @@ +#include // For the random number generator +#include // Will use time as the random seed +#include "Dice.h" + +int Dice::RollDice() +{ + srand(time(NULL)); // Uses the current time as the random seed + return rand() % Sides + 1; // Return a random number between 1 and number of sides +} +int Dice::Set_NumSides(int Num) +{ + Sides = Num; +} diff --git a/Dice.h b/Dice.h new file mode 100644 index 0000000..1a3b545 --- /dev/null +++ b/Dice.h @@ -0,0 +1,16 @@ +#ifndef __DICE__ +#define __DICE__ + +#include + +class Dice +{ + private: + int Sides; + public: + Dice(){ Sides = 6; } // Initialize with 6 sides + int RollDice(); + int Set_NumSides(int); +}; + +#endif diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..6cd387b --- /dev/null +++ b/Main.cpp @@ -0,0 +1,69 @@ +#include "Player.h" +#include "AI.h" + +#include +#include + +using namespace std; + +int main() +{ + srand(time(NULL)); + + Player Player1; + AI Computer1; + Dice Die; + + while (!(Player1.Get_Score() >= 100) && !(Computer1.Get_Score() >= 100)) + { + int input = 0; + + while (!Player1.Get_Hold()) + { + cout << "Roll Dice(1) or Hold(2)?" << endl; + cin >> input; + + if (input == 1) + { + int tmp = Player1.RollDie(&Die); + + cout << "Dice Rolled a: " << tmp << endl; + cout << "Running Score is: " << Player1.Get_TempScore() << endl; + cout << "Current Overall Score is: " << Player1.Get_Score() << endl; + } + else if (input == 2) + { + Player1.Set_Hold(true); + + cout << "New Overall Score: " << Player1.Get_Score() << endl; + } + } + + cout << endl; + + while (!Computer1.Get_Hold()) + { + cout << "Computers Rolls: " << Computer1.RollDie(&Die) << endl; + } + + cout << "Computers New Overall Score: " << Computer1.Get_Score() << endl; + + cout << endl; + + Player1.Set_Hold(false); + Computer1.Set_Hold(false); + } + + if (Player1.Get_Score() >= 100) + { + cout << "Player One is the winner!!!"; + } + else + { + cout << "The Computer is the winner!!!"; + } + cin.ignore(); + cin.get(); + + return 0; +} \ No newline at end of file diff --git a/Player.cpp b/Player.cpp new file mode 100644 index 0000000..c281471 --- /dev/null +++ b/Player.cpp @@ -0,0 +1,46 @@ +#include "Player.h" + +int Player::RollDie(Dice *Die) +{ + int RolledNumber = Die->RollDice(); + + if (RolledNumber == 1) + { + TempScore = 0; + Hold = true; + } + else + { + TempScore += RolledNumber; + } + return RolledNumber; +} + +bool Player::Get_Hold() +{ + return Hold; +} + +void Player::Set_Hold(bool toHold) +{ + if (toHold) + { + OverallScore += TempScore; + TempScore = 0; + Hold = toHold; + } + else + { + Hold = false; + } +} + +int Player::Get_Score() +{ + return OverallScore; +} + +int Player::Get_TempScore() +{ + return TempScore; +} \ No newline at end of file diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..2f9c721 --- /dev/null +++ b/Player.h @@ -0,0 +1,26 @@ +#ifndef __PLAYER__ +#define __PLAYER__ + +#include "Dice.h" + +class Player +{ +protected: + int TempScore; + int OverallScore; + bool Hold; + +public: + + + Player() : TempScore(0), OverallScore(0), Hold(false) + {} + + virtual int RollDie(Dice *Die); //Roll of non 1 adds to TempScore, roll of 1: TempScore = 0 + bool Get_Hold(); + void Set_Hold(bool); + int Get_Score(); + int Get_TempScore(); +}; + +#endif \ No newline at end of file