here is my version of your script
Features:
- mute disabled ( since some people listen to music while playing)
- new game or reload cards does not destroy the main gui
- resource folder set to %a_scriptdir%\BlackJack
Edit:
Added:
-played hands
-save/load game (in tray menu)
-msgbox replaced by a msgbox like gui that is more apropiate for the main gui
Code:
#SingleInstance Force
#Persistent
#NoEnv
SetBatchLines, -1
Total_Amount = 200
Save_Key = BlackJack_WNK_MOD
SoundPlay = Off
game:=0
cancelcount:=0
BlackJack_Dir = %A_ScriptDir%\BlackJack ; C:\Documents and Settings\%A_UserName%\BlackJack
IfExist, %BlackJack_Dir%
{
SetWorkingDir, %BlackJack_Dir%
Gosub, TrayMenu
Loop, %BlackJack_Dir%\*.*
File_Cnt = %A_Index%
If File_Cnt < 71
GoSub, Load_Files
Else
{
SplashImage, BlackJack_Logo.bmp, B
Sleep, 3000
SplashImage, Off
Progress, Off
}
}
IfNotExist, %BlackJack_Dir%
{
FileCreateDir, %BlackJack_Dir%
SetWorkingDir, %BlackJack_Dir%
If ErrorLevel = 1
ExitApp
GoSub, Load_Files
}
;New_Game:
Gui, Destroy
Gui, Margin, 0, 0
SetTimer, Flasher, Off
Gui +LastFound
hWnd := WinExist()
hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-6,"Uint","0x400")
DllCall("DrawMenuBar","Int",hWnd)
Cnt = 0
Bet = Off
Stand = Off
Split = Off
Card_List =
DoubleDown =
Split_Hand =
Dealer_Hand =
Player_Hand =
Split_Hand_1 =
Split_Hand_2 =
Progress = Off
Insurance = Off
Player_Ace_Cnt = 0
Dealer_Ace_Cnt = 0
Player_Hit_Cnt = 3
Dealer_Hit_Cnt = 3
Double_Down_Cnt = 4
Double_Bet_Amount = 0
Split_Hand_1_Hit_Cnt = 3
Split_Hand_2_Hit_Cnt = 3
DoubleDown_Split_Hand_1 = No
DoubleDown_Split_Hand_2 = No
Loop, 5
{
Dealer_Card_%A_Index%_Value = 0
Player_Card_%A_Index%_Value = 0
Split_Hand_1_Card_%A_Index%_Value = 0
Split_Hand_2_Card_%A_Index%_Value = 0
}
Gui, Add, Picture, , BlackJack_Table.bmp
Gui, Add, Picture, gInsurance vInsurance x311 y226, Insurance.bmp
Gui, Add, Picture, vInsurance_Chip x505 y220
Gui, Add, Picture, vChip_Stack_1 x110 y233
Gui, Add, Picture, vChip_Stack_2 x637 y233
Gui, Add, Picture, vDealer_Card_1 x330 y110
Gui, Add, Picture, vDealer_Card_2 x350 y110
Gui, Add, Picture, vDealer_Card_3 x370 y110
Gui, Add, Picture, vDealer_Card_4 x390 y110
Gui, Add, Picture, vDealer_Card_5 x410 y110
Gui, Add, Picture, vPlayer_Card_1 x199 y307
Gui, Add, Picture, vPlayer_Card_2 x286 y307
Gui, Add, Picture, vPlayer_Card_3 x373 y307
Gui, Add, Picture, vPlayer_Card_4 x460 y307
Gui, Add, Picture, vPlayer_Card_5 x547 y307
Gui, Add, Picture, vSplit_Hand_1_Card_1 x289 y280
Gui, Add, Picture, vSplit_Hand_1_Card_2 x289 y310
Gui, Add, Picture, vSplit_Hand_1_Card_3 x289 y340
Gui, Add, Picture, vSplit_Hand_1_Card_4 x289 y370
Gui, Add, Picture, vSplit_Hand_1_Card_5 x289 y400
Gui, Add, Picture, vSplit_Hand_2_Card_1 x458 y280
Gui, Add, Picture, vSplit_Hand_2_Card_2 x458 y310
Gui, Add, Picture, vSplit_Hand_2_Card_3 x458 y340
Gui, Add, Picture, vSplit_Hand_2_Card_4 x458 y370
Gui, Add, Picture, vSplit_Hand_2_Card_5 x458 y400
Gui, Font, s11 Bold
Gui, Add, Button, vDouble_Down x007 y505 w100 h35, Double Down
Gui, Font, s12 Bold
Gui, Add, Button, vSurrender x118 y505 w100 h35, Surrender
Gui, Add, Button, vSplit x229 y505 w100 h35, Split
Gui, Add, Button, vHit x340 y505 w100 h35, Hit
Gui, Add, Button, vStand x451 y505 w100 h35, Stand
Gui, Add, Button, vDeal x562 y505 w100 h35, Deal
Gui, Add, Text, x90 y288 cRed Backgroundtrans vHand_1_Bet w70
Gui, Add, Text, x650 y288 cRed Backgroundtrans vHand_2_Bet w70
Gui, Font, s14 Bold
Gui, Add, Text, x302 y108 cYellow Backgroundtrans vDealer_Hand_Cnt w25
Gui, Add, Text, x400 y420 cYellow Backgroundtrans vPlayer_Hand_Cnt w25
Gui, Add, Text, x255 y280 cYellow Backgroundtrans vSplit_Hand_1_Cnt w25
Gui, Add, Text, x545 y280 cYellow Backgroundtrans vSplit_Hand_2_Cnt w25
Gui, Font, s24 Bold cRed
Gui, Add, Text, Backgroundtrans x670 y506, $
Gui, Font, s13 Bold cRed
Gui, Add, Text, Backgroundtrans x693 y482 vBet_Amount_Text, Bet Amount
Gui, Font, s14 Bold cLime
Gui, Add, Text, Backgroundtrans x7 y150, Total Amount
Gui, Font, s16
Total_Amount := Ceil(Total_Amount)
Gui, Add, Text, Backgroundtrans x7 y175 vtamount w200, $ %Total_Amount%
Gui, Add, Text, Backgroundtrans x7 y455 w200, Hands played:
Gui, Add, Text, Backgroundtrans x7 y475 vhands_played w200, %A_space%%A_space%%game%
Gui, Font, s18 Bold cRed
Gui, Add, Edit, x692 y505 w100 h35 Number Limit vBet_Amount, %BetAmount%
GuiControl, Disable, Surrender
GuiControl, Disable, Double_Down
GuiControl, Disable, Split
GuiControl, Disable, Hit
GuiControl, Disable, Stand
GuiControl, Disable, Deal
Gui, Show, Center AutoSize, BlackJack
SetTimer, Check_Bet_Amount, 250
If Total_Amount = 0
{
SetTimer, Check_Bet_Amount, Off
GuiControl, Disable, Deal
yPos = 150
PosVar = Minus
Gui, 4:+AlwaysOnTop -Border +Owner
Gui, 4:Font, s60 Bold cRed
Gui, 4:Color, Black
Gui, 4:Add, Text, vText Backgroundtrans, GAME OVER
Gui, 4:Show
Loop
{
If PosVar = Plus
yPos++
If PosVar = Minus
yPos--
GuiControl, 4:Move, Text, y%yPos%
If yPos = -25
PosVar = Plus
If yPos = 115
PosVar = Minus
If A_Index = 9487
Break
}
If SoundPlay = On
SoundPlay, GameOver.wav, Wait
gameover = true
gosub New_game
Return
}
If SoundPlay = On
SoundPlay, Shuffle.wav, Wait
Return
ButtonDeal:
Gui, Submit, NoHide
If Bet_Amount > %Total_Amount%
{
If SoundPlay = On
SoundPlay, Error.wav
;MsgBox, 8208, BlackJack, You do not have enough money to make this bet.`n`n%A_Tab%%A_Space%%A_Space%Please bet again.
msgbox("You do not have enough money.Please bet again.","OK")
GuiControl, , Bet_Amount, %Total_Amount%
Return
}
BetAmount = %Bet_Amount%
GuiControl, , Hand_1_Bet, $%Bet_Amount%
GuiControl, , Chip_Stack_1, Chip_Stack.bmp
If SoundPlay = On
SoundPlay, Bet.wav, Wait
SetTimer, Check_Bet_Amount, Off
GoSub, Get_Card
Player_Card_1 = %Card%
Player_Card_1_Value = %Card_Value%
Player_Card_1_Pic = %Pic%
GuiControl, , Player_Card_1, %Player_Card_1_Pic%
GoSub, Get_Card
Dealer_Card_1 = %Card%
Dealer_Card_1_Value = %Card_Value%
Dealer_Card_1_Pic = %Pic%
GuiControl, , Dealer_Card_1, Dealer_Down_Card.bmp
GoSub, Get_Card
Player_Card_2 = %Card%
Player_Card_2_Value = %Card_Value%
Player_Card_2_Pic = %Pic%
GuiControl, , Player_Card_2, %Player_Card_2_Pic%
Player_Hand = %Player_Card_1%,%Player_Card_2%
GoSub, Get_Card
Dealer_Card_2 = %Card%
Dealer_Card_2_Value = %Card_Value%
Dealer_Card_2_Pic = %Pic%
GuiControl, , Dealer_Card_2, %Dealer_Card_2_Pic%
Dealer_Hand = %Dealer_Card_1%,%Dealer_Card_2%
GuiControl, Disable, Deal
GuiControl, Enable, Hit
GuiControl, Enable, Stand
GuiControl, Enable, Surrender
GoSub, Dealer_Hand_Cnt
GoSub, Player_Hand_Cnt
Double_Bet_Amount := (Bet_Amount + Bet_Amount)
If Double_Bet_Amount <= %Total_Amount%
GuiControl, Enable, Double_Down
If Player_Card_1 = %Player_Card_2%
If Double_Bet_Amount <= %Total_Amount%
GuiControl, Enable, Split
If (Player_Card_1_Value + Player_Card_2_Value = 21)
{
GuiControl, Disable, Surrender
GuiControl, Disable, Double_Down
GuiControl, Disable, Split
GuiControl, Disable, Hit
GuiControl, Disable, Stand
GuiControl, Disable, Deal
Sleep, 1000
yPos = 150
PosVar = Minus
Gui, 4:-Border +Owner +AlwaysOnTop
Gui, 4:Color, Black
Gui, 4:Font, s60 Bold cTeal
Gui, 4:Add, Text, vText Backgroundtrans, BlackJack
Gui, 4:Submit, NoHide
Gui, 4:Show, AutoSize
Loop
{
If PosVar = Plus
yPos++
If PosVar = Minus
yPos--
GuiControl, 4:Move, Text, y%yPos%
If yPos = -25
PosVar = Plus
If yPos = 115
PosVar = Minus
If A_Index = 9487
Break
}
If SoundPlay = On
SoundPlay, BlackJack.wav, Wait
Sleep, 2000
Gui, 4:Destroy
Half_Bet_Amount := (Bet_Amount / 2)
Total_Amount := (Total_Amount + Bet_Amount + Half_Bet_Amount)
Goto, New_Game
}
game:=game+1
GuiControl, , hands_played,%a_space%%a_space%%game%
Return
ButtonHit:
GuiControl, Disable, Double_Down
GuiControl, Disable, Surrender
GuiControl, Disable, Split
Insurance = On
GoSub, Get_Card
If Split = On
{
If Split_Hand = 1
{
Split_Hand_1_Card_%Split_Hand_1_Hit_Cnt% = %Card%
Split_Hand_1_Card_%Split_Hand_1_Hit_Cnt%_Value = %Card_Value%
Split_Hand_1_Card_%Split_Hand_1_Hit_Cnt%_Pic = %Pic%
GuiControl, , Split_Hand_1_Card_%Split_Hand_1_Hit_Cnt%, %Pic%
GoSub, Split_Hand_1_Cnt
If Split_Hand_1_Cnt > 21
{
If SoundPlay = On
SoundPlay, Lose.wav, Wait
;SoundSet, +, , Mute
;MsgBox, 8192, BlackJack, Hand (1) Bust
msgbox("Hand (1) Bust","OK")
;SoundSet, -, , Mute
Split_Hand_1 = Bust
Split_Hand = 2
GoSub, Split_Hand_1_Cnt
GuiControl, Enable, Double_Down
Return
}
If Double_Down_Cnt = 1
{
Split_Hand = 2
DoubleDown_Split_Hand_1 = Yes
GoSub, Split_Hand_1_Cnt
GuiControl, Disable, Double_Down
If (Double_Bet_Amount + Double_Bet_Amount <= Total_Amount)
GuiControl, Enable, Double_Down
Return
}
If Split_Hand_1_Hit_Cnt = 5
Goto, ButtonStand
Split_Hand_1_Hit_Cnt++
Return
}
If Split_Hand = 2
{
Split_Hand_2_Card_%Split_Hand_2_Hit_Cnt% = %Card%
Split_Hand_2_Card_%Split_Hand_2_Hit_Cnt%_Value = %Card_Value%
Split_Hand_2_Card_%Split_Hand_2_Hit_Cnt%_Pic = %Pic%
GuiControl, , Split_Hand_2_Card_%Split_Hand_2_Hit_Cnt%, %Pic%
GoSub, Split_Hand_2_Cnt
If Split_Hand_2_Cnt > 21
{
If SoundPlay = On
SoundPlay, Lose.wav, Wait
;SoundSet, +, , Mute
;MsgBox, 8192, BlackJack, Hand (2) Bust
msgbox("Hand (2) Bust","OK")
;SoundSet, -, , Mute
SetTimer, Flasher, Off
GoSub, Split_Hand_2_Cnt
If Split_Hand_1 = Bust
{
If SoundPlay = On
SoundPlay, Bust.wav, Wait
;SoundSet, +, , Mute
;MsgBox, 8192, BlackJack, Hand (1) Loses!`n`nHand (2) Loses!
msgbox("Hand (1) Loses!`nHand (2) Loses!","OK")
;SoundSet, -, , Mute
If DoubleDown_Split_Hand_1 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
If DoubleDown_Split_Hand_2 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Double_Bet_Amount)
Goto, New_Game
}
Goto, ButtonStand
}
If Double_Down_Cnt = 2
{
DoubleDown_Split_Hand_2 = Yes
Goto, ButtonStand
}
If Split_Hand_2_Hit_Cnt = 5
Goto, ButtonStand
Split_Hand_2_Hit_Cnt++
}
Return
}
Else
{
Player_Card_%Player_Hit_Cnt% = %Card%
Player_Card_%Player_Hit_Cnt%_Value = %Card_Value%
Player_Card_%Player_Hit_Cnt%_Pic = %Pic%
GuiControl, , Player_Card_%Player_Hit_Cnt%, %Pic%
Player_Hand = %Player_Hand%,Player_Card_%Player_Hit_Cnt%,
GoSub, Player_Hand_Cnt
If Player_Hit_Cnt = 5
If Player_Hand_Cnt <= 21
Goto, ButtonStand
Player_Hit_Cnt++
}
If Player_Hand_Cnt > 21
{
If SoundPlay = On
SoundPlay, Lose.wav, Wait
;SoundSet, +, , Mute
If Double_Down_Cnt = 0
Bet_Amount = %Double_Bet_Amount%
Total_Amount := (Total_Amount - Bet_Amount)
;MsgBox, 8192, BlackJack, You Bust`n`nYou Lose!
msgbox("You Bust`nYou Lose!","OK")
;SoundSet, -, , Mute
Goto, New_Game
}
If Double_Down_Cnt = 0
Goto, ButtonStand
Return
ButtonStand:
If SoundPlay = On
SoundPlay, Stand.wav, Wait
Stand = On
GuiControl, Disable, Double_Down
GuiControl, Disable, Surrender
GuiControl, Disable, Split
GuiControl, Disable, Hit
GuiControl, Disable, Stand
GuiControl, Disable, Deal
If Split_Hand = 1
{
GuiControl, Enable, Double_Down
GuiControl, Enable, Hit
GuiControl, Enable, Stand
Split_Hand = 2
GoSub, Split_Hand_1_Cnt
Return
}
If Split_Hand = 2
{
GuiControl, Disable, Stand
SetTimer, Flasher, Off
GoSub, Split_Hand_2_Cnt
}
GoSub, Player_Hand_Cnt
GoSub, Dealer_Hand_Cnt
GuiControl, , Dealer_Card_1, %Dealer_Card_1_Pic%
Loop:
Loop
{
If Dealer_Hand_Cnt < 17
{
Sleep, 1500
GoSub, Get_Card
Dealer_Card_%Dealer_Hit_Cnt% = %Card%
Dealer_Card_%Dealer_Hit_Cnt%_Value = %Card_Value%
Dealer_Card_%Dealer_Hit_Cnt%_Pic = %Pic%
GuiControl, , Dealer_Card_%Dealer_Hit_Cnt%, %Pic%
Dealer_Hand = %Dealer_Hand%,Dealer_Card_%Dealer_Hit_Cnt%,
GoSub, Dealer_Hand_Cnt
If Dealer_Hit_Cnt = 5
Break
Dealer_Hit_Cnt++
If Dealer_Hand_Cnt >= 17
Break
Goto, Loop
}
Break
}
Sleep, 500
If Split = On
{
If Dealer_Hand_Cnt > 21
{
If Split_Hand_1_Cnt <= 21
{
If DoubleDown_Split_Hand_1 = Yes
Total_Amount := (Total_Amount + Bet_Amount)
Total_Amount := (Total_Amount + Bet_Amount)
Split_Hand_1 = Hand (1) Wins!
}
If Split_Hand_1_Cnt > 21
{
If DoubleDown_Split_Hand_1 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Bet_Amount)
Split_Hand_1 = Hand (1) Loses!
}
If Split_Hand_2_Cnt <= 21
{
If DoubleDown_Split_Hand_2 = Yes
Total_Amount := (Total_Amount + Bet_Amount)
Total_Amount := (Total_Amount + Bet_Amount)
Split_Hand_2 = Hand (2) Wins!
}
If Split_Hand_2_Cnt > 21
{
If DoubleDown_Split_Hand_2 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Bet_Amount)
Split_Hand_2 = Hand (2) Loses!
}
}
If Dealer_Hand_Cnt <= 21
{
If Split_Hand_1_Cnt > 21
{
If DoubleDown_Split_Hand_1 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Bet_Amount)
Split_Hand_1 = Hand (1) Loses!
}
If Split_Hand_2_Cnt > 21
{
If DoubleDown_Split_Hand_2 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Bet_Amount)
Split_Hand_2 = Hand (2) Loses!
}
If Split_Hand_1_Cnt < %Dealer_Hand_Cnt%
{
If DoubleDown_Split_Hand_1 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Bet_Amount)
Split_Hand_1 = Hand (1) Loses!
}
If Split_Hand_2_Cnt < %Dealer_Hand_Cnt%
{
If DoubleDown_Split_Hand_2 = Yes
Total_Amount := (Total_Amount - Bet_Amount)
Total_Amount := (Total_Amount - Bet_Amount)
Split_Hand_2 = Hand (2) Loses!
}
If Split_Hand_1_Cnt <= 21
{
If Split_Hand_1_Cnt > %Dealer_Hand_Cnt%
{
If DoubleDown_Split_Hand_1 = Yes
Total_Amount := (Total_Amount + Bet_Amount)
Total_Amount := (Total_Amount + Bet_Amount)
Split_Hand_1 = Hand (1) Wins!
}
}
If Split_Hand_2_Cnt <= 21
{
If Split_Hand_2_Cnt > %Dealer_Hand_Cnt%
{
If DoubleDown_Split_Hand_2 = Yes
Total_Amount := (Total_Amount + Bet_Amount)
Total_Amount := (Total_Amount + Bet_Amount)
Split_Hand_2 = Hand (2) Wins!
}
}
If Split_Hand_1_Cnt = %Dealer_Hand_Cnt%
Split_Hand_1 = Hand (1) Ties
If Split_Hand_2_Cnt = %Dealer_Hand_Cnt%
Split_Hand_2 = Hand (2) Ties
If Split_Hand_1_Hit_Cnt = 5
If Split_Hand_1_Cnt <= 21
{
Total_Amount := (Total_Amount + Bet_Amount)
Split_Hand_1 = Hand (1) Wins!
}
If Split_Hand_2_Hit_Cnt = 5
If Split_Hand_2_Cnt <= 21
{
Total_Amount := (Total_Amount + Bet_Amount)
Split_Hand_2 = Hand (1) Wins!
}
}
;SoundSet, +, , Mute
;MsgBox, 8192, BlackJack, %Split_Hand_1%`n`n%Split_Hand_2%
msgbox("%Split_Hand_1%`n%Split_Hand_2%","OK")
;SoundSet, -, , Mute
Goto, New_Game
}
Else
{
If Double_Down_Cnt = 0
Bet_Amount = %Double_Bet_Amount%
If Dealer_Hand_Cnt > 21
If Player_Hand_Cnt <= 21
{
If SoundPlay = On
SoundPlay, Win.wav, Wait
;SoundSet, +, , Mute
Total_Amount := (Total_Amount + Bet_Amount)
;MsgBox, 8192, BlackJack, Dealer Bust`n`nYou Win!
msgbox("Dealer Bust`nYou Win!","OK")
;SoundSet, -, , Mute
Goto, New_Game
}
If Dealer_Hand_Cnt <= 21
If Player_Hand_Cnt > %Dealer_Hand_Cnt%
{
If SoundPlay = On
SoundPlay, Win.wav, Wait
;SoundSet, +, , Mute
Total_Amount := (Total_Amount + Bet_Amount)
;MsgBox, 8192, BlackJack, You Win!
msgbox("You Win!","OK")
;SoundSet, -, , Mute
Goto, New_Game
}
If Dealer_Hand_Cnt <= 21
If Player_Hand_Cnt < %Dealer_Hand_Cnt%
{
If SoundPlay = On
SoundPlay, Bust.wav, Wait
;SoundSet, +, , Mute
Total_Amount := (Total_Amount - Bet_Amount)
;MsgBox, 8192, BlackJack, You Lose!
msgbox("You Lose!","OK")
;SoundSet, -, , Mute
Goto, New_Game
}
If Player_Hand_Cnt = %Dealer_Hand_Cnt%
{
If SoundPlay = On
SoundPlay, Tie.wav, Wait
;SoundSet, +, , Mute
;MsgBox, 8192, BlackJack, You Tie...
msgbox("You Tie...","OK")
;SoundSet, -, , Mute
Goto, New_Game
}
}
Goto, New_Game
ButtonSplit:
Split = On
Split_Hand = 1
Insurance = On
If SoundPlay = On
SoundPlay, Bet.wav, Wait
GuiControl, Disable, Double_Down
GuiControl, Disable, Surrender
GuiControl, Disable, Split
GuiControl, Hide, Player_Hand_Cnt
GuiControl, , Hand_2_Bet, $%Bet_Amount%
GuiControl, , Chip_Stack_2, Chip_Stack.bmp
GuiControl, Hide, Player_Card_1
GuiControl, Hide, Player_Card_2
If (Double_Bet_Amount + Bet_Amount <= Total_Amount)
GuiControl, Enable, Double_Down
If Player_Card_1_Value = 11
Player_Card_2_Value = 11
If Player_Card_2_Value = 11
Player_Card_1_Value = 11
Split_Hand_1_Card_1 = %Player_Card_1%
Split_Hand_1_Card_1_Value = %Player_Card_1_Value%
Split_Hand_1_Card_1_Pic= %Player_Card_1_Pic%
Split_Hand_2_Card_1 = %Player_Card_2%
Split_Hand_2_Card_1_Value = %Player_Card_2_Value%
Split_Hand_2_Card_1_Pic= %Player_Card_2_Pic%
GuiControl, , Split_Hand_1_Card_1, %Split_Hand_1_Card_1_Pic%
GuiControl, , Split_Hand_2_Card_1, %Split_Hand_2_Card_1_Pic%
GoSub, Get_Card
Split_Hand_1_Card_2 = %Card%
Split_Hand_1_Card_2_Value = %Card_Value%
Split_Hand_1_Card_2_Pic = %Pic%
GuiControl, , Split_Hand_1_Card_2, %Split_Hand_1_Card_2_Pic%
GoSub, Get_Card
Split_Hand_2_Card_2 = %Card%
Split_Hand_2_Card_2_Value = %Card_Value%
Split_Hand_2_Card_2_Pic = %Pic%
GuiControl, , Split_Hand_2_Card_2, %Split_Hand_2_Card_2_Pic%
GoSub, Split_Hand_1_Cnt
GoSub, Split_Hand_2_Cnt
SetTimer, Flasher, 1000
GoSub, Flasher
Return
Insurance:
If Insurance = On
Return
Insurance = On
If Dealer_Card_2_Value = 11
{
If SoundPlay = On
SoundPlay, Bet.wav, Wait
GuiControl, , Insurance_Chip, Insurance_Chip.bmp
GuiControl, Disable, Surrender
GuiControl, Disable, Double_Down
GuiControl, Disable, Split
GuiControl, Disable, Hit
GuiControl, Disable, Stand
Insurance_Amount := (Bet_Amount / 2)
Gui, 4:+AlwaysOnTop -Border +Owner
Gui, 4:Font, s25 Bold
Gui, 4:Color, Black
Gui, 4:Add, Text, vText cSilver Backgroundtrans, The dealer is checking his cards...
Gui, 4:Show, AutoSize
Sleep, 4000
Gui, 4:Destroy
If (Dealer_Card_1_Value + Dealer_Card_2_Value = 21)
{
GuiControl, , Dealer_Card_1, %Dealer_Card_1_Pic%
GuiControl, , Dealer_Hand_Cnt, 21
Gui, 4:+AlwaysOnTop -Border +Owner
Gui, 4:Font, s25 Bold
Gui, 4:Color, Black
Gui, 4:Add, Text, vText cSilver Backgroundtrans, The dealer has 21`n%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%%A_Space%You Win!
Gui, 4:Show, AutoSize
Sleep, 4000
Gui, 4:Destroy
Total_Amount := (Total_Amount + Insurance_Amount * 2)
Goto, New_Game
}
Gui, 4:+AlwaysOnTop -Border +Owner
Gui, 4:Font, s25 Bold
Gui, 4:Color, Black
Gui, 4:Add, Text, vText cSilver Backgroundtrans, The dealer does not have 21
Gui, 4:Show, AutoSize
Sleep, 4000
Gui, 4:Destroy
Total_Amount:= (Total_Amount - Insurance_Amount)
If Double_Down_Cnt > 0
GuiControl, Enable, Double_Down
GuiControl, Enable, Surrender
GuiControl, Enable, Split
GuiControl, Enable, Hit
GuiControl, Enable, Stand
Return
}
Return
ButtonDoubleDown:
Double_Down_Cnt = 0
If Split = On
{
If Split_Hand = 1
{
Double_Down_Cnt = 1
GuiControl, Enable, Double_Down
}
If Split_Hand = 2
Double_Down_Cnt = 2
}
If Double_Down_Cnt = 0
{
GuiControl, , Hand_2_Bet, $%Bet_Amount%
GuiControl, , Chip_Stack_2, Chip_Stack.bmp
If SoundPlay = On
SoundPlay, Bet.wav, Wait
}
Goto, ButtonHit
ButtonSurrender:
If SoundPlay = On
SoundPlay, Surrender.wav, Wait
;SoundSet, +, , Mute
Total_Amount := (Total_Amount - Bet_Amount / 2)
;MsgBox, 8192, BlackJack, You Surrendered...
msgbox("You Surrendered...","OK")
;SoundSet, -, , Mute
Goto, New_Game
Check_Bet_Amount:
GuiControlGet, Check_Bet_Amount, , Bet_Amount
If Check_Bet_Amount =
GuiControl, Disable, Deal
If Check_Bet_Amount > 0
GuiControl, Enable, Deal
Return
Flasher:
GoSub, Split_Hand_%Split_Hand%_Cnt
Sleep, 600
GuiControl, , Split_Hand_%Split_Hand%_Cnt
Return
Dealer_Hand_Cnt:
Var_1 = Dealer_Hand_Cnt
Var_2 = Dealer_Card
If Stand = On
{
Dealer_Hand_Cnt := (Dealer_Card_1_Value + Dealer_Card_2_Value + Dealer_Card_3_Value + Dealer_Card_4_Value + Dealer_Card_5_Value)
GoSub, Check_Aces
GuiControl, , Dealer_Hand_Cnt, %Dealer_Hand_Cnt%
}
Else
{
Dealer_Hand_Cnt := (Dealer_Card_2_Value + Dealer_Card_3_Value + Dealer_Card_4_Value + Dealer_Card_5_Value)
GoSub, Check_Aces
GuiControl, , Dealer_Hand_Cnt, %Dealer_Hand_Cnt%
}
Return
Player_Hand_Cnt:
Var_1 = Player_Hand_Cnt
Var_2 = Player_Card
Player_Hand_Cnt := (Player_Card_1_Value + Player_Card_2_Value + Player_Card_3_Value + Player_Card_4_Value + Player_Card_5_Value)
GoSub, Check_Aces
GuiControl, , Player_Hand_Cnt, %Player_Hand_Cnt%
Return
Split_Hand_1_Cnt:
Var_1 = Split_Hand_1_Cnt
Var_2 = Split_Hand_1_Card
Split_Hand_1_Cnt := (Split_Hand_1_Card_1_Value + Split_Hand_1_Card_2_Value + Split_Hand_1_Card_3_Value + Split_Hand_1_Card_4_Value + Split_Hand_1_Card_5_Value)
GoSub, Check_Aces
GuiControl, , Split_Hand_1_Cnt, %Split_Hand_1_Cnt%
Return
Split_Hand_2_Cnt:
Var_1 = Split_Hand_2_Cnt
Var_2 = Split_Hand_2_Card
Split_Hand_2_Cnt := (Split_Hand_2_Card_1_Value + Split_Hand_2_Card_2_Value + Split_Hand_2_Card_3_Value + Split_Hand_2_Card_4_Value + Split_Hand_2_Card_5_Value)
GoSub, Check_Aces
GuiControl, , Split_Hand_2_Cnt, %Split_Hand_2_Cnt%
Return
Check_Aces:
If %Var_1% > 21
{
Loop, 5
{
If %Var_2%_%A_Index%_Value = 11
{
%Var_2%_%A_Index%_Value = 1
Goto, %Var_1%
}
}
}
Return
Get_Card:
;01-13 = Spades
;14-26 = Hearts
;27-39 = Clubs
;40-52 = Diamonds
Random, Card, 1, 52
If Card in %Card_List%
Goto, Get_Card
Card_List = %Card_List%%Card%,
If Card between 1 and 13
Suit = S
If Card between 14 and 26
{
Suit = H
Cnt = 14
GoSub, Card_Counter
}
If Card between 27 and 39
{
Suit = C
Cnt = 27
GoSub, Card_Counter
}
If Card between 40 and 52
{
Suit = D
Cnt = 40
GoSub, Card_Counter
}
If Card = 1
Card_Value = 11
If Card between 2 and 10
Card_Value = %Card%
If Card between 11 and 13
Card_Value = 10
Pic = %Suit%%Card%.bmp
If Card = 11
Card = J
IF Card = 12
Card = Q
If Card = 13
Card = K
Sleep, 100
If SoundPlay = On
SoundPlay, Deal.wav, Wait
Return
Card_Counter:
Loop, 13
{
If Card = %Cnt%
Card = %A_Index%
Cnt++
}
Return
TrayMenu:
Menu, Tray, Icon, BlackJack.ico
Menu, Tray, Icon, BlackJack.ico, , 1
Menu, Tray, MainWindow
Menu, Tray, NoStandard
Menu, Tray, DeleteAll
Menu, Tray, Add, BlackJack, BlackJack
Menu, Tray, Tip, BlackJack
Menu, Submenu, Add, Premise of the game, Rules/Instructions
Menu, Submenu, Add, Values of the cards, Rules/Instructions
Menu, Submenu, Add, How the dealer plays his hand, Rules/Instructions
Menu, Submenu, Add, Hitting/Standing, Rules/Instructions
Menu, Submenu, Add, Splitting Pairs, Rules/Instructions
Menu, Submenu, Add, Doubling Down, Rules/Instructions
Menu, Submenu, Add, Surrender, Rules/Instructions
Menu, Submenu, Add, Insurance, Rules/Instructions
Menu, Tray, Add, Rules/Instructions, :Submenu
Menu, Tray, Add, Sounds, Sounds
Menu, Tray, Add, Save, Save
Menu, Tray, Add, Load, Load
Menu, Tray, Add, New Game, NewGame
Menu, Tray, Add, About, About
Menu, Tray, Add, Quit, GuiClose
Menu, Tray, Check, Sounds
Menu, Tray, Default, BlackJack
Return
BlackJack:
Gui, Show, Center AutoSize, BlackJack
Return
Rules/Instructions:
#LTrim
If A_ThisMenuItem = Premise of the game
{
Message =
(
The basic premise of the game is that you want to have a hand value that is closer
to 21 than that of the dealer, without going over 21. Other players at the table are
of no concern. Your hand is strictly played out against the hand of the dealer. The
rules of play for the dealer are strictly dictated, leaving no decisions up to the dealer.
Therefore, there is not a problem with the dealer or any of the other players at the table
seeing the cards in your hand.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = Values of the cards
{
Message =
(
In blackjack, the cards are valued as follows:
An Ace can count as either 1 or 11.
The cards from 2 through 9 are valued as indicated.
The 10, Jack, Queen, and King are all valued at 10.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = How the dealer plays his hand
{
Message =
(
The dealer must play his hand in a specific way, with no choices allowed. "Dealer stands on all 17s".
This is the most common rule. In this case, the dealer must continue to take cards ("hit") until his
total is 17 or greater. An Ace in the dealer's hand is always counted as 11 if possible without the
dealer going over 21. For example, (Ace,8) would be 19 and the dealer would stop drawing cards
("stand"). Also, (Ace,6) is 17 and again the dealer will stand. (Ace,5) is only 16, so the dealer would
hit. He will continue to draw cards until the hand's value is 17 or more. For example, (Ace,5,7) is only
13 so he hits again. (Ace,5,7,5) makes 18 so he would stop ("stand") at that point. This game is also
setup so the maximum number of cards the dealer can draw is 5. If his hand is over 21 with 5 cards
then of coursethe dealer "Bust", but if its not over 21 his hand is considered live and is played
against the players hand at that point no matter what his card count is.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = Hitting/Standing
{
Message =
(
The most common decision a player must make during the game is whether to
draw another card to the hand ("hit"), or stop at the current total ("stand").
This game is also setup so the maximum number of cards you can draw is 5. If
your hand is over 21 with 5 cards then of course you "Bust", but if its not
over 21 your hand is considered live and is played against the dealers hand at
that point no matter what your card count is.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = Splitting Pairs
{
Message =
(
When you are dealt a matching pair of cards you have the ability to split
the hand into two separate hands, and play them independently. Let's say
you are dealt a pair of eights for a total of sixteen. Sixteen is the worst
possible player hand, since it is unlikely to win as is, but is very likely
to bust if you draw to it. Here's a great chance to improve a bad situation.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = Doubling Down
{
Message =
(
This can only be done with a two card hand, before another card has been drawn.
Doubling down allows you to double your bet and receive one, and only one,
additional card to the hand. A good example of a doubling opportunity is when you
hold a total of 11, say a (6,5) against a dealer's upcard of 5. In this case, you have
a good chance of winning the hand by drawing one additional card, so you might as
well increase your bet in this advantageous situation. The amount of the double down
bet in this game is the full bet amount.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = Surrender
{
Message =
(
Surrender offers you as a player the choice to fold your hand,
at the cost of half of the original bet. You must make that
decision prior to taking any other action on the hand. For example,
once you draw a third card, or split, or double down, surrender
is no longer an option.
)
Goto, Rules-Instructions
}
If A_ThisMenuItem = Insurance
{
Message =
(
If the dealer turns an up-card of an Ace, he will offer "Insurance" to the players.
Insurance bets can be made by betting up to half your original bet amount in the
insurance betting stripe in front of your bet (this game has a set amount, which is
set to half the bet amount). The dealer will check to see if he has a 10-value card
underneath his Ace, and if he does have Blackjack, your winning Insurance bet will be
paid at odds of 2:1. You'll lose your original bet of course. Of course, if the dealer
does not have blackjack, you'll lose the insurance bet, and still have to play the original
bet out. If the dealer is showing an Ace and you want insurance, click on the word
'Insurance' on the table as seen in the picture below.
)
Goto, Rules-Instructions
}
Rules-Instructions:
Gui, 3:Destroy
Gui, 3:+AlwaysOnTop +Owner
Gui, 3:Font, s16
Gui, 3:Add, Text, cRed, %A_ThisMenuItem%
Gui, 3:Font, s12
Gui, 3:Add, Text, cNavy, %Message%`n
If A_ThisMenuItem = Insurance
Gui, 3:Add, Picture, , Insurance.bmp
Gui, 3:Show, , BlackJack - Rules/Instructions
#LTrim Off
Return
new_game:
gui 4:destroy
Cnt = 0
Bet = Off
Stand = Off
Split = Off
Card_List =
DoubleDown =
Split_Hand =
Dealer_Hand =
Player_Hand =
Split_Hand_1 =
Split_Hand_2 =
Progress = Off
Insurance = Off
Player_Ace_Cnt = 0
Dealer_Ace_Cnt = 0
Player_Hit_Cnt = 3
Dealer_Hit_Cnt = 3
Double_Down_Cnt = 4
Double_Bet_Amount = 0
Split_Hand_1_Hit_Cnt = 3
Split_Hand_2_Hit_Cnt = 3
DoubleDown_Split_Hand_1 = No
DoubleDown_Split_Hand_2 = No
Loop, 5
{
Dealer_Card_%A_Index%_Value = 0
Player_Card_%A_Index%_Value = 0
Split_Hand_1_Card_%A_Index%_Value = 0
Split_Hand_2_Card_%A_Index%_Value = 0
}
GuiControl, , tamount, $%Total_amount%
GuiControl, Disable, Surrender
GuiControl, Disable, Double_Down
GuiControl, Disable, Split
GuiControl, Disable, Hit
GuiControl, Disable, Stand
GuiControl, Disable, Deal
Split_Hand_1_Card_1 =
Split_Hand_1_Card_1_Value =
Split_Hand_1_Card_1_Pic=
Split_Hand_2_Card_1 =
Split_Hand_2_Card_1_Value =
Split_Hand_2_Card_1_Pic=
Split_Hand_1_Card_2 =
Split_Hand_1_Card_2_Value =
Split_Hand_1_Card_2_Pic =
Split_Hand_2_Card_2 =
Split_Hand_2_Card_2_Value =
Split_Hand_2_Card_2_Pic =
GuiControl, , Dealer_Hand_Cnt,
GuiControl, , Player_Hand_Cnt,
GuiControl, , Hand_1_Bet,
GuiControl, , Hand_2_Bet,
GuiControl, , Split_Hand_1_Card_1,
GuiControl, , Split_Hand_1_Card_2,
GuiControl, , Split_Hand_1_Card_3,
GuiControl, , Split_Hand_1_Card_4,
GuiControl, , Split_Hand_1_Card_5,
GuiControl, , Split_Hand_2_Card_1,
GuiControl, , Split_Hand_2_Card_2,
GuiControl, , Split_Hand_2_Card_3,
GuiControl, , Split_Hand_2_Card_4,
GuiControl, , Split_Hand_2_Card_5,
GuiControl, , Split_Hand_1_Cnt,
GuiControl, , Split_Hand_2_Cnt,
GuiControl, , Chip_Stack_1
GuiControl, , Chip_Stack_2
GuiControl, , Dealer_Card_1
GuiControl, , Dealer_Card_2
GuiControl, , Dealer_Card_3
GuiControl, , Dealer_Card_4
GuiControl, , Dealer_Card_5
GuiControl, , Player_Card_1
GuiControl, , Player_Card_2
GuiControl, , Player_Card_3
GuiControl, , Player_Card_4
GuiControl, , Player_Card_5
SetTimer, Check_Bet_Amount, 250
If Total_Amount = 0
{
SetTimer, Check_Bet_Amount, Off
GuiControl, Disable, Deal
yPos = 150
PosVar = Minus
Gui, 4:+AlwaysOnTop -Border +Owner
Gui, 4:Font, s60 Bold cRed
Gui, 4:Color, Black
Gui, 4:Add, Text, vText Backgroundtrans, GAME OVER
Gui, 4:Show
Loop
{
If PosVar = Plus
yPos++
If PosVar = Minus
yPos--
GuiControl, 4:Move, Text, y%yPos%
If yPos = -25
PosVar = Plus
If yPos = 115
PosVar = Minus
If A_Index = 9487
Break
}
If SoundPlay = On
SoundPlay, GameOver.wav, Wait
Total_Amount = 200
game:=0
GuiControl, , hands_played,%a_space%%a_space%%game%
gosub New_game
Return
}
If SoundPlay = On
SoundPlay, Shuffle.wav, Wait
return
NewGame:
Total_amount:=200
game:=1
Cnt = 0
Bet = Off
Stand = Off
Split = Off
Card_List =
DoubleDown =
Split_Hand =
Dealer_Hand =
Player_Hand =
Split_Hand_1 =
Split_Hand_2 =
Progress = Off
Insurance = Off
Player_Ace_Cnt = 0
Dealer_Ace_Cnt = 0
Player_Hit_Cnt = 3
Dealer_Hit_Cnt = 3
Double_Down_Cnt = 4
Double_Bet_Amount = 0
Split_Hand_1_Hit_Cnt = 3
Split_Hand_2_Hit_Cnt = 3
DoubleDown_Split_Hand_1 = No
DoubleDown_Split_Hand_2 = No
Loop, 5
{
Dealer_Card_%A_Index%_Value = 0
Player_Card_%A_Index%_Value = 0
Split_Hand_1_Card_%A_Index%_Value = 0
Split_Hand_2_Card_%A_Index%_Value = 0
}
GuiControl, , tamount, $%Total_amount%
GuiControl, Disable, Surrender
GuiControl, Disable, Double_Down
GuiControl, Disable, Split
GuiControl, Disable, Hit
GuiControl, Disable, Stand
GuiControl, Disable, Deal
Split_Hand_1_Card_1 =
Split_Hand_1_Card_1_Value =
Split_Hand_1_Card_1_Pic=
Split_Hand_2_Card_1 =
Split_Hand_2_Card_1_Value =
Split_Hand_2_Card_1_Pic=
Split_Hand_1_Card_2 =
Split_Hand_1_Card_2_Value =
Split_Hand_1_Card_2_Pic =
Split_Hand_2_Card_2 =
Split_Hand_2_Card_2_Value =
Split_Hand_2_Card_2_Pic =
GuiControl, , Dealer_Hand_Cnt,
GuiControl, , Player_Hand_Cnt,
GuiControl, , Hand_1_Bet,
GuiControl, , Hand_2_Bet,
GuiControl, , Split_Hand_1_Card_1,
GuiControl, , Split_Hand_1_Card_2,
GuiControl, , Split_Hand_1_Card_3,
GuiControl, , Split_Hand_1_Card_4,
GuiControl, , Split_Hand_1_Card_5,
GuiControl, , Split_Hand_2_Card_1,
GuiControl, , Split_Hand_2_Card_2,
GuiControl, , Split_Hand_2_Card_3,
GuiControl, , Split_Hand_2_Card_4,
GuiControl, , Split_Hand_2_Card_5,
GuiControl, , Split_Hand_1_Cnt,
GuiControl, , Split_Hand_2_Cnt,
GuiControl, , Chip_Stack_1
GuiControl, , Chip_Stack_2
GuiControl, , Dealer_Card_1
GuiControl, , Dealer_Card_2
GuiControl, , Dealer_Card_3
GuiControl, , Dealer_Card_4
GuiControl, , Dealer_Card_5
GuiControl, , Player_Card_1
GuiControl, , Player_Card_2
GuiControl, , Player_Card_3
GuiControl, , Player_Card_4
GuiControl, , Player_Card_5
return
;Reload
Sounds:
Menu, Tray, ToggleCheck, Sounds
If SoundPlay = On
SoundPlay = Off
Else
If SoundPlay = Off
SoundPlay = On
Return
About:
Gui, 2:Destroy
Pos1 = 100
Pos2 = 120
Pos3 = 155
Pos4 = 170
Gui, 2:+AlwaysOnTop +Owner
Gui, 2:Add, Picture, y10 gLogo, AHK.bmp
Gui, 2:Font, s10 Bold
Gui, 2:Add, Text, vText1 x175 y%Pos1%, Written by:
Gui, 2:Font, s14 Bold
Gui, 2:Add, Text, vText2 x172 y%Pos2% cBlue gaCkRiTe, aCkRiTe
Gui, 2:Font, s8 Bold
Gui, 2:Add, Text, vText3 x174 y%Pos3% cRed gVersion, Version 1.0.1
Gui, 2:Add, Text, vText4 x177 y%Pos4% cRed gVersion, 01/10/2007
Gui, 2:Show, h100, About BlackJack
Loop
{
Sleep, 35
Pos1--
Pos2--
Pos3--
Pos4--
GuiControl, 2:Move, Text1, y%Pos1%
GuiControl, 2:Move, Text2, y%Pos2%
GuiControl, 2:Move, Text3, y%Pos3%
GuiControl, 2:Move, Text4, y%Pos4%
If Pos1 = 10
Break
}
Return
Logo:
Run, iexplore.exe http://www.autohotkey.com, Max
Return
aCkRiTe:
Run, iexplore.exe http://www.autohotkey.com/forum/profile.php?mode=viewprofile&u=3082, Max
Return
Version:
Run, iexplore.exe http://www.autohotkey.com/forum/viewtopic.php?t=15988, Max
Return
Create_File:
WriteFile(Image_File . "",Block . "")
WriteFile(File,Blocks)
{
Global
Local Handle, Data, Hex
Handle := DllCall("CreateFile","str",File,"Uint",0x40000000,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
Loop, Parse, Blocks, |
{
Data := %A_LoopField%
GuiControl, , MyProgress, +1
Loop,
{
If StrLen(Data) = 0
Break
StringLeft, Hex, Data, 2
StringTrimLeft, Data, Data, 2
Hex = 0x%Hex%
DllCall("WriteFile","UInt", Handle,"UChar *", Hex,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
}
}
DllCall("CloseHandle", "Uint", Handle)
Return
}
Return
Load_Files:
Msgbox Please Paste the original code from Autohotkey forum by aCkRiTe`nhttp://www.autohotkey.com/forum/viewtopic.php?t=15988
return
msgbox(message,type="OK")
{
Gui, 11:+AlwaysOnTop -Border +Owner
Gui, 11:Color, Black
gui, 11:font, s14 bold cred
Gui, 11:Add, Text, x16 y21 w260 h60 Backgroundtrans 0x1, %message%
gui, 11:font
if type= YES/NO
{
Gui, 11: Add, Button, x26 y91 w110 h30 gmsgYES, YES
Gui, 11: Add, Button, x166 y91 w120 h30 gmsgNO, NO
}
if type= OK
Gui, 11:Add, Button, x86 y91 w120 h30 gmsgOK, OK
Gui, 11: Show ;,h135 w280
;Gui +Disabled
pause
}
msgOK:
;Gui -Disabled
pause off
Gui, 11: Destroy
return
msgYES:
pause off
Gui, 11: Destroy
gosub save
return
msgNO:
pause off
Gui, 11: Destroy
gosub Close
return
save:
cancelcount:=0
save1:
gui +owndialogs
FileSelectFile, saveas , S16, %A_scriptdir%, Please select a name for the save, BlackJack Save (*.bjs)
if saveas =
{
cancelcount:=cancelcount+1
if cancelcount<3
{
MsgBox,,BlackJack,Please select a file to save
gosub save1
}
else
return
}
else
{
save_ammount:=Encode(Total_Amount,Save_Key)
save_date:=Encode(A_YYYY . "/" . A_MM . "/" . A_DD,Save_Key)
save_time:=Encode(A_Hour . ":" . A_Min,Save_Key)
save_game:=Encode(game,Save_Key)
save_text:= save_date . "|" . save_time . "|" . save_game . "|" . save_ammount
;save_text:==Encode(save_text,Save_Key)
StringReplace, dir, saveas, .bjs,, All
ifexist %dir%.bjs
filedelete %dir%.bjs
FileAppend , %save_text%, %dir%.bjs
}
;gosub Close
return
load:
gui +owndialogs
FileSelectFile, load , , %A_scriptdir%, Please select the save file to load, BlackJack Save (*.bjs)
if load =
return
else
{
FileReadLine, loadvar, %load%, 1
;loadvar:=Decode(loadvar, Save_Key)
Loop, parse, loadvar, |
{
decode%a_index%:=Decode(A_LoopField, Save_Key)
}
game:= decode3
Total_amount:= decode4
GuiControl, , hands_played,%a_space%%a_space%%game%
gosub new_game
}
return
GuiClose:
save:=msgbox("Do you want to save the curent game?","YES/NO")
Close:
ExitApp
Encode(Text, Key)
{
cKey := Key ;Create copy of "Key"
if % StrLen(Key) < StrLen(Text) ;Need "Key" length to be same as or bigger than "Text"
Loop
{
cKey .= Key ;Key * 2
if % StrLen(cKey) >= StrLen(Text)
break
}
Loop % StrLen(Text)
{
StringMid, t_%A_Index%, Text, %A_Index%, 1 ;Get ASCII value of Text, and ASCII value of Key
StringMid, k_%A_Index%, cKey, %A_Index%, 1 ;then begin to add the values individially ex//
cText.= Chr(Asc(k_%A_Index%) + Asc(t_%A_Index%)) ;Key = ab, Text = cd. Get ASCII value of a, then
} ;add it to ASCII value of c, get ASCII value of
return cText ;b and add to ASCII value of d
}
Decode(Text, Key)
{
cKey := Key
if % StrLen(Key) < StrLen(Text)
Loop
{
cKey .= Key
if % StrLen(cKey) >= StrLen(Text)
break
}
Loop % StrLen(Text)
{
StringMid, t_%A_Index%, Text, %A_Index%, 1
StringMid, k_%A_Index%, cKey, %A_Index%, 1
cText.= Chr(Asc(t_%A_Index%) - Asc(k_%A_Index%))
}
return cText
}