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
1 change: 1 addition & 0 deletions B_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, this is my branch.
16 changes: 16 additions & 0 deletions Dice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "Dice.h"
#include <stdlib.h>
#include <time.h>

Dice::Dice(int num_sides){
srand(time(NULL));
this->sides = num_sides;
}

Dice::~Dice(){

}

int Dice::getRoll(){
return rand()%(this->sides) + 1; // + min to compensate for 0 roll
}
18 changes: 18 additions & 0 deletions Dice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef DICE_H
#define DICE_H

class Dice{
int sides;
public:
// Constructor / Destructor
Dice(int num_sides);
~Dice();
// Getters
int getNumSides() { return sides; };
// Setters
int setNumSides(int num_sides) { this->sides = num_sides; };
// Actions
int getRoll();
};

#endif
675 changes: 0 additions & 675 deletions LICENSE

This file was deleted.

17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
main: main.o Dice.o Player.o gameFunc.o
g++ -o main main.o dice.o player.o gameFunc.o

main.o: main.cpp Dice.h gameFunc.h Player.h
g++ -c main.cpp

Player.o: Player.cpp
g++ -c Player.cpp

Dice.o: Dice.cpp
g++ -c Dice.cpp

gameFunc.o: gameFunc.cpp
g++ -c gameFunc.cpp

clean:
rm *.o
10 changes: 10 additions & 0 deletions Player.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Player.h"

Player::Player(std::string name){
this->name = name;
score = 0;
}

Player::~Player(){

}
21 changes: 21 additions & 0 deletions Player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <iostream>
#include <string.h>

class Player{
int score;
std::string name;

public:
Player(std::string name);
~Player();
// Getters
std::string getName() {return name;}
int getScore() {return score;}
// Setters
void setName(std::string new_name) {this->name = new_name;}
int increaseScore(int score_inc) {score += score_inc; return score;}
};

#endif
218 changes: 218 additions & 0 deletions gameFunc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/**
* Game Functions.cpp
* @author Thibaut Hardin
*/

#include <stdlib.h> //rand
#include <time.h>
#include <string>
#include <vector>
#include <iostream>

#include "gameFunc.h"
#include "Player.h"
#include "Dice.h"

using std::string;
using std::vector;

/**
* startMessage - this function displays the game title and has the player
* set their name and game attributes
*/
void GameFunc::startMessage(){
string gameName[8] = {" _____ _ _____ ",
"| __ (_) / ____| ",
"| |__) | __ _ ___| | __ __ _ _ __ ___ ___ ",
"| ___/ |/ _` / __| | |_ |/ _` | '_ ` _ \\ / _ \\",
"| | | | (_| \\__ \\ |__| | (_| | | | | | | __/",
"|_| |_|\\__, |___/\\_____|\\__,_|_| |_| |_|\\___|",
" __/ | ",
" |___/ "};

//Simple for loop to print
for(int i=0;i<8;i++)
cout << gameName[i] << endl;

cout << "\n\nWelcome to PigsGame!\n"+
cout << "What is your name?\n"
string s;
addPlayer(s);

//Not enough time to fully implement
cout << "\nWould you like to change additional options?\n y / n \n"
cin >> s;
if(s=='y' || s=='Y')
additionalOptions();

if(m_numCompPlayers > 0){
cout << "\nWhat difficulty would you like the computer set to (Range: 0 - " + m_maxDifficultyLevels + "): ";
int temp;
cin >> temp;
changeDifficulty(temp);

}

}

/**
* This function is called when the player would like additional options
*/
void GameFunc::additionalOptions(){
"Please enter the number of players: ";
int temp;
cin >> temp;
m_numPlayers = temp;
cout << "\nPlease enter the number of computer players: ";
cin >> temp;
m_numCompPlayers = temp;
//Requires separate function to reassign d
cout << "\nPlease enter the number of sides you want the die to have: "
cin >> temp;
m_numSides = temp;
cout << "\nPlease specify the amount you would like the game to end at: "
cin >> temp;
m_endScore = temp;
cout << "\nPlease enter any numbers you would like to pass on separated by commas: "
string s;
//function to handle this.
}

/**
* beginGame - this function begins the game
*/
void GameFunc::beginGame(){
//Select random player to start.
srand(time(NULL)); //Initialize random seed.
int firstPlayer = rand() * m_pVec.size();
m_curPlayerIndex = firstPlayer;

//Main loop
while(!checkWinner()) //While score < m_endScore;
if(getPlayerChoice()){ // Roll or hold
if(!rollDie()) // If !(num in m_passNums), add roll to m_holdPoints
changeTurn();
}
else{
updateHoldScore(); // Add points to
changeTurn();
}
gameEnd();
}


