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/blackjack/blackjack.scxml | |
parent | d0441f605434a89b53735427e4e81182c65debbd (diff) |
some missing files
Diffstat (limited to 'examples/blackjack/blackjack.scxml')
-rw-r--r-- | examples/blackjack/blackjack.scxml | 217 |
1 files changed, 102 insertions, 115 deletions
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> |