I'm making an Yahtzee game in C++, my goal is to make an intelligent play field there the game will give examples to the user where he or she can put the result. In order to do that I have to sort the dices from low to high and then make new arrays, one array for those dices equal each other and the size of each array has to be as big as the number of dices in it.
This is my base-class:
The funktion that throws each dice.
void InGame::setDice(int dice){
if (this->diceCapacity <= this->nrOfDices){
this->expandDice();
}
for (int i = 0; i < nrOfDices; i++){
die[i]->roll(6);
}
}
setDice works fine. After this I'm sorting all 5 dices in a sub-class called scoreCalculator.
The sorting funktion:
void ScoreCalculator::sortDie(int arr[], int nrOfDieces){
int temp = -1;
int minIndex = 0;
for (int i = 0; i < nrOfDieces - 1; i++){
minIndex = i;
for (int k = (i + 1); k < nrOfDieces; k++){
if (arr[k] < arr[minIndex]){
minIndex = k;
}
}
temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}
And now I'm going to fill each equal die into different arrays that just holds those dices that are equal to each other.
This is what I have done so far
void ScoreCalculator::equalDie(int dice[]){
dice[5];
this->sortDie(dice, 5);
int count = 0;
int equal[5];
for (int i = 0; i < 5; i++){
for (int x = 1; x < 6; x++){
if (dice[i] == dice[x]){
for (int y = 0; y < 5; y++){
equal[y] = dice[i];
equal[y + 1] = dice[x];
y++;
}
}
}
}
}
This last funktion is not working at all
Aucun commentaire:
Enregistrer un commentaire