/*
* gameEnd - this function ends the game
*/
void GameFunc::gameEnd(){
cout << "\nGame Over.\n";
//Ask to play again, if yes, resetScores(), ask for additionalOptions()
}

/**
* rollDie - This function calls the die roll function of the die and handles the output.
* @return - bool - Whether or not the die roll was in m_passNums[]
*/
bool GameFunc::rollDie(){
int roll = d.getRoll();
//Check if the roll is a passable num
int passNumsSize = m_passNums.size();
for(int i=0;i<passNumsSize;i++)
if(roll == m_passNums[i]){
m_holdPoints = 0;
return false;
}
//Otherwise update holdscore
m_holdPoints += roll;
return true;
}

/**
* getNumPlayers - this function returns the number of players
* @return - int - the number of players
*/
int GameFunc::getNumPlayers(){
return m_numPlayers;
}

/**
* getPlayerChoice - this function allows the player to continue rolling
* or to hold at their current roll
* @return - bool -
*/
bool GameFunc::getPlayerChoice(){
cout << "Roll or Hold (r/h): \n";
string input;
cin >> input;
if(input == r)
return true;
return false;

}

/**
* resetScore - this function resets the score if the player wishes to continue playing
*/
bool GameFunc::resetScore(){
for(i=0; i<m_numPlayers;i++);
m_pVec[score = 0;
}

/**
* changeDifficulty - Called from within the additionalOptions() function, changes AI difficulty level
*/
void GameFunc::changeDifficulty(int i){
for(int i=0;i<m_numPlayers;i++)
if(m_pVec[i].type == 1)
//Change difficulty of all computer players
}
}

/**
* updateHoldScore - adds m_holdPoints to the current player's score
*/
void GameFunc::updateHoldScore(){
m_pVec[m_curPlayerIndex].score += m_holdPoints;
m_holdPoints = 0;
}

/**
* changeTurn - changes the player turn to the next player in m_pVec
*/
void GameFunc::changeTurn(){
if(m_curPlayerIndex == (m_pVec.size()-1))
m_curPlayerIndex = 0;
else
m_curPlayerIndex++;
}

/**
* checkWinner - checks if the current player has scored > m_endScore
*/
bool GameFunc::checkWinner(){
if (m_pVec[m_curPlayerIndex].getPoints >= m_endScore)
gameEnd();
}

/**
* addNumToPassNums - called from additionalOptions function to add numbers to pass
*/
void GameFunc::addNumToPassNums(){
//add nums to pass to m_passNums
}

/**
* setEndScore - changes the m_endScore of the game
*/
void GameFunc::setEndScore(int i){
m_endScore = i;
}

/**
* addPlayer - adds a player to m_pVec
@param - string - playerName - the name of the player to be added
*/
void GameFunc::addPlayer(string playerName){
Player p = new Player(playerName);
m_pVec.push(p);
}
47 changes: 47 additions & 0 deletions gameFunc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Game Functions header class
* @author Thibaut Hardin
*/

#ifndef GAME_FUNCTIONS
#define GAME_FUNCTIONS

#include "player.h"
#include "die.h"

using std::string;
using std::vector;

class GameFunc{
public:
void startMessage();
void beginGame();
void resetScore();
int getPlayerChoice();
int getNumPlayers();
bool rollDie();
private:
int m_holdPoints = 0;
int m_numPlayers = 2; //total number of players
int m_numCompPlayers = 1; //number of computer players
int m_curPlayerIndex;
int m_endScore = 100;
int m_maxDifficultyLevels = 4;
int m_numSides = 6;
vector<Player> m_pVec; //vector of players
vector<int> m_passNums = {1}; //incase mroe pass numbers than 1

Dice d;

//Could be implemented into a vector for multiple user names.
string m_playerName;

void changeDifficulty(int i);
void additionalOptions();
void updateHoldScore();
void changeTurn();
void addNumToPassNums();
bool checkWinner();

};
#endif
17 changes: 17 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "Dice.h"
#include "Player.h"
#include "gameFunc.h"
#include <iostream>

using namespace std;


int main()
{

gameFunc gf = new GameFunc();
gf.startMessage();
gf.beginGame();

return 0;
};