diff options
author | Noam Rosenthal <nrosenth@nokia.com> | 2009-06-08 12:28:41 -0700 |
---|---|---|
committer | Noam Rosenthal <nrosenth@nokia.com> | 2009-06-08 12:28:41 -0700 |
commit | 7a41ce5b7a595c67c16ae5ef1711927623602b6a (patch) | |
tree | 5a6917940daa31c04f21bbb67417504674b6418a /examples | |
parent | d0441f605434a89b53735427e4e81182c65debbd (diff) |
some missing files
Diffstat (limited to 'examples')
-rw-r--r-- | examples/blackjack/blackjack.pro | 2 | ||||
-rw-r--r-- | examples/blackjack/blackjack.scxml | 217 | ||||
-rw-r--r-- | examples/blackjack/main.cpp | 4 | ||||
-rw-r--r-- | examples/calc/calc.pro | 2 | ||||
-rw-r--r-- | examples/calc/calc.scxml | 215 | ||||
-rw-r--r-- | examples/calc/main.cpp | 4 | ||||
-rw-r--r-- | examples/examples.pro | 2 | ||||
-rw-r--r-- | examples/mediaplayer/main.cpp | 4 | ||||
-rw-r--r-- | examples/mediaplayer/mediaplayer.pro | 2 |
9 files changed, 218 insertions, 234 deletions
diff --git a/examples/blackjack/blackjack.pro b/examples/blackjack/blackjack.pro index 29c7351..71c4409 100644 --- a/examples/blackjack/blackjack.pro +++ b/examples/blackjack/blackjack.pro @@ -9,6 +9,6 @@ CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp -include($$PWD/../../src/qtstatemachine.pri) +include(../../src/qscxml.pri) FORMS += blackjack.ui RESOURCES += bj.qrc diff --git a/examples/blackjack/blackjack.scxml b/examples/blackjack/blackjack.scxml index 6c98eb5..4c73cd4 100644 --- a/examples/blackjack/blackjack.scxml +++ b/examples/blackjack/blackjack.scxml @@ -5,17 +5,15 @@ var Suits = "CDHS"; var Ranks = "-A23456789TJQK"; - function CardToString() - { - return "" + Ranks[this.rank] + Suits[this.suit]; - } - function Card (r,s) { this.rank = r; this.suit = s; this.minValue = Math.min(r,10); - this.toString = CardToString; + this.toString = function() { + return "" + Ranks[this.rank] + Suits[this.suit]; + }; +; } function updateDisplay () @@ -23,88 +21,78 @@ cardsLabel.text = "My Cards: " + myDeck + " Dealer Cards: " + dealerCards; } - function randomSort (a,b) - { - return Math.random() * 3 - 1; - } - - function deckReset() - { - this.clear (); - for (var i=1; i <= 13; ++i) - for (var j = 0; j < 4; ++j) - this.cards.push(new Card(i,j)); - this.cards.sort(randomSort); - } + - function deckDraw () - { - return this.cards.pop(); - } - function deckDrawFrom (d) - { - var c = d.draw (); - this.cards.push(c); - updateDisplay (); - } - - function deckClear () + function Deck() { - this.cards = new Array; - } + this.draw = function() + { + return this.cards.pop(); + }; + this.cards = new Array(); + this.reset = function() + { + this.clear (); + for (var i=1; i <= 13; ++i) + for (var j = 0; j < 4; ++j) + this.cards.push(new Card(i,j)); + this.cards.sort(function (a,b) + { + return Math.random() * 3 - 1; + }); + }; + + this.clear = function() + { + this.cards = new Array; + }; + this.evalMin = function () + { + var minVal = 0; + var cardCount = this.cards.length; + for (c in this.cards) { + minVal += this.cards[c].minValue; + } + if (cardCount > 4 && minVal < 22) + minVal = 21; + return minVal; + }; - function deckEvalMin () - { - var minVal = 0; - var cardCount = this.cards.length; - for (c in this.cards) { - minVal += this.cards[c].minValue; - } - if (cardCount > 4 && minVal < 22) - minVal = 21; - return minVal; - } + this.evalBest = function() + { + var bestVal = this.evalMin(); + if (bestVal > 21) + return 0; + else if (bestVal == 21) + return bestVal; - function deckEvalBest () - { - var bestVal = this.evalMin(); - if (bestVal > 21) - return 0; - else if (bestVal == 21) - return bestVal; - - for (i in this.cards) { - if (this.cards[i].rank == 1) - { - var v = bestVal + 10; - if (v <= 21) - bestVal = v; + for (i in this.cards) { + if (this.cards[i].rank == 1) + { + var v = bestVal + 10; + if (v <= 21) + bestVal = v; + } } - } - return bestVal; - - } + return bestVal; - function deckToString () - { - var s = ""; - for (i in this.cards) - s += this.cards[i].toString() + ":"; + }; + this.toString = function() + { + var s = ""; + for (i in this.cards) + s += this.cards[i].toString() + ":"; - return s; - } + return s; + }; - function Deck() - { - this.draw = deckDraw; - this.cards = new Array(); - this.reset = deckReset; - this.clear = deckClear; - this.evalMin = deckEvalMin; - this.evalBest = deckEvalBest; - this.toString = deckToString; - this.drawFrom = deckDrawFrom; + this.drawFrom = function(d) + { + var c = d.draw (); + this.cards.push(c); + updateDisplay (); + }; } @@ -125,35 +113,34 @@ </script> - </onentry> + </onentry> <invoke type="q-bindings"> <content> [[welcomeLabel,"text","Welcome to Blackjack"]] </content> - </invoke> + </invoke> <transition event="q-signal:newGameButton.clicked()" target="newgame" /> <state id="newgame"> - <onentry> - <script> - points = 1000; - pointsLabel.text = points; - </script> + <onentry> + <script> + points = 1000; + pointsLabel.text = points; + </script> </onentry> <transition target="newround" /> </state> <state id="quitdlg"> <invoke type="q-messagebox"> - <content> - { - "parent" : gameWidget, - "icon" : QMessageBox.Question, - "windowTitle" : "Exit Blackjack", - "text" : "Are you sure?", - "standardButtons" : - QMessageBox.Yes|QMessageBox.No - } - </content> - </invoke> + <content> + { + "parent" : gameWidget, + "icon" : QMessageBox.Question, + "windowTitle" : "Exit Blackjack", + "text" : "Are you sure?", + "standardButtons" : QMessageBox.Yes|QMessageBox.No + } + </content> + </invoke> <transition event="q-messagebox.finished" target="exit" cond="_event.data[0]==QMessageBox.Yes" /> <transition event="q-messagebox.finished" target="gamestate" cond="_event.data[0]==QMessageBox.No" /> </state> @@ -194,24 +181,24 @@ </transition> <transition event="q-signal:surrenderButton.clicked()" target="newround" /> </state> - <state id="betTooHigh"> + <state id="betTooHigh"> <invoke type="q-messagebox"> - <content> - { - "parent" : betEdit, - "icon" : QMessageBox.Warning, - "windowTitle" : "Bet is Too High", - "text" : "Please Place Another Bet", - "standardButtons" : - QMessageBox.Ok - } - </content> - </invoke> + <content> + { + "parent" : betEdit, + "icon" : QMessageBox.Warning, + "windowTitle" : "Bet is Too High", + "text" : "Please Place Another Bet", + "standardButtons" : + QMessageBox.Ok + } + </content> + </invoke> <transition event="q-messagebox.finished" target="waitForBet" /> - <transition event="bth-mb-timeout" target="waitForBet" /> - <onentry> + <transition event="bth-mb-timeout" target="waitForBet" /> + <onentry> <send event="'bth-mb-timeout'" delay="'1500ms'" /> - </onentry> + </onentry> </state> <state id="testCards"> <transition target="loss" cond="myDeck.evalBest() == 0" /> @@ -268,9 +255,9 @@ <invoke type="q-bindings"><content>[[newRoundButton,"enabled",true]]</content></invoke> <transition event="q-signal:newRoundButton.clicked()" target="newround" /> <transition event="timeout" target="newround" /> - <onentry> - <send event="'timeout'" delay="'3s'" /> - </onentry> + <onentry> + <send event="'timeout'" delay="'3s'" /> + </onentry> <state id="win"> <onentry> diff --git a/examples/blackjack/main.cpp b/examples/blackjack/main.cpp index c2e8105..4b5c978 100644 --- a/examples/blackjack/main.cpp +++ b/examples/blackjack/main.cpp @@ -5,14 +5,14 @@ #include <QMessageBox> #include <QUrl> #include <QScriptEngine> -#include "qscriptedstatemachine.h" +#include "qscxml.h" #include "time.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); srand(clock()); - QtScriptedStateMachine *sm = QtScriptedStateMachine::load(":/blackjack.scxml"); + QScxml *sm = QScxml::load(":/blackjack.scxml"); QObject::connect (sm, SIGNAL(finished()), &a, SLOT(quit())); QMessageBox b; QWidget* wdg = new QWidget(); diff --git a/examples/calc/calc.pro b/examples/calc/calc.pro index ff274c2..f20233e 100644 --- a/examples/calc/calc.pro +++ b/examples/calc/calc.pro @@ -7,7 +7,7 @@ TEMPLATE = app win32: CONFIG += console mac:CONFIG -= app_bundle QT = core gui script -include($$PWD/../../src/qtstatemachine.pri) +include($$PWD/../../src/qscxml.pri) # Input SOURCES += main.cpp calc.cpp diff --git a/examples/calc/calc.scxml b/examples/calc/calc.scxml index 35a9b9e..ec732c7 100644 --- a/examples/calc/calc.scxml +++ b/examples/calc/calc.scxml @@ -1,6 +1,3 @@ -<!-- http://www.state-machine.com/devzone/Recipe_DesigningHSM.pdf --> -<!-- events: OPER.PLUS OPER.MINUS OPER.MULTIPLY OPER.DIVIDE DIGIT.0 DIGIT.1_9 EQUALS CE C POINT - ---> <scxml initial="on" profile="ecma" name="calc"> <script> @@ -70,26 +67,26 @@ <datamodel> <data id="long_expr" /> <data id="res" >0</data> - </datamodel> + </datamodel> <onentry> - <script> + <script> var short_expr = 0; _data.res = 0; _data.long_expr = ""; updateDisplay(); - </script> - </onentry> - <state id="ready" initial="begin"> - <state id="begin"> - <transition event="OPER.MINUS" target="negated1" /> - <onentry> - <script> - updateDisplay (); - </script> - </onentry> - </state> - <state id="result"> - </state> + </script> + </onentry> + <state id="ready" initial="begin"> + <state id="begin"> + <transition event="OPER.MINUS" target="negated1" /> + <onentry> + <script> + updateDisplay (); + </script> + </onentry> + </state> + <state id="result"> + </state> <transition event="OPER" target="opEntered" /> <transition event="DIGIT.0" target="zero1"> <script> @@ -107,107 +104,107 @@ </script> </transition> </state> - <state id="negated1"> - <onentry> - <script> - negate (); - </script> - </onentry> - <transition event="DIGIT.0" target="zero1" /> + <state id="negated1"> + <onentry> + <script> + negate (); + </script> + </onentry> + <transition event="DIGIT.0" target="zero1" /> <transition event="DIGIT" target="int1" /> - <transition event="POINT" target="frac1" /> - </state> - <state id="operand1"> - <state id="zero1"> + <transition event="POINT" target="frac1" /> + </state> + <state id="operand1"> + <state id="zero1"> <transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int1" /> - <transition event="POINT" target="frac1" /> - </state> - <state id="int1"> - <transition event="POINT" target="frac1" /> + <transition event="POINT" target="frac1" /> + </state> + <state id="int1"> + <transition event="POINT" target="frac1" /> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - <onentry> - <script> - insertDigit (); - </script> - </onentry> - </state> - <state id="frac1"> - <onentry> - <script> - insert ('.'); - </script> - </onentry> + <script> + insertDigit (); + </script> + </transition> + <onentry> + <script> + insertDigit (); + </script> + </onentry> + </state> + <state id="frac1"> + <onentry> + <script> + insert ('.'); + </script> + </onentry> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - </state> - <transition event="CE" target="ready" /> + <script> + insertDigit (); + </script> + </transition> + </state> + <transition event="CE" target="ready" /> <transition event="OPER" target="opEntered" /> - </state> - <state id="error" /> - <state id="opEntered"> - <transition event="OPER.MINUS" target="negated2" /> - <transition event="POINT" target="frac2" /> - <transition event="DIGIT.0" target="zero2" /> + </state> + <state id="error" /> + <state id="opEntered"> + <transition event="OPER.MINUS" target="negated2" /> + <transition event="POINT" target="frac2" /> + <transition event="DIGIT.0" target="zero2" /> <transition event="DIGIT" target="int2" /> - <onentry> - <script> - insertOp (); - </script> - </onentry> - </state> - <state id="negated2"> - <onentry> - <script> - negate (); - </script> - </onentry> - <transition event="CE" target="opEntered" /> - <transition event="DIGIT.0" target="zero2" /> + <onentry> + <script> + insertOp (); + </script> + </onentry> + </state> + <state id="negated2"> + <onentry> + <script> + negate (); + </script> + </onentry> + <transition event="CE" target="opEntered" /> + <transition event="DIGIT.0" target="zero2" /> <transition event="DIGIT" target="int2" /> - <transition event="POINT" target="frac2" /> - </state> - <state id="operand2"> - <state id="zero2"> + <transition event="POINT" target="frac2" /> + </state> + <state id="operand2"> + <state id="zero2"> <transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int2" /> - <transition event="POINT" target="frac2" /> - </state> - <state id="int2"> + <transition event="POINT" target="frac2" /> + </state> + <state id="int2"> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - <onentry> - <script> - insertDigit (); - </script> - </onentry> - <transition event="POINT" target="frac2" /> - </state> - <state id="frac2"> - <onentry> - <script> - insert ('.'); - </script> - </onentry> + <script> + insertDigit (); + </script> + </transition> + <onentry> + <script> + insertDigit (); + </script> + </onentry> + <transition event="POINT" target="frac2" /> + </state> + <state id="frac2"> + <onentry> + <script> + insert ('.'); + </script> + </onentry> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - </state> + <script> + insertDigit (); + </script> + </transition> + </state> <transition event="OPER" cond="!insertOp()" target="error" /> <transition event="OPER" target="opEntered" /> - <transition event="EQUALS" cond="!calc()" target="error" /> - <transition event="EQUALS" target="result" /> - </state> - <transition event="C" target="on" /> - </state> + <transition event="EQUALS" cond="!calc()" target="error" /> + <transition event="EQUALS" target="result" /> + </state> + <transition event="C" target="on" /> + </state> </scxml> diff --git a/examples/calc/main.cpp b/examples/calc/main.cpp index 9d30c6b..181b792 100644 --- a/examples/calc/main.cpp +++ b/examples/calc/main.cpp @@ -1,11 +1,11 @@ #include <QtGui/QApplication> #include "calc.h" -#include "qscriptedstatemachine.h" +#include "qscxml.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); - QtScriptedStateMachine *sm = QtScriptedStateMachine::load(":/calc.scxml"); + QScxml *sm = QScxml::load(":/calc.scxml"); CalcWidget w; sm->registerObject(&w,"",true); QObject::connect (&w, SIGNAL(command(QString)), sm, SLOT(postNamedEvent(QString))); diff --git a/examples/examples.pro b/examples/examples.pro index a13e798..53d0ca3 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += blackjack calc mediaplayer
\ No newline at end of file +SUBDIRS += blackjack calc mediaplayer
\ No newline at end of file diff --git a/examples/mediaplayer/main.cpp b/examples/mediaplayer/main.cpp index 1eb7b4b..29bc3fc 100644 --- a/examples/mediaplayer/main.cpp +++ b/examples/mediaplayer/main.cpp @@ -1,4 +1,4 @@ -#include "qscriptedstatemachine.h" +#include "qscxml.h" #include "spview.h" #include "spmodel.h" #include "spengine.h" @@ -38,7 +38,7 @@ int main( int argc, char **argv) app.setApplicationName("SCXML-mediaplayer"); SPView* view = new SPView(NULL); - QtScriptedStateMachine *sm = QtScriptedStateMachine::load(":/mediaplayer.scxml"); + QScxml *sm = QScxml::load(":/mediaplayer.scxml"); QObject::connect (sm, SIGNAL(finished()), &app, SLOT(quit())); SPModel* model= new SPModel(NULL); view->setModel(model); diff --git a/examples/mediaplayer/mediaplayer.pro b/examples/mediaplayer/mediaplayer.pro index 355da25..70c06f1 100644 --- a/examples/mediaplayer/mediaplayer.pro +++ b/examples/mediaplayer/mediaplayer.pro @@ -3,7 +3,7 @@ TARGET = scxmlplayer QT += script \ sql \ phonon -include($$PWD/../../src/qtstatemachine.pri) +include(../../src/qscxml.pri) HEADERS += spmodel.h \ spengine.h \ |