blob: 7530730f82e5eb3501461f2eefa8e747ea9c4ee4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "dicerollernode.h"
#include "die.h"
#include <QDateTime>
#include <QDebug>
DiceRollerNode::DiceRollerNode(quint64 faces)
: m_faces(faces),m_myDiceResult(new DiceResult())
{
uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch();
qsrand(seed);
m_result=m_myDiceResult;
}
void DiceRollerNode::run(ExecutionNode* previous)
{
if(NULL!=previous)
{
m_diceCount = previous->getResult()->getScalar();
for(quint64 i=0; i < m_diceCount ; ++i)
{
Die die;
die.insertRollValue(rollDice());
m_myDiceResult->insertResult(die);
}
if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
}
}
quint64 DiceRollerNode::rollDice()
{
return (qrand()%m_faces)+1;
}
|