Skip to content

Instantly share code, notes, and snippets.

@Ephellon
Created October 15, 2015 22:46
Show Gist options
  • Save Ephellon/5c751f05c0ffd134f284 to your computer and use it in GitHub Desktop.
Save Ephellon/5c751f05c0ffd134f284 to your computer and use it in GitHub Desktop.
Tuxedo Script: Piggy Bank Example
<script type=text/ts>
##!, strict mode required for advanced features
## +clean
## +eval
## +legacy
## +math
## +wordy
## +advance
## -hide
## -html-editor
## -js-editor
## -ugly
.PiggyBank {
@(max) {
@max = max.
@coins = 0.
@smashed = false.
}
add(amount) {
amount = amount or 1.
if @coins < @max and not @busted {
@coins += amount.
}
if @coins < @max {
@coins = @coins
}{
@coins = @max
}
}
amount(value) {
if value {
% value equals @coins.
}
% @coins.
}
smashed() {
% @smashed.
}
smash() {
% @smashed = true.
}
toString() {
% "$" + (@amount() * 0.01).
}
}
#bank = new PiggyBank(500). ## $5
$doc.body.$html += ("<b val>${bank.amount()}</b> <br>").
bank.add().
$doc.body.$html += ("<b val>${bank.amount()}</b> <br>").
bank.add(23).
$doc.body.$html += ("<b val>${bank.toString()}</b> <br>").
</script>
<script src="http://codepen.io/Ephellon/pen/EVxVaJ.js"></script>
body {
background: #000;
color: #fff;
font-family: arial, monospace;
}
b {
color: #ae94c0;
}
[var] {
color: #efc371;
}
[val] {
color: #dd925f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment