Microsoft Small Basic

Program Listing: XMC288
Sub var
total = 0
bet = 0
mbet = 0
a1 = 0
a2 = 0
a3 = 0
a4 = 0
EndSub
var()
money = 100
suitename = "suitename"
intro()

Sub space
TextWindow.WriteLine(" ")
EndSub

Sub intro
If total > 35 then
TextWindow.Clear()
stay()
EndIf
For x = 1 To 52
Deck[x]="U"
EndFor
TextWindow.Clear()
TextWindow.WriteLine("Blackjack" + " Money: $" + money + " Bet: $" + mbet + " Total: " + total)
space()
space()
if bet = 0 then
bet()
else
TextWindow.WriteLine("1. Hit Me")
TextWindow.WriteLine("2. Stay")
endif
If a1 = 1 then
TextWindow.WriteLine("3. Change the Ace to an 11.")
ElseIf a1 = 2 then
TextWindow.WriteLine("3. Change the Ace to an 1.")
EndIf
If a2 = 1 then
TextWindow.WriteLine("4. Change the Ace to an 11.")
ElseIf a2 = 2 then
TextWindow.WriteLine("4. Change the Ace to an 1.")
EndIf
If a3 = 1 then
TextWindow.WriteLine("5. Change the Ace to an 11.")
ElseIf a3 = 2 then
TextWindow.WriteLine("5. Change the Ace to an 1.")
EndIf
If a4 = 1 then
TextWindow.WriteLine("6. Change the Ace to an 11.")
ElseIf a4 = 2 then
TextWindow.WriteLine("6. Change the Ace to an 1.")
EndIf
commands()
EndSub

sub bet
bet = 1
textwindow.writeline("Press a number corresponding to the bet you want.")
space()
textwindow.writeline("1. $10 2. $25 3. $50 4. $75 5. $100")
space()
moneybet = textwindow.readkey()
space()
if moneybet = 1 and money >= 10 then
mbet = 10
TextWindow.Clear()
intro()
elseif moneybet = 2 and money >= 25 then
mbet = 25
TextWindow.Clear()
intro()
elseif moneybet = 3 and money >= 50 then
mbet = 50
TextWindow.Clear()
intro()
elseif moneybet = 4 and money >= 75 then
mbet = 75
TextWindow.Clear()
intro()
elseif moneybet = 5 and money >= 100 then
mbet = 100
TextWindow.Clear()
intro()
else
TextWindow.Clear()
bet = 0
intro()
endif
EndSub

Sub commandintro
space()
TextWindow.Pause()
TextWindow.Clear()
intro()
EndSub

sub commands
space()
intro = TextWindow.ReadKey()
If a1 = 1 and intro = 3 then
total = total + 10
a1 = 2
commandintro()
elseif a1 = 2 and intro = 3 then
a1 = 1
total = total - 10
commandintro()
EndIf
If a2 = 1 and intro = 4 then
total = total + 10
a2 = 2
commandintro()
elseif a2 = 2 and intro = 4 then
a2 = 1
total = total - 10
commandintro()
EndIf
If a3 = 1 and intro = 5 then
total = total + 10
a1 = 2
commandintro()
elseif a3 = 2 and intro = 5 then
a3 = 1
total = total - 10
commandintro()
EndIf
If a4 = 1 and intro = 6 then
total = total + 10
a4 = 2
commandintro()
elseif a4 = 2 and intro = 6 then
a4 = 1
total = total - 10
commandintro()
EndIf
If intro = 1 Then
suite()
space()
commandintro()
ElseIf intro = 2 then
stay()
Else
TextWindow.Clear()
intro()
EndIf
EndSub

