aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/dicerollernode.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2013-12-29 02:04:19 +0100
committerRenaud G <renaud@rolisteam.org>2013-12-29 02:04:19 +0100
commitf30020384f816b498fe1f6013758a8de37811821 (patch)
tree7388de7fe766fe2973d94a3256f8820e3c7fbcdf /node/dicerollernode.cpp
parent7a1784893af6fe986503dc67672135ed05816579 (diff)
downloadOneRoll-f30020384f816b498fe1f6013758a8de37811821.tar.gz
OneRoll-f30020384f816b498fe1f6013758a8de37811821.zip
Firt commit of the new dice system for rolisteam.
Diffstat (limited to 'node/dicerollernode.cpp')
-rw-r--r--node/dicerollernode.cpp30
1 files changed, 30 insertions, 0 deletions
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 <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;
+}