From f30020384f816b498fe1f6013758a8de37811821 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 29 Dec 2013 02:04:19 +0100 Subject: Firt commit of the new dice system for rolisteam. --- node/dicerollernode.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 node/dicerollernode.cpp (limited to 'node/dicerollernode.cpp') diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp new file mode 100644 index 0000000..c21b53c --- /dev/null +++ b/node/dicerollernode.cpp @@ -0,0 +1,30 @@ +#include "dicerollernode.h" + +#include +#include + +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; +} -- cgit v1.2.3-70-g09d2