A simple blackjack game. Draws the cards in a custom window, and keeps track of high scores. Future updates may include: betting, multiple players.
Simple save the code in your scripts editor, right click on a channel, and choose blackjack
Bear
;Email any errors, suggestions, or comments to: bearruler@gmail.com
menu channel {
.Blackjack:bj_new
}
alias bj_new {
unset %bj.*
set %bj.game on
window -p @Blackjack
set %bj.h.c $rand(2,10) $rand(2,10)
bj_tot h
set %bj.p.c $replace($rand(2,11) $+ $chr(32) $+ $rand(2,11),11,a)
bj_chkace
.timer 1 1 bj_house
}
alias bj_quit {
unset %bj.*
window -c @blackjack
}
alias bj_tot {
set %bj.t. $+ $1
var %a = 1
while $gettok(%bj. [ $+ [ $1 ] $+ [ . ] $+ [ c ] ],%a,32) {
inc %bj.t. $+ $1 $v1
inc %a
}
}
alias bj_chkace {
var %a = 1
while $gettok(%bj.p.c,%a,32) {
if ($v1 == a) {
dialog -m bjace bjace
halt
}
inc %a
}
bj_tot p
bj_draw
bj_check
}
alias bj_draw {
bj_tot p
bj_tot h
drawrect -f @blackjack $color(background) 1 0 0 700 700
drawrect @blackjack 4 1 20 215 80 30
drawtext @blackjack 4 arial 18 45 220 Hit!
drawrect @blackjack 4 1 120 215 80 30
drawtext @blackjack 4 arial 18 135 220 Stand
drawrect @blackjack 4 1 220 215 80 30
drawtext @blackjack 4 arial 18 245 220 Quit
drawrect @blackjack 4 1 320 215 80 30
drawtext @blackjack 4 arial 18 344 220 New
drawtext @blackjack 4 arial 18 20 180 Player Total: %bj.t.p
drawtext @blackjack 4 arial 18 20 160 Player wins: %pwins
drawtext @blackjack 4 arial 18 20 280 House wins: %hwins
var %a = 1
while $gettok(%bj.p.c,%a,32) {
drawrect @blackjack 4 2 $calc(20 + (100 * (%a - 1))) 20 80 120
drawtext @blackjack 4 arial 16 $calc(25 + (100 * (%a - 1))) 25 $v1
drawtext @blackjack 4 arial 16 $calc(79 + (100 * (%a - 1))) 115 $v1
inc %a
}
%a = 1
if (%bj.game == on) {
drawrect @blackjack 4 2 20 320 80 120
drawtext @blackjack 4 arial 50 45 350 ?
drawtext @blackjack 4 arial 18 20 260 House Total: ?
%a = 2
}
else { drawtext @blackjack 4 arial 18 20 260 House Total: %bj.t.h }
while $gettok(%bj.h.c,%a,32) {
drawrect @blackjack 4 2 $calc(20 + (100 * (%a - 1))) 320 80 120
drawtext @blackjack 4 arial 16 $calc(25 + (100 * (%a - 1))) 325 $v1
drawtext @blackjack 4 arial 16 $calc(79 + (100 * (%a - 1))) 415 $v1
inc %a
}
}
dialog bjace {
option dbu
size -1 -1 55 35
title "BJ Ace"
text "Do you want it to be a 11 or an Ace?",1,5 5 45 30
button "1",2,10 23 10 10
button "11",3,35 23 10 10
}
on *:dialog:bjace:sclick:2,3: {
set %bj.p.c $reptok(%bj.p.c,a,$did($did),1,32)
dialog -x bjace bjace
bj_chkace
}
menu @blackjack {
sclick:bj_clicks $mouse.x $mouse.y
uclick:bj_clickup $mouse.x $mouse.y
}
alias bj_clickup {
if ($inrect($1,$2,220,215,80,30)) { drawrect @blackjack $color(background) 3 220 215 80 30 | drawrect @blackjack 4 1 220 215 80 30 | /bj_quit }
if ($inrect($1,$2,320,215,80,30)) { drawrect @blackjack $color(background) 3 320 215 80 30 | drawrect @blackjack 4 1 320 215 80 30 | /bj_quit | .timer 1 0 /bj_new }
if (%bj.game == off) { halt }
if ($inrect($1,$2,20,215,80,30)) { drawrect @blackjack $color(background) 3 20 215 80 30 | drawrect @blackjack 4 1 20 215 80 30 | /bj_hit }
if ($inrect($1,$2,120,215,80,30)) { drawrect @blackjack $color(background) 3 120 215 80 30 | drawrect @blackjack 4 1 120 215 80 30 | /bj_end }
}
alias bj_clicks {
if ($inrect($1,$2,220,215,80,30)) { drawrect @blackjack 4 3 220 215 80 30 }
if ($inrect($1,$2,320,215,80,30)) { drawrect @blackjack 4 3 320 215 80 30 }
if (%bj.game == off) { halt }
if ($inrect($1,$2,20,215,80,30)) { drawrect @blackjack 4 3 20 215 80 30 }
if ($inrect($1,$2,120,215,80,30)) { drawrect @blackjack 4 3 120 215 80 30 }
}
alias bj_hit {
if (!$bj_check(p)) { bj_end | halt }
set %bj.p.c %bj.p.c $replace($rand(2,11),11,a))
bj_chkace
if (!$bj_check(p)) { bj_end | halt }
}
alias bj_check {
bj_tot p
if (%bj.t.p > 21) {
bj_end
return $false
}
if (%bj.t.p == 21) {
bj_end
return $false
}
return $true
}
alias bj_house {
bj_tot h
if (%bj.t.h >= 17) { halt }
set %bj.h.c %bj.h.c $rand(1,10)
bj_tot h
bj_draw
.timer 1 1 bj_house
}
alias bj_end {
set %bj.game off
bj_draw
if (%bj.t.h == 21) { drawtext @blackjack 4 arial 20 210 180 House Blackjack! House Wins! | inc %hwins }
elseif (%bj.t.p == 21) { drawtext @blackjack 4 arial 20 210 180 Player Blackjack! Player Wins! | inc %pwins }
elseif (%bj.t.h > 21) { drawtext @blackjack 4 arial 20 210 180 House bust! Player Wins! | inc %pwins }
elseif (%bj.t.p > 21) { drawtext @blackjack 4 arial 20 210 180 Player Bust! House Wins! | inc %hwins }
elseif (%bj.t.p > %bj.t.h) { /drawtext @blackjack 4 arial 20 210 180 Player Wins! | inc %pwins }
elseif (%bj.t.p < %bj.t.h) { /drawtext @blackjack 4 arial 20 210 180 House Wins! | inc %hwins }
elseif (%bj.t.p == %bj.t.h) { /drawtext @blackjack 4 arial 20 210 180 Draw! }
else { /drawtext @blackjack 4 arial 20 210 180 Damn errors! }
}