aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/dicerollernode.cpp
blob: c21b53c86dc13a54db4309967b2b5961fd5c3a0a (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
#include "dicerollernode.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)
        {
            m_result.insertResult(rollDice());
        }
        if(NULL!=m_nextNode)
        {
            m_nextNode->run(this);
        }
    }
}
quint64 DiceRollerNode::rollDice()
{
    return (qrand()%m_faces)+1;
}