Originally it started out as little chunks of code, then later while playing an actual game of Boggle, i got the idea to turn that lesson into a working model and it was later assembled into what you see below.
It's a functional, albeit more proof-of-concept, Boggle-like game, but I thought I would share it anyway. I saw some other game examples on the forums that were way more advanced, but didn't see Boggle so... here ya go?
It could use a lot of work like a more streamlined GUI code, or a better way to randomize letters, or validate words exist in the puzzle or are actual dictionary words, but like I said, I was just trying to help someone else learn and this is what I ended up with when I finished showing how to use various AHK examples and make something that works.
Feel free to share, improve, etc.
[Edit: Added in Scoring of # of words & Word lengths, Also a check for duplicates]
[Edit: Renamed topic to title of the game... "Crappy Boggle Game"]
preview: https://drive.google.com/open?id=1wkdnjJbq8RSrknE7yMZMMVMxOagqUh_A
Code: Select all
#SingleInstance Force
gosub, scratch
; Gui was made real quick with Smart GUI Creator
Gui, Font, S10 , Verdana
Gui, Add, edit, x250 y9 w240 r18 vscratch, %scratchpadnotes%
; Rules Link
Gui, Font, S10 , Verdana
gui, add, text, x250 y+5 r1 cgray vrules grules, Rules
; Timer
Gui, Font, S10 , Verdana
gui, add, text, x+15 w1200 r1 cblue vtimer, 3 minute timer
; Boggle Grid of Letters
Gui, Font, S25 CDefault, Verdana
Gui, Add, Edit, center ReadOnly x12 y9 w50 h50 vA1, B
Gui, Add, Edit, center ReadOnly x72 y9 w50 h50 vA2, O
Gui, Add, Edit, center ReadOnly x132 y9 w50 h50 vA3, G
Gui, Add, Edit, center ReadOnly x192 y9 w50 h50 vA4, G
Gui, Add, Edit, center ReadOnly x12 y69 w50 h50 vB1, L
Gui, Add, Edit, center ReadOnly x72 y69 w50 h50 vB2, E
Gui, Add, Edit, center ReadOnly x132 y69 w50 h50 vB3, M
Gui, Add, Edit, center ReadOnly x192 y69 w50 h50 vB4, A
Gui, Add, Edit, center ReadOnly x12 y129 w50 h50 vC1, K
Gui, Add, Edit, center ReadOnly x72 y129 w50 h50 vC2, E
Gui, Add, Edit, center ReadOnly x132 y129 w50 h50 vC3, R
Gui, Add, Edit, center ReadOnly x192 y129 w50 h50 vC4, B
Gui, Add, Edit, center ReadOnly x12 y189 w50 h50 vD1, Y
Gui, Add, Edit, center ReadOnly x72 y189 w50 h50 vD2, M
Gui, Add, Edit, center ReadOnly x132 y189 w50 h50 vD3, E
Gui, Add, Edit, center ReadOnly x192 y189 w50 h50 vD4, !
; Time's Up Alert
Gui, Font, S20 CDefault, Verdana
Gui, Add, text, x15 y245 w200 h50 vtimeup cred, ;TIME'S UP!!!!
; Submit Button to scramble new letters.
Gui, Font, S18 , Verdana
Gui, Add, Button, x1 y295 w200 h30 vsubmit gsubmit, Shake the Box!
; Show this thing
Gui, Show, w500 h329, Boggle... kinda
return
; Submit does this:
submit:
gui, submit, nohide
; Begin in 3... 2... 1... GO!
gosub, startgame
; Randomize letters and create letter blocks
Letters = A,A,B,C,D,E,E,E,F,G,H,I,I,J,K,L,M,N,O,O,P,Qu,R,S,T,U,V,W,X,Y,Z,A,B,C,D,E,E,F,G,I,L,M,N,O,P,R,S,T,W
loop, parse, letters, `,
{
l%a_index% = %a_loopfield%
maxletters = %a_index%
}
; Variables for Row 1
Random, pick, 1,%maxletters%
A1 := l%pick%
Random, pick, 1,%maxletters%
A2 := l%pick%
Random, pick, 1,%maxletters%
A3 := l%pick%
Random, pick, 1,%maxletters%
A4 := l%pick%
; Variables for Row 2
Random, pick, 1,%maxletters%
B1 := l%pick%
Random, pick, 1,%maxletters%
B2 := l%pick%
Random, pick, 1,%maxletters%
B3 := l%pick%
Random, pick, 1,%maxletters%
B4 := l%pick%
; Variables for Row 3
Random, pick, 1,%maxletters%
C1 := l%pick%
Random, pick, 1,%maxletters%
C2 := l%pick%
Random, pick, 1,%maxletters%
C3 := l%pick%
Random, pick, 1,%maxletters%
C4 := l%pick%
; Variables for Row 4
Random, pick, 1,%maxletters%
D1 := l%pick%
Random, pick, 1,%maxletters%
D2 := l%pick%
Random, pick, 1,%maxletters%
D3 := l%pick%
Random, pick, 1,%maxletters%
D4 := l%pick%
; Set GUI to the variables
guicontrol,,a1, %a1%
guicontrol,,a2, %a2%
guicontrol,,a3, %a3%
guicontrol,,a4, %a4%
guicontrol,,b1, %b1%
guicontrol,,b2, %b2%
guicontrol,,b3, %b3%
guicontrol,,b4, %b4%
guicontrol,,c1, %c1%
guicontrol,,c2, %c2%
guicontrol,,c3, %c3%
guicontrol,,c4, %c4%
guicontrol,,d1, %d1%
guicontrol,,d2, %d2%
guicontrol,,d3, %d3%
guicontrol,,d4, %d4%
; Start the game & Timer
gosub, Countdown
return
; Rules of Boggle.
rules:
therules =
(
Rules:
The goal of Boggle is to score points by finding words in the random letters in the grid. The letters you use must be touching vertically, horizontally, or diagonally in a chain. You can't skip, or "jump" across letters, or use the same letter twice within a given word.
Scoring:
Points are scored like so:
3-letter words = 1 point
4-letter words = 1 point
5-letter words = 2 points
6-letter words = 3 points
7-letter words = 5 points
8-letter words or greater = 11 points
)
MsgBox % therules
return
; Scratch Pad notes/text pre-game info
scratch:
scratchpadnotes =
(
This is your Scratch Pad.
You can type your discovered words in here once you begin. Click Rules for information about scoring points.
Once you shake up the box, this Scratch Pad area will clear, and the Timer will begin.
)
return
; GUI setup for starting the game. Clear vars etc.
startgame:
GuiControl,, scratch,
begin = 4
loop, 3 {
begin:=begin-1
GuiControl,, timeup, Begin in %begin%
sleep, 1000
}
GuiControl,, timeup, GO
sleep, 750
GuiControl,, timeup,
SetTimer, countdown, 1000
tick = 181
return
; Countdown timer start and what to do when reaching 0
Countdown:
tick:=tick-1
GuiControl,, timer, %tick%
if (tick = 0)
{
settimer, countdown, off
GuiControl,, timeup, TIME'S UP!!!
GuiControl,, timer, You're out of time.
;~ GuiControl,, submit, Shake the Box!
gosub, score
}
return
; Read word list, tally up words and score based on Word length
score:
gui, submit, nohide
totalscore:=8word:=7word:=6word:=5word:=4word:=3word:=score8:=score7:=score6:=score5:=score4:=score3:="0" ; Clear score variables before calculating
scoremessage:=""
; Check for dpulicates
scratchduplicatecheck=
(
%scratch%
)
Sort, scratchduplicatecheck, U
scratch = %scratchduplicatecheck%
loop, parse, scratch, `n
{
countword = %a_index%
length := StrLen(a_loopfield)
if (length = 3) {
3word := 3word+1
}
if (length = 4) {
4word := 4word+1
}
if (length = 5) {
5word := 5word+1
}
if (length = 6) {
6word := 6word+1
}
if (length = 7) {
7word := 7word+1
}
if (length >= 8) {
8word := 8word+1
}
}
if (8word >= 1) {
score8 := ( 8word * 11)
totalscore:=totalscore+score8
ww8 = You had %8word%x 8 letter words worth 11 points each: %score8% points.
scoremessage = %scoremessage%%ww8%`n
}
if (7word >= 1) {
score7 := ( 7word * 5)
totalscore:=totalscore+score7
ww7 = You had %7word%x 7 letter words worth 5 points each: %score7% points.
scoremessage = %scoremessage%%ww7%`n
}
if (6word >= 1) {
score6 := ( 6word * 3)
totalscore:=totalscore+score6
ww6 = You had %6word%x 6 letter words worth 3 points each: %score6% points.
scoremessage = %scoremessage%%ww6%`n
}
if (5word >= 1) {
score5 := ( 5word * 2)
totalscore:=totalscore+score5
ww5 = You had %5word%x 5 letter words worth 2 points each: %score5% points.
scoremessage = %scoremessage%%ww5%`n
}
if (4word >= 1) {
score4 := ( 4word * 1)
totalscore:=totalscore+score4
ww4 = You had %4word%x 4 letter words worth 1 point each: %score4% points.
scoremessage = %scoremessage%%ww4%`n
}
if (3word >= 1) {
score3 := ( 3word * 1)
totalscore:=totalscore+score3
ww3 = You had %3word%x 3 letter words worth 1 point each: %score3% points.
scoremessage = %scoremessage%%ww3%`n
}
MsgBox, You had %countword% total words:`n%scoremessage%`n`nTOTAL SCORE IS: -- %totalscore% -- POINTS!
return
GuiClose:
ExitApp