diff options
| author | 2014-01-05 13:12:05 +0100 | |
|---|---|---|
| committer | 2014-01-05 13:12:05 +0100 | |
| commit | 3853227d5852f45341c1ee49be4411ada78d860c (patch) | |
| tree | 12bd626e68a445b37e0c3870a996aedf8552a5c8 | |
| parent | 4de8cf5796446b7f8b09d776e4a6a6d6b8e95cb6 (diff) | |
| download | OneRoll-3853227d5852f45341c1ee49be4411ada78d860c.tar.gz OneRoll-3853227d5852f45341c1ee49be4411ada78d860c.zip | |
Add new management of result.
It may require to make several
| -rw-r--r-- | diceParser.pro | 6 | ||||
| -rw-r--r-- | diceparser.cpp | 3 | ||||
| -rw-r--r-- | diceresult.cpp | 16 | ||||
| -rw-r--r-- | diceresult.h | 10 | ||||
| -rw-r--r-- | die.cpp | 34 | ||||
| -rw-r--r-- | die.h | 24 | ||||
| -rw-r--r-- | main.cpp | 2 | ||||
| -rw-r--r-- | node/dicerollernode.cpp | 6 | ||||
| -rw-r--r-- | node/rerolldicenode.cpp | 20 | ||||
| -rw-r--r-- | node/rerolldicenode.h | 6 | ||||
| -rw-r--r-- | node/sortresult.cpp | 4 |
11 files changed, 97 insertions, 34 deletions
diff --git a/diceParser.pro b/diceParser.pro index 112fb9a..caf19fb 100644 --- a/diceParser.pro +++ b/diceParser.pro @@ -22,7 +22,8 @@ SOURCES += main.cpp \ diceresult.cpp \ range.cpp \ booleancondition.cpp \ - validator.cpp + validator.cpp \ + die.cpp HEADERS += \ @@ -30,7 +31,8 @@ HEADERS += \ diceresult.h \ range.h \ booleancondition.h \ - validator.h + validator.h \ + die.h OTHER_FILES += README.md diff --git a/diceparser.cpp b/diceparser.cpp index f44f6af..81fc1e7 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -48,6 +48,7 @@ void DiceParser::setCurrentNode(ExecutionNode* node) void DiceParser::parseLine(QString str) { + QString command = str; m_start = new StartingNode(); m_current = m_start; bool keepParsing = true; @@ -71,7 +72,7 @@ void DiceParser::parseLine(QString str) { next = next->getNextNode(); } - qDebug() << "list:" <<next->getResult()->getResultList() << "sum" <<next->getResult()->getSum() ; + qDebug() << "list:" <<next->getResult()->getResultList() << " sum:" <<next->getResult()->getSum() << " command:" << command; } bool DiceParser::readNumber(QString& str, int& myNumber) { diff --git a/diceresult.cpp b/diceresult.cpp index 619ccbd..6d84ce1 100644 --- a/diceresult.cpp +++ b/diceresult.cpp @@ -4,25 +4,15 @@ DiceResult::DiceResult() { } -void DiceResult::insertResult(qint64 die) +void DiceResult::insertResult(Die die) { m_diceValues.append(die); } -QList<qint64>& DiceResult::getResultList() +QList<Die>& DiceResult::getResultList() { return m_diceValues; } -qint64 DiceResult::getSum() -{ - qint64 sum=0; - foreach (qint64 tmp, m_diceValues) - { - sum+=tmp; - } - return sum; -} - -void DiceResult::setResultList(QList<qint64> list) +void DiceResult::setResultList(QList<Die> list) { m_diceValues.clear(); m_diceValues << list; diff --git a/diceresult.h b/diceresult.h index 9212233..7cb5169 100644 --- a/diceresult.h +++ b/diceresult.h @@ -2,20 +2,22 @@ #define DICERESULT_H #include <QList> +#include "die.h" + class DiceResult { public: DiceResult(); qint64 getSum(); - QList<qint64>& getResultList(); - void insertResult(qint64); + QList<Die>& getResultList(); + void insertResult(Die); - void setResultList(QList<qint64> list); + void setResultList(QList<Die> list); private: - QList<qint64> m_diceValues; + QList<Die> m_diceValues; }; #endif // DICERESULT_H @@ -0,0 +1,34 @@ +#include "die.h" + +Die::Die() +{ +} + +void Die::setValue(qint64 r) +{ + m_value = r; +} + +void Die::insertRollValue(qint64 r) +{ + m_rollResult.insert(r); +} + +void Die::setSelected(bool b) +{ + m_selected = b; +} + + +bool Die::isSelected() const +{ + return m_selected; +} +qint64 Die::getValue() const +{ + return m_value; +} +QList<qint64> Die::getListValue() const +{ + return m_rollResult; +} @@ -0,0 +1,24 @@ +#ifndef DIE_H +#define DIE_H + +#include <QList> + +class Die +{ +public: + Die(); + + void setValue(qint64 r); + void insertRollValue(qint64 r); + void setSelected(bool b); + + bool isSelected() const; + qint64 getValue() const; + QList<qint64> getListValue() const; +private: + qint64 m_value; + QList<qint64> m_rollResult; + bool m_selected; +}; + +#endif // DIE_H @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) myParser->parseLine("D25"); myParser->parseLine("8+8"); myParser->parseLine("88-1D20"); - myParser->parseLine("100*1D20"); + myParser->parseLine("100*1D20*2D6"); myParser->parseLine("100/28"); myParser->parseLine("100/8"); myParser->parseLine("100*3"); diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index c21b53c..f068f4b 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -1,4 +1,6 @@ #include "dicerollernode.h" +#include "die.h" + #include <QDateTime> #include <QDebug> @@ -16,7 +18,9 @@ void DiceRollerNode::run(ExecutionNode* previous) m_diceCount = previous->getResult()->getSum(); for(quint64 i=0; i < m_diceCount ; ++i) { - m_result.insertResult(rollDice()); + Die die; + die.setValue(rollDice()); + m_result.insertResult(die); } if(NULL!=m_nextNode) { diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index 45f27de..6bc9467 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -1,21 +1,27 @@ #include "rerolldicenode.h" +#include "dicerollernode.h" -RerollDiceNode::RerollDiceNode(ExecutionNode* previous) - : m_previous(previous) +RerollDiceNode::RerollDiceNode() { } -void RerollDiceNode::run() +void RerollDiceNode::run(ExecutionNode* previous) { - if((NULL!=m_previous)&&(NULL!=m_previous->getResult())) + if((NULL!=previous)&&(NULL!=previous->getResult())) { - QList<qint64> list = m_previous->getResult()->getResultList(); + QList<Die> list = previous->getResult()->getResultList(); - for(qint64 i=0; i < list.size() ; ++i) + foreach(Die die, list) { - // m_result.insertResult(rollDice()); + if(m_value == die.getValue()) + { +/* + DiceRollerNode roller; + roller.run(this);*/ + } } + if(NULL!=m_nextNode) { m_nextNode->run(this); diff --git a/node/rerolldicenode.h b/node/rerolldicenode.h index 90dc81a..609fcf3 100644 --- a/node/rerolldicenode.h +++ b/node/rerolldicenode.h @@ -12,11 +12,11 @@ class RerollDiceNode : public ExecutionNode public: enum ReRollMode {EQUAL,LESSER,GREATER}; - RerollDiceNode(ExecutionNode* previous); + RerollDiceNode(); - virtual void run(); + virtual void run(ExecutionNode* previous); private: - ExecutionNode* m_previous; + qint64 m_value; }; #endif // REROLLDICENODE_H diff --git a/node/sortresult.cpp b/node/sortresult.cpp index f4364fa..f842fcc 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -12,8 +12,8 @@ void SortResultNode::run(ExecutionNode* node) { return; } - QList<qint64> diceList=node->getResult()->getResultList(); - QList<qint64> diceList2=m_result.getResultList(); + QList<Die> diceList=node->getResult()->getResultList(); + QList<Die> diceList2=m_result.getResultList(); diceList2 = diceList; if(!m_ascending) |