diff options
| author | 2014-01-08 18:02:50 +0100 | |
|---|---|---|
| committer | 2014-01-08 18:02:50 +0100 | |
| commit | ed4de87f2518c63fc8a463b0f600ce37eb4749c4 (patch) | |
| tree | 2826be68884205a2a3382c5fbe0f1f31e2ebf0b4 /die.cpp | |
| parent | 4c02b504e0369fea3e82f240ba4269c08962bdba (diff) | |
| download | OneRoll-ed4de87f2518c63fc8a463b0f600ce37eb4749c4.tar.gz OneRoll-ed4de87f2518c63fc8a463b0f600ce37eb4749c4.zip | |
Update die.cpp
-put rolling die as method of die class
Diffstat (limited to 'die.cpp')
| -rw-r--r-- | die.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -1,10 +1,17 @@ +#include <QDateTime> + #include "die.h" +#include <QDebug> + Die::Die() : m_hasValue(false) { + uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch(); + qsrand(seed); } + void Die::setValue(qint64 r) { m_value = r; @@ -48,3 +55,28 @@ bool Die::hasChildrenValue() { return m_rollResult.size()>1?true:false; } +void Die::replaceLastValue(qint64 value) +{ + m_rollResult.removeLast(); + insertRollValue(value); +} + +void Die::roll(bool adding) +{ + quint64 value=(qrand()%m_faces)+1; + + if((adding)||(m_rollResult.isEmpty())) + { + insertRollValue(value); + } + else + { + replaceLastValue(value); + } +} + + +void Die::setFaces(quint64 face) +{ + m_faces=face; +} |