Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word Search Maker
#24
I decided to add the ability to save your puzzles as a JPG file to your local directory where you have this program. 
When you press S to save it, an Input Box will pop up and you can type a name and press OK and then a Message Box will come up saying it's saved and where.
I also added a title name to display on your puzzle if you want. If you don't want one you can just press Enter where it asks for one.

One trick I figured out by myself recently was how to center text to the screen. Today I made it even easier with just 1 line of code: 
nm$ would be the words you want centered and 30 is just the vertical number I chose for the heading.

Code: (Select All)

_PrintString ((_Width / 2) - ((Len(nm$) * 8) / 2), 30), nm$ 'Centers nm$ horizontally

If you want a word directly in the middle of the screen, horizontal and vertical, you can do this:

Code: (Select All)

_PrintString ((_Width / 2) - ((Len(nm$) * 8) / 2), ((_Height / 2)), nm$ 'Centers nm$ horizontally and vertically.

Here is the new update, enjoy!

Code: (Select All)

'Word Search Maker by SierraKen
'May 17, 2025
'With some help by ChatGPT. I was very close by myself, all of the math and arrays are from me, just needed it cleaned up a bit.
'Thank you to B+ for the graphics rotation code to print on printer and also for the idea of seeing the answers to the words.
'Thank you also to PhilofPerth for the idea of still using small letters and converting them to large. Also for using letters instead of numbers on the answers selections.
'Also, thank you PhilofPerth for the idea of putting the instructions on the main page.

'Update: Shifted list of words at the bottom so they are right under the puzzle and centered better for any amount.
'Update: Added ability to save as JPG picture. Also added a title displayed on your puzzle.

Dim word$(24), grid$(18, 18), dir(24), x(24), y(24)

Screen _NewImage(800, 600, 32)
_Title "Word Search Maker - by SierraKen"
begin:
t = 0: num = 0
For a = 1 To 24
    word$(a) = ""
Next a

Cls
Paint (1, 1), _RGB32(255, 255, 255)
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
Print "                                        Word Search Maker"
Print "                                          by SierraKen"
Print: Print: Print
Print "    Instructions"
Print "    ------------"
Print
Print "    A to see an Answer to a Word."
Print "    P to Print on Printer."
Print "    S to Save as JPG picture."
Print "    C to Copy to Clipboard to use with another graphics program."
Print "    Space Bar for another one."
Print "    Esc to Quit."
Print
Print "    Words cannot be over 15 letters long."
Print
Input "    New title name to display (Just press Enter for no title.): ", nm$
Print
Input "    How many words (1-24): ", num
If num > 24 Or num < 1 Or num <> Int(num) Then GoTo begin
Cls
Paint (1, 1), _RGB32(255, 255, 255)
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
Print "    Type one word at a time here for your puzzle."
Print
For w = 1 To num
    words:
    Print Str$(w) + ". ";
    Input word$(w)
    If Len(word$(w)) > 15 Then Print "    Words cannot be over 15 letters long.": Print: GoTo words
    temp$ = ""
    For ii = 1 To Len(word$(w))
        If Mid$(word$(w), ii, 1) <> " " Then temp$ = temp$ + Mid$(word$(w), ii, 1)
    Next ii
    If temp$ <> "" Then word$(w) = temp$ ' Only assign if temp$ changed
    If word$(w) = "" Or word$(w) = " " Or word$(w) = "  " Or word$(w) = "  " Or word$(w) = "    " Or word$(w) = "    " Or word$(w) = "      " Or word$(w) = "      " Or word$(w) = "        " Or word$(w) = "        " Or word$(w) = "          " Then
        Print "        Nothing typed, try again."
        GoTo words
    End If
    For ii = 1 To Len(word$(w))
        If Mid$(word$(w), ii, 1) < Chr$(65) Or (Mid$(word$(w), ii, 1) > Chr$(90) And Mid$(word$(w), ii, 1) < Chr$(97)) Then
            Print "    No numbers or symbols,  try again.": GoTo words
        End If
    Next ii
    For ii = 1 To Len(word$(w))
        If Mid$(word$(w), ii, 1) > Chr$(122) Then
            Print "    No numbers or symbols, try again.": GoTo words
        End If
    Next ii

    For ii = 1 To Len(word$(w))
        If Mid$(word$(w), ii, 1) > Chr$(96) Or Mid$(word$(w), ii, 1) < Chr$(123) Then
            word$(w) = UCase$(word$(w))
        End If
    Next ii

Next w
Cls
Paint (1, 1), _RGB32(255, 255, 255)
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
' Initialize grid
For y = 1 To 18
    For x = 1 To 18
        grid$(y, x) = ""
    Next x
Next y

_PrintString ((_Width / 2) - ((Len(nm$) * 8) / 2), 30), nm$ 'Centers nm$

Randomize Timer
For w = 1 To num
    placement:
    t = t + 1
    If t > 2000 Then
        Print word$(w) + " unable to work with this puzzle, press Enter to start over."
        Input ab$
        t = 0
        GoTo begin
    End If
    dir(w) = Int(Rnd * 8) + 1
    x(w) = Int(Rnd * 18) + 1: y(w) = Int(Rnd * 18) + 1

    ' Ensure the word fits in the selected direction
    If dir(w) = 1 And x(w) + Len(word$(w)) > 18 Then GoTo placement ' Right
    If dir(w) = 2 And x(w) - Len(word$(w)) < 1 Then GoTo placement ' Left
    If dir(w) = 3 And y(w) + Len(word$(w)) > 18 Then GoTo placement ' Down
    If dir(w) = 4 And y(w) - Len(word$(w)) < 1 Then GoTo placement ' Up
    If dir(w) = 5 And (x(w) + Len(word$(w)) > 18 Or y(w) + Len(word$(w)) > 18) Then GoTo placement ' Right-Down
    If dir(w) = 6 And (x(w) - Len(word$(w)) < 1 Or y(w) + Len(word$(w)) > 18) Then GoTo placement ' Left-Down
    If dir(w) = 7 And (x(w) - Len(word$(w)) < 1 Or y(w) - Len(word$(w)) < 1) Then GoTo placement ' Left-Up
    If dir(w) = 8 And (x(w) + Len(word$(w)) > 18 Or y(w) - Len(word$(w)) < 1) Then GoTo placement ' Right-Up

    ' Check for conflicts
    For l = 1 To Len(word$(w))
        cx = x(w): cy = y(w)
        If dir(w) = 1 Then cx = x(w) + l ' Right
        If dir(w) = 2 Then cx = x(w) - l ' Left
        If dir(w) = 3 Then cy = y(w) + l ' Down
        If dir(w) = 4 Then cy = y(w) - l ' Up
        If dir(w) = 5 Then cx = x(w) + l: cy = y(w) + l ' Right-Down
        If dir(w) = 6 Then cx = x(w) - l: cy = y(w) + l ' Left-Down
        If dir(w) = 7 Then cx = x(w) - l: cy = y(w) - l ' Left-Up
        If dir(w) = 8 Then cx = x(w) + l: cy = y(w) - l ' Right-Up

        If grid$(cy, cx) <> "" And grid$(cy, cx) <> Mid$(word$(w), l, 1) Then GoTo placement
    Next l

    ' Place word
    For l = 1 To Len(word$(w))
        cx = x(w): cy = y(w)
        If dir(w) = 1 Then cx = x(w) + l ' Right
        If dir(w) = 2 Then cx = x(w) - l ' Left
        If dir(w) = 3 Then cy = y(w) + l ' Down
        If dir(w) = 4 Then cy = y(w) - l ' Up
        If dir(w) = 5 Then cx = x(w) + l: cy = y(w) + l ' Right-Down
        If dir(w) = 6 Then cx = x(w) - l: cy = y(w) + l ' Left-Down
        If dir(w) = 7 Then cx = x(w) - l: cy = y(w) - l ' Left-Up
        If dir(w) = 8 Then cx = x(w) + l: cy = y(w) - l ' Right-Up

        grid$(cy, cx) = Mid$(word$(w), l, 1)
    Next l
    t = 0
Next w

' Fill empty spaces with random letters
For y = 1 To 18
    For x = 1 To 18
        If grid$(y, x) = "" Then grid$(y, x) = Chr$(Int(Rnd * 26) + 65)
    Next x
Next y

' Display grid with spaces between letters
For y = 1 To 18
    For x = 1 To 18
        Locate y + 5, (x * 2) + 31: Print grid$(y, x); " ";
    Next x
    Print
Next y
listx = 15: listy = 25
If num < 7 Then listx = 46
If num > 6 And num < 13 Then listx = 35
If num > 12 And num < 19 Then listx = 28
For l = 1 To num
    listy = listy + 1
    If listy / 8 = Int(listy / 8) Then
        listy = 26: listx = listx + 20
    End If
    Locate listy, listx: Print word$(l)
Next l

Locate 1, 11: Print "(A)nswer | (P)rint | (S)ave | (C)opy | (Space Bar) For New Puzzle | (Esc) To Quit"

Do
    a$ = InKey$
    If a$ = "a" Or a$ = "A" Then GoSub answers
    If a$ = "s" Or a$ = "S" Then GoSub saving
    If a$ = "c" Or a$ = "C" Then
        Locate 1, 15: Print "                                                                        "
        _Delay .1
        landscape2& = _CopyImage(0)
        _ClipboardImage = landscape2&
        For sz = 0 To 20
            Line (sz, sz)-(800 - sz, 600 - sz), _RGB32(255, 0, 0), B
        Next sz
        _Delay 2
        For sz = 0 To 20
            Line (sz, sz)-(800 - sz, 600 - sz), _RGB32(255, 255, 255), B
        Next sz
        _FreeImage landscape2&
        Locate 1, 11: Print "(A)nswer | (P)rint | (S)ave | (C)opy | (Space Bar) For New Puzzle | (Esc) To Quit"
    End If
    If a$ = "p" Or a$ = "P" Then
        Locate 1, 15: Print "                                                                        "
        _Delay .1
        'printer prep (code from bplus Free Calendar Program)
        YMAX = _Height: XMAX = _Width
        landscape& = _NewImage(YMAX, XMAX, 32)
        _MapTriangle (XMAX, 0)-(0, 0)-(0, YMAX), 0 To(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
        _MapTriangle (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 To(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
        _PrintImage landscape&
        _Delay 2
        _FreeImage landscape&
        Locate 1, 11: Print "(A)nswer | (P)rint | (S)ave | (C)opy | (Space Bar) For New Puzzle | (Esc) To Quit"
    End If
    If a$ = " " Then GoTo begin
    If a$ = Chr$(27) Then End
Loop

answers:
listx = 15: listy = 25
If num < 7 Then listx = 46
If num > 6 And num < 13 Then listx = 35
If num > 12 And num < 19 Then listx = 28
For l = 1 To num
    listy = listy + 1
    If listy / 8 = Int(listy / 8) Then
        listy = 26: listx = listx + 20
    End If
    Locate listy, listx: Print "(" + Chr$(96 + l) + ") " + word$(l)
Next l

Locate 23, 5: Print "Which word letter?"
Do
    pick:
    n$ = InKey$
    If n$ <> "" Then
        If n$ = "a" Or n$ = "A" Then n = 1
        If n$ = "b" Or n$ = "B" Then n = 2
        If n$ = "c" Or n$ = "C" Then n = 3
        If n$ = "d" Or n$ = "D" Then n = 4
        If n$ = "e" Or n$ = "E" Then n = 5
        If n$ = "f" Or n$ = "F" Then n = 6
        If n$ = "g" Or n$ = "G" Then n = 7
        If n$ = "h" Or n$ = "H" Then n = 8
        If n$ = "i" Or n$ = "I" Then n = 9
        If n$ = "j" Or n$ = "J" Then n = 10
        If n$ = "k" Or n$ = "K" Then n = 11
        If n$ = "l" Or n$ = "L" Then n = 12
        If n$ = "m" Or n$ = "M" Then n = 13
        If n$ = "n" Or n$ = "N" Then n = 14
        If n$ = "o" Or n$ = "O" Then n = 15
        If n$ = "p" Or n$ = "P" Then n = 16
        If n$ = "q" Or n$ = "Q" Then n = 17
        If n$ = "r" Or n$ = "R" Then n = 18
        If n$ = "s" Or n$ = "S" Then n = 19
        If n$ = "t" Or n$ = "T" Then n = 20
        If n$ = "u" Or n$ = "U" Then n = 21
        If n$ = "v" Or n$ = "V" Then n = 22
        If n$ = "w" Or n$ = "W" Then n = 23
        If n$ = "x" Or n$ = "X" Then n = 24
        If word$(n) = "" Then GoTo pick
        GoTo nex
    End If
Loop
nex:

For l = 1 To Len(word$(n))
    cx = x(n): cy = y(n)
    Select Case dir(n)
        Case 1: cx = x(n) + l ' Right
        Case 2: cx = x(n) - l ' Left
        Case 3: cy = y(n) + l ' Down
        Case 4: cy = y(n) - l ' Up
        Case 5: cx = x(n) + l: cy = y(n) + l ' Right-Down
        Case 6: cx = x(n) - l: cy = y(n) + l ' Left-Down
        Case 7: cx = x(n) - l: cy = y(n) - l ' Left-Up
        Case 8: cx = x(n) + l: cy = y(n) - l ' Right-Up
    End Select
    Locate cy + 5, (cx * 2) + 30
    Color _RGB32(255, 0, 0)
    Print grid$(cy, cx);
Next l
_Delay 5

For l = 1 To Len(word$(n))
    cx = x(n): cy = y(n)
    Select Case dir(n)
        Case 1: cx = x(n) + l ' Right
        Case 2: cx = x(n) - l ' Left
        Case 3: cy = y(n) + l ' Down
        Case 4: cy = y(n) - l ' Up
        Case 5: cx = x(n) + l: cy = y(n) + l ' Right-Down
        Case 6: cx = x(n) - l: cy = y(n) + l ' Left-Down
        Case 7: cx = x(n) - l: cy = y(n) - l ' Left-Up
        Case 8: cx = x(n) + l: cy = y(n) - l ' Right-Up
    End Select
    Locate cy + 5, (cx * 2) + 30
    Color _RGB32(0, 0, 0)
    Print grid$(cy, cx);
Next l

Locate 23, 5: Print "                        "

listx = 15: listy = 25
If num < 7 Then listx = 46
If num > 6 And num < 13 Then listx = 35
If num > 12 And num < 19 Then listx = 28
For l = 1 To num
    listy = listy + 1
    If listy / 8 = Int(listy / 8) Then
        listy = 26: listx = listx + 20
    End If
    Locate listy, listx: Print "                      "
    Locate listy, listx: Print word$(l)
Next l
n = 0
n$ = ""
Return

saving:

name$ = _InputBox$("Save", "Type a name of file to save without jpg ending.")
If name$ = "" Then GoTo saving
name$ = name$ + ".jpg"
Locate 1, 11: Print "                                                                                    "
_SaveImage name$
path$ = _FullPath$(name$)
_MessageBox "Saved", "Puzzle picture saved as " + name$ + " to " + path$
Locate 1, 11: Print "(A)nswer | (P)rint | (S)ave | (C)opy | (Space Bar) For New Puzzle | (Esc) To Quit"
Return
Reply


Messages In This Thread
Word Search Maker - by SierraKen - 04-02-2025, 01:11 AM
RE: Word Search Maker - by bplus - 04-02-2025, 02:15 AM
RE: Word Search Maker - by SierraKen - 04-02-2025, 02:24 AM
RE: Word Search Maker - by PhilOfPerth - 04-02-2025, 03:21 AM
RE: Word Search Maker - by SierraKen - 04-02-2025, 05:03 AM
RE: Word Search Maker - by SierraKen - 04-02-2025, 05:24 AM
RE: Word Search Maker - by bplus - 04-02-2025, 12:22 PM
RE: Word Search Maker - by SierraKen - 04-02-2025, 04:37 PM
RE: Word Search Maker - by SierraKen - 04-02-2025, 06:46 PM
RE: Word Search Maker - by bplus - 04-02-2025, 06:56 PM
RE: Word Search Maker - by SierraKen - 04-02-2025, 07:11 PM
RE: Word Search Maker - by bplus - 04-02-2025, 07:27 PM
RE: Word Search Maker - by SierraKen - 04-02-2025, 07:49 PM
RE: Word Search Maker - by PhilOfPerth - 04-03-2025, 12:24 AM
RE: Word Search Maker - by bplus - 04-02-2025, 08:37 PM
RE: Word Search Maker - by SierraKen - 04-02-2025, 08:44 PM
RE: Word Search Maker - by SierraKen - 04-03-2025, 01:19 AM
RE: Word Search Maker - by PhilOfPerth - 04-03-2025, 01:22 AM
RE: Word Search Maker - by SierraKen - 04-03-2025, 01:53 AM
RE: Word Search Maker - by SierraKen - 04-03-2025, 05:39 AM
RE: Word Search Maker - by dano - 04-19-2025, 07:55 PM
RE: Word Search Maker - by SierraKen - 04-23-2025, 05:03 AM
RE: Word Search Maker - by SierraKen - 05-06-2025, 06:44 PM
RE: Word Search Maker - by SierraKen - 05-17-2025, 07:23 PM
RE: Word Search Maker - by SierraKen - 05-17-2025, 08:09 PM
RE: Word Search Maker - by euklides - 06-01-2025, 08:33 AM



Users browsing this thread: 2 Guest(s)