diff options
Diffstat (limited to 'node')
| -rw-r--r-- | node/countexecutenode.cpp | 33 | ||||
| -rw-r--r-- | node/countexecutenode.h | 22 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 27 | ||||
| -rw-r--r-- | node/keepdiceexecnode.h | 17 | ||||
| -rw-r--r-- | node/node.pri | 10 | ||||
| -rw-r--r-- | node/sortresult.cpp | 37 | ||||
| -rw-r--r-- | node/sortresult.h | 18 |
7 files changed, 162 insertions, 2 deletions
diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp new file mode 100644 index 0000000..fff00f2 --- /dev/null +++ b/node/countexecutenode.cpp @@ -0,0 +1,33 @@ +#include "countexecutenode.h" + +CountExecuteNode::CountExecuteNode() +{ +} +void CountExecuteNode::setValidator(Validator* validator) +{ + m_validator = validator; +} + +void CountExecuteNode::run(ExecutionNode *previous) +{ + if(NULL==previous) + { + return; + } + QList<qint64> diceList=previous->getResult()->getResultList(); + qint64 sum = 0; + foreach(qint64 dice,diceList) + { + if(m_validator->isValid(dice)) + { + ++sum; + } + } + m_result.insertResult(sum); + + + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} diff --git a/node/countexecutenode.h b/node/countexecutenode.h new file mode 100644 index 0000000..6c971ea --- /dev/null +++ b/node/countexecutenode.h @@ -0,0 +1,22 @@ +#ifndef COUNTEXECUTENODE_H +#define COUNTEXECUTENODE_H + +#include "executionnode.h" + +#include "validator.h" + +class CountExecuteNode : public ExecutionNode +{ +public: + CountExecuteNode(); + virtual void run(ExecutionNode* previous); + + + virtual void setValidator(Validator* ); + +private: + Validator* m_validator; + +}; + +#endif // COUNTEXECUTENODE_H diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp new file mode 100644 index 0000000..cd2b76e --- /dev/null +++ b/node/keepdiceexecnode.cpp @@ -0,0 +1,27 @@ +#include "keepdiceexecnode.h" + +KeepDiceExecNode::KeepDiceExecNode() +{ +} + +void KeepDiceExecNode::run(ExecutionNode* previous) +{ + if(NULL==previous) + { + return; + } + QList<qint64> diceList=previous->getResult()->getResultList(); + QList<qint64> diceList2=m_result.getResultList(); + + + diceList2 = diceList.mid(0,m_numberOfDice); + m_result.setResultList(diceList2); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} +void KeepDiceExecNode::setDiceKeepNumber(quint64 n) +{ + m_numberOfDice = n; +} diff --git a/node/keepdiceexecnode.h b/node/keepdiceexecnode.h new file mode 100644 index 0000000..28c637d --- /dev/null +++ b/node/keepdiceexecnode.h @@ -0,0 +1,17 @@ +#ifndef KEEPDICEEXECNODE_H +#define KEEPDICEEXECNODE_H + +#include "executionnode.h" + +class KeepDiceExecNode : public ExecutionNode +{ +public: + KeepDiceExecNode(); + + virtual void run(ExecutionNode *previous); + virtual void setDiceKeepNumber(quint64 ); +private: + quint64 m_numberOfDice; +}; + +#endif // KEEPDICEEXECNODE_H diff --git a/node/node.pri b/node/node.pri index c3e1d65..fb2d9ad 100644 --- a/node/node.pri +++ b/node/node.pri @@ -4,7 +4,10 @@ HEADERS += \ node/rerolldicenode.h \ node/startingnode.h \ node/scalaroperatornode.h \ - node/numbernode.h + node/numbernode.h \ + node/sortresult.h \ + node/keepdiceexecnode.h \ + node/countexecutenode.h SOURCES += \ node/dicerollernode.cpp \ @@ -12,4 +15,7 @@ SOURCES += \ node/startingnode.cpp \ node/rerolldicenode.cpp \ node/scalaroperatornode.cpp \ - node/numbernode.cpp + node/numbernode.cpp \ + node/sortresult.cpp \ + node/keepdiceexecnode.cpp \ + node/countexecutenode.cpp diff --git a/node/sortresult.cpp b/node/sortresult.cpp new file mode 100644 index 0000000..f4364fa --- /dev/null +++ b/node/sortresult.cpp @@ -0,0 +1,37 @@ +#include "sortresult.h" + +#include <QDebug> + +SortResultNode::SortResultNode() +{ + m_ascending = true; +} +void SortResultNode::run(ExecutionNode* node) +{ + if(NULL==node) + { + return; + } + QList<qint64> diceList=node->getResult()->getResultList(); + QList<qint64> diceList2=m_result.getResultList(); + + diceList2 = diceList; + if(!m_ascending) + { + qSort(diceList2.begin(), diceList2.end(), qGreater<int>()); + } + else + { + qSort(diceList2.begin(), diceList2.end(), qLess<int>()); + } + m_result.setResultList(diceList2); + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } + +} +void SortResultNode::setSortAscending(bool asc) +{ + m_ascending = asc; +} diff --git a/node/sortresult.h b/node/sortresult.h new file mode 100644 index 0000000..8433eba --- /dev/null +++ b/node/sortresult.h @@ -0,0 +1,18 @@ +#ifndef SORTRESULT_H +#define SORTRESULT_H + +#include "executionnode.h" + +class SortResultNode : public ExecutionNode +{ +public: + SortResultNode(); + virtual void run(ExecutionNode*); + + + void setSortAscending(bool asc); +private: + bool m_ascending; +}; + +#endif // SORTRESULT_H |