Question
C++ need help on adding Dice object and adding a fuction to roll all the dices - here is my code (Yahtzee game) Player.h #ifndef
C++ need help on adding Dice object and adding a fuction to roll all the dices - here is my code (Yahtzee game)
Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include "Dice.h"
class Player
{
private:
Dice myDice[5]; // an array of Dice objects
int nDice; // number of Dices player has
public:
Player(int nDice); // parameterized constructor with nDice
void playerRoll(); // roll all the dices
void setNumDice(int nDice); // set number of dices
int getDiceValueAtIndex(int i) const; // get value of Dice i
};
#endif
Player.cpp
#include "Player.h"
Player::Player(int number){
nDice = number;
for (int i = 0; i < nDice; i++){
Dice d1;
/*
add Dice object created to array of Dices
... is it Dice d1, d2(1,2,3,4,5)?
*/
}
}
void Player::setNumDice(int number){
nDice = number;
}
void Player::playerRoll(){
/*
Create a function to roll all the dices
*/
}
int Player::getDiceValueAtIndex(int i) const{
return myDice[i].getFaceValue();
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started