Page 1 of 1

CoinSino

Posted: 13 Feb 2019, 18:41
by Vh_
Here's a little game that I made inspired by the #ahk freenode IRC channel. I thought i'd share it with the community. feel free to modify and post your versions, and or high scores! ;)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance,Force

Bank = 1000
Counter = 0
highscore := bank

Gui, Font, s15 cRed, Consolas
Gui, Add, Text, w200 vBet, CoinSino
Gui, Font, s13 cWhite, Consolas
Gui, Add, Text, w200 vTheDice, Roll:
Gui, Font, s10 cWhite, Consolas
Gui, Add, Text, w200 vHiSc0re, HiScore:
Gui, Font, s13 cWhite, Consolas
Gui, Add, Text, w200 vBank, Bank: 1000
Gui, Font, s11 cBlack, Consolas
Gui, Add, Edit, number vBet_amount w100 h25, place bet..
Gui, Add, StatusBar
Gui, Font, s15 cWhite, Consolas
Gui, Add, Button, w100 vRollie gRoll Default, Roll!
Gui, Color, Black
Gui, Font, s3 cWhite, Consolas
Gui, Show, w140 h265, CoinSino
return

Roll:
Gui, Submit, NoHide

GuiControl,, Bet_amount,

ControlGetText, Game_status, Button1, CoinSino

If (Game_status = "Restart")
	GoTo, Start_Over


If (Bet_amount = "")
	return

If (Bet_amount = 0)
{
	msgbox, invalid bet..
	GuiControl,, Bet_amount,
	return
}


Counter++ 
SB_SetText("Bets placed: " . Counter)
If (Bet_amount > Bank)
{
	Msgbox, you don't have that many coins....
	GuiControl,, Bet_amount,
	return
}

random, dice, 0, 100
GuiControl,, TheDice, Roll: %dice%

Final_Score := Bank

If (dice >= 51)
{
	Bank := Bet_amount+Bank
	GuiControl,,Bet, WIN
	GuiControl,,Bank,Bank: %Bank%
}
else if (dice <= 49)
	{
		Bank := bank - Bet_amount
		If (Bank = 0)
		{
			GuiControl,,Bet, GAME OVER!
			GuiControl,,Bank, Bank: %Final_Score%
			GuiControl,, Bet_amount,
			Control, Disable,, edit1, CoinSino
			GuiControl,, Rollie, Restart
			Gui, Submit, NoHide
			return
		}
		GuiControl,,Bet, LOSS
		GuiControl,,Bank,Bank: %Bank%
	}
else if (dice = 50)
{
	GuiControl,,Bet, JACKPOT!
	Bank := bank + Bet_amount * 10
	GuiControl,,Bank,Bank: %Bank%
}
If (highscore < bank)
{
	highscore := bank
	GuiControl,, HiSc0re, HiScore: %bank%
}
ControlFocus, Edit1, CoinSino ;for users who click Roll instead of pressing enter key.
return


Start_Over: 
Bank = 1000
GuiControl,, TheDice, Roll:
GuiControl,, bet, CoinSino
GuiControl,,Bank,Bank: %Bank%
GuiControl,, Rollie, Roll!
Control, Enable,, edit1, CoinSino
ControlFocus, Edit1, CoinSino
return

GuiClose:
ExitApp
Have fun!

Credit tidbit for some help and testing. :)

Re: CoinSino

Posted: 14 Feb 2019, 12:12
by AHKStudent
looks good

add ControlFocus, Edit1, CoinSino on line 98

Re: CoinSino

Posted: 14 Feb 2019, 19:31
by Vh_
AHKStudent wrote:
14 Feb 2019, 12:12
looks good

add ControlFocus, Edit1, CoinSino on line 98
Enter key is set to work with the button, I hadn't thought about anyone using it with a click.I'll add it for users who choose the button method. Thanks! :)