Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions AI.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions AI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __AI__
#define __AI__

#include "Player.h"

class AI : public Player
{
private:
public:
int RollDie(Dice *Die);
};

#endif
13 changes: 13 additions & 0 deletions Dice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <cstdlib> // For the random number generator
#include <ctime> // 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;
}
16 changes: 16 additions & 0 deletions Dice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __DICE__
#define __DICE__

#include <time.h>

class Dice
{
private:
int Sides;
public:
Dice(){ Sides = 6; } // Initialize with 6 sides
int RollDice();
int Set_NumSides(int);
};

#endif
69 changes: 69 additions & 0 deletions Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "Player.h"
#include "AI.h"

#include <iostream>
#include <time.h>

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;
}
46 changes: 46 additions & 0 deletions Player.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
26 changes: 26 additions & 0 deletions Player.h
Original file line number Diff line number Diff line change
@@ -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