aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/dicerollernode.cpp
blob: f068f4bced6480b700310df28cdffa40368a7891 (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
#include "dicerollernode.h"
#include "die.h"


#include <QDateTime>
#include <QDebug>

DiceRollerNode::DiceRollerNode(quint64 faces)
    : m_faces(faces)
{
    uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch();
    qsrand(seed);
}
void DiceRollerNode::run(ExecutionNode* previous)
{
    if(NULL!=previous)
    {
        m_diceCount = previous->getResult()->getSum();
        for(quint64 i=0; i < m_diceCount ; ++i)
        {
            Die die;
            die.setValue(rollDice());
            m_result.insertResult(die);
        }
        if(NULL!=m_nextNode)
        {
            m_nextNode->run(this);
        }
    }
}
quint64 DiceRollerNode::rollDice()
{
    return (qrand()%m_faces)+1;
}