AHK Tracks

Post your working scripts, libraries and tools for AHK v1.1 and older
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

AHK Tracks

01 Feb 2022, 17:36

i was bored, coded up a game, theres a bug that sometimes when you land on a special spot, the piece stops moving, just reload the script, have fun!

Code: Select all

SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Gui Font, s9, Segoe UI
Gui Add, GroupBox, h70 w85, Starts
Gui Add, Radio, xm+5 ym+17 vStart Checked, Random
Gui Add, Radio, y+1, Player
Gui Add, Radio, y+1, Computer
Gui Add, Button, xm-1 y+13 w88 Default gStart, Start
Gui Show, , Window
p1_moves := ["x68 y17", "x106 y17", "x144 y17", "x182 y17", "x220 y17", "x258 y17", "x296 y17", "x296 y55"
, "x296 y93", "x258 y93", "x220 y93", "x182 y93", "x144 y93", "x106 y93", "x68 y93", "x30 y93", "x30 y131"
, "x30 y168", "x68 y168", "x106 y168", "x144 y168", "x182 y168", "x220 y168", "x258 y168", "x296 y168"]
p2_moves := ["x68 y33", "x106 y33", "x144 y33", "x182 y33", "x220 y33", "x258 y33", "x296 y33", "x296 y71"
, "x296 y109", "x258 y109", "x220 y109", "x182 y109", "x144 y109", "x106 y109", "x68 y109", "x30 y109", "x30 y147"
, "x30 y184", "x68 y184", "x106 y184", "x144 y184", "x182 y184", "x220 y184", "x258 y184", "x296 y184"]
return

GuiEscape:
GuiClose:
    ExitApp

Start:
Gui, Submit
if (Start = 1)
	Random, WhoStarts, 1, 2
else
	WhoStarts := Start-1
Turn := WhoStarts 
Gui, New
Gui, 2:Default
Gui, Add, Picture, , %A_Desktop%\Track.png
Gui, Add, Radio, w13 h13 x30 y17 ;+38
Gui, Add, Radio, w13 h13 x30 y33 ;+38
Gui, Add, Button, y220 xm gRoll, Roll Dice
Gui, Font, Bold
Gui, Add, Text, x+210 yp+3 +cWhite, Rolled: 0
GUi, Font
GuiControl, , Button%WhoStarts%, 1
Gui, Show, , AHK Tracks
if (Turn = 1)
	Gui, Color, Red, White
else
{
	Gui, Color, Blue, White
	GuiControl, Disable, Button3
	Goto, Roll
}
return

Roll:
GuiControl, , Static2, % "Rolled: " Rolled := Dice()
Loop, % Rolled
{
	p%Turn% += 1
	GuiControl, Move, Button%Turn%, % p%Turn%_moves[p%Turn%]
	Sleep, 100
	if (p%Turn% > 24)
	{
		if (Turn = 1)
			Msgbox, You've won!
		else
			Msgbox, I've won!
		MsgBox 0x24, , The game has finished. Play again?
		ifMsgBox, Yes
			Reload
		else ifMsgBox, No
			ExitApp
		ExitApp
	}
}
if (p%Turn% = 5 || p%Turn% = 10 || p%Turn% = 15 || p%Turn% = 20)
{
	newplace := MysteryCard(p%Turn%)
	p%Turn% := Round(newplace)
	GuiControl, Move, Button%Turn%, % p%Turn%_moves[p%Turn%]
}
Turn := (Turn = 1) ? 2 : 1
if (Turn = 1)
{
	Gui, Color, Red, White
	GuiControl, Enable, Button3
}
else
{
	Gui, Color, Blue, White
	GuiControl, Disable, Button3
	Sleep, 1500
	Goto, Roll
}
return

Dice(Sides := 6) {
	Random, DiceOutput, 1, %Sides%
	return DiceOutput
}
MysteryCard(Place) {
	Random, rand, 1, 15
	Random, rand2, 1, 5
	return ((A_Sec*1.18*3.141592/Place*1.5*rand/rand2) > 25) ? Place+Rand/Rand2 : (A_Sec*1.18*3.141592/Place*1.5*rand/rand2)
}
User avatar
labrint
Posts: 383
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: AHK Tracks

02 Mar 2022, 07:07

Well done. Clever use of radio buttons.

I would say the algorithm is very good, and applicable to any dice game. Perhaps more work is needed on the GUI, but you deserve praise.

Similar to Ludo / Snakes and Ladders concept except with just one chip moving per player and no reverse movements.

Though AHK may be a bit limited when it comes to games, I do find myself bored needing to code something. I did something like this that simulates a coin toss with a bet which can be looped to get score for nth number of games. viewtopic.php?f=6&t=100290
User avatar
kunkel321
Posts: 1194
Joined: 30 Nov 2015, 21:19

Re: AHK Tracks

09 Mar 2022, 16:08

Pretty fun :- }
ste(phen|ve) kunkel

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 238 guests