sub suite
If total > 35 then
TextWindow.Clear()
stay()
EndIf
Value = Math.GetRandomNumber(52)
If Deck[Value]="U" Then
Deck[Value]="P"
EndIf
If value >= 1 And Value <= 13 then
suitename = "Spades"
total = total + Value
elseif value >= 14 And Value <= 26 then
suitename = "Hearts"
total = total + (Value - 13)
elseif value >= 27 And Value <= 39 then
suitename = "Clubs"
total = total + (Value - 26)
else
suitename = "Diamonds"
total = total + (Value - 39)
endif
If Value = 1 or Value = 14 or Value = 27 Or Value = 40 then
total = total - 1
TextWindow.WriteLine("You draw the Ace of " + suitename)
space()
TextWindow.WriteLine("1. 1 2. 11")
cardsone = TextWindow.Readkey()
space()
If cardsone = 1 Then
total = total + 1
If a1 = 0 then
a1 = 1
ElseIf a1 = 1 or 2 then
a2 = 1
ElseIf a2 = 1 or 2 then
a3 = 1
ElseIf a3 = 1 or 2 then
a4 = 1
Else
TextWindow.Clear()
intro()
EndIf
ElseIf cardsone = 2 then
total = total + 11
If a1 = 0 then
a1 = 2
ElseIf a1 = 1 or 2 then
a2 = 2
ElseIf a2 = 1 or 2 then
a3 = 2
ElseIf a3 = 1 or 2 then
a4 = 2
Else
TextWindow.Clear()
intro()
EndIf
Else
TextWindow.Clear()
suite()
EndIf
EndIf
If value = 11 or Value = 24 Or Value = 37 Or Value = 50 then
TextWindow.WriteLine("You draw the Jack of " + suitename)
ElseIf value = 12 or Value = 25 or Value = 38 or Value = 51 then
TextWindow.WriteLine("You draw the Queen of " + suitename)
ElseIf value = 13 or Value = 26 or value = 39 or Value = 52 then
TextWindow.WriteLine("You draw the King of " + suitename)
Else
If value >= 1 And Value <= 13 then
Value = Value
elseif value >= 14 And Value <= 26 then
Value = Value - 13
elseif value >= 27 And Value <= 39 then
Value = Value - 26
else
Value = Value - 39
endif
If Value = 1 or Value = 14 or Value = 27 Or Value = 40 then
Else
TextWindow.WriteLine("You draw the " + value + " of " + suitename)
EndIf
EndIf
EndSub

Sub stay
TextWindow.Clear()
dealtotal = Math.GetRandomNumber(13) + Math.GetRandomNumber(13)
If dealtotal < 15 Then
dealtotal = dealtotal + Math.GetRandomNumber(13)
EndIf
TextWindow.WriteLine("You have a total of " + total + ".")
space()
TextWindow.WriteLine("The dealer has a total of " + dealtotal + ".")
space()
If (total > dealtotal) And (total <= 21) or (total < dealtotal) And (total <= 21) and (dealtotal > 21) then
win()
ElseIf (dealtotal > total) And (dealtotal <= 21) or (total > 21) and (dealtotal <= 21) then
lose()
elseif (dealtotal > 21) and (total > 21) or (dealtotal = total) then
tie()
EndIf
EndSub

Sub variables
var()
money = money
For x = 1 To 52
Deck[x]="U"
EndFor
EndSub

Sub win
money = money + mbet
TextWindow.WriteLine("You won $" + mbet + "!!!")
space()
TextWindow.WriteLine("1. Play Again 2. Quit")
win = TextWindow.Readkey()
If win = 1 Then
variables()
intro()
ElseIf win = 2 then
Program.End()
Else
win()
EndIf
EndSub

Sub lose
TextWindow.WriteLine("You lost $" + mbet + "!!!")
space()
money = money - mbet
if money <= 0 then
Program.Delay(3000)
Program.End()
endif
TextWindow.WriteLine("1. Play Again 2. Quit")
lost = TextWindow.Readkey()
If lost = 1 Then
variables()
intro()
ElseIf lost = 2 then
Program.End()
Else
lose()
EndIf
EndSub

Sub tie
TextWindow.WriteLine("You tied!!!")
space()
TextWindow.WriteLine("1. Play Again 2. Quit")
tie = TextWindow.Readkey()
If tie = 1 Then
variables()
intro()
ElseIf tie = 2 then
Program.End()
Else
tie()
EndIf
EndSub