This is my Assignment and its very difficult, But maybe someone out there can give me a hand with this.
Dice Game
The dice game involves a set of six-sided dice, which you should store in a vector of pointers to RandomWheel objects, which is declared this way:
vector<RandomWheel *> diceList;
The game proceeds as follows:
The player starts with 0 points.
Begin by asking how many dice (N) to to use. Add that many elements to your vector, allocating and initializing each object appropriately:
The values are simply the integers 1 through 6.
The labels should be text "pictures" that represent each number. (It doesn't matter what they look like - feel free to be creative - as long as it is obvious what each picture represents).
One "round" of the game is:
Roll all N dice. Display their labels in a sequence.
Exactly two times, prompt the user for a dice number (0 up to N-1) to re-roll, then re-roll that particular die. (Reject any input that isn't valid, without giving a chance to input again.) After each re-roll, display all labels again.
At this point, if any value makes up the majority of the dice (i.e. more than N/2), the player gains N*10 points;
Otherwise, the player gains points equal to the sum of all dice values.
Do 5 rounds of the game, then report the player's final score.
When done, return to the main menu.
This is the code that I have thus far but I have hit a major wall.
//This is the H file
#ifndef RANDOMWHEEL_H
#define RANDOMWHEEL_H
#include <vector>
#include <iostream>
using namespace std;
class RandomWheel
{
private:
int numberOfItems;
int currentItem;
vector<int> itemValues;
vector<string> itemLabels;
public:
// CONSTRUCTOR
RandomWheel(int itemCount, int values[], string labels[]);
// MUTATORS
void Spin();
// ACCESSORS
int GetCurrentValue() const;
string GetCurrentLabel() const;
};
#endif // RANDOMWHEEL_H
//This is the ccp file
#include "RandomWheel.h"
#include <cstdlib>
#include <ctime>
// CONSTRUCTOR
RandomWheel::RandomWheel(int itemCount, int values[], string labels[])
{
srand(time(0));
numberOfItems = itemCount;
currentItem = 0;
for (int i = 0; i < itemCount; i++)
{
itemValues.push_back(values[i]);
itemLabels.push_back(labels[i]);
}
}
// MUTATORS
void RandomWheel::Spin()
{
currentItem = rand()%numberOfItems;
}
// ACCESSORS
int RandomWheel::GetCurrentValue() const
{
return (itemValues[currentItem]);
}
Do it in small steps and compile/run/test after each step.
Comment out the code in main and start writing the new code. Don't delete it since then you can use it as reference.
You know how to get input from user so just code that.
Then write code to create a pointer to one RandomWheel thinking about what the arrays that are passed to RandomWheel should be.
Then rewrite the code so it creates the number of RandomWheels that the user requested.
Then rewrite code so it creates the diceList vector.
Then write code that rolls(spins) all the dice in the diceList.
Then write code that displays all the dice labels.
Then write code that asks the user for a die number.
Then write code that spins just that die.
Then write code that displays all the labels.
Then rewrite code for above 3 lines so it does it twice.
.
.
.
etc