Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Stuck on coding

Author
Message
Donald Smith
22
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 7th Sep 2017 04:48
I have an issue (more like a brain freeze). In making a Wheel of Fortune game, I can't figure out how make the code to puzzle count the individual letters and skip to the next line. So, in my code example, the title in the puzzle is "Superstition by Stevie Wonder". The 1st and 4th row equal 12 spaces and the 2nd & 3rd row equal 14 spaces. The word "Superstition" will fill the entire 1st row and the words "by Stevie" (including the space) will be in the 2nd row and the word "Wonder" in the 4th.

But if the phrase is "Star Trek: The Next Generation", the words "Star Trek:" (including the colon) will be in the 1st row, "The Next" in the 2nd and "Generation" in the third.

Any thoughts? Thank you.

[/code]

Rem * Title : Wheel of Fortune
Rem * Author : Donald Smith
hide mouse

Symbols$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ&,'-:?"

REM Letters and puzzle symbols array
DIM Characters$(32)
For FillArray = 1 to 30
Characters$(FillArray) = MID$(Symbols$,FillArray)
REM Loads images A through -
Next FillArray
REM Fills array with : and ? symbols
REM File names for colon & question images are different
REM : is named colon, ? is named question
Characters$(31) = MID$(Symbols$,31)
Characters$(32) = MID$(Symbols$,32)


REM Silver Borders above Thin Light Blue border
ink rgb(192,192,192),0
A = 58: B = 30: C = 578
For Silver = 1 to 2
gosub Borders
Next Silver

REM Thin Light Blue Border
ink rgb(44,217,243),0
A = 59: B = 31: C = 577
gosub Borders

REM Silver Borders below Thin Light Blue border
ink rgb(192,192,192),0
A = 61: B = 33: C = 575
For Silver = 1 to 2
gosub Borders
Next Silver

REM Short horizontal Lines above to attach outside frame to puzzleboard
A = 61 : B = 53 : Horizontal = 1
Gosub Horizlines

REM Short horizontal lines in middle to attach outside frame to puzzleboard
A = 21 : B = 111 : Horizontal = 2
Gosub Horizlines

REM Short horizontal Lines below to attach outside frame to puzzleboard
A = 61 : B = 243 : Horizontal = 3
Gosub Horizlines

REM Double pair of vertical lines to attach outside frame to puzzleboard
A = 150 : B = 33 : C = 150
For Position = 1 to 4
For Frame = 1 to 2
For Attach = 1 to 2
line A, B, A , B + 6
line A + 1, B, A + 1, B + 6
B = 284
Next Attach
A = A + 14 : B = 33
Next Frame
If Position = 2 then C = 110
A = C + (Position * 120)
Next Position

REM Vertical single lines on outside of frame attached to puzzleboard
A = 30 : B = 88 : Vertical = 2
Gosub Vertlines

REM Four single lines in different positions attached to frame & puzzleboard
A = 96 : B = 33 : Vertical = 3
Gosub Vertlines

REM In & outside single vertical lines above to attach frame to puzzleboard
A = 69 : B = 33 : Vertical = 1
Gosub Vertlines

REM Silver Borders above Thick Light Blue border
A = 68: B = 40: C = 568
For Silver = 1 to 2
gosub Borders
Next Silver

REM Thick Light Blue Border
ink rgb(44,217,243),0
A = 74: B = 46: C = 562
For LightBlue = 5 to 0 Step -1
gosub Borders
Next LightBlue

REM Silver Borders below Thick Light Blue border and above green puzzleboard
ink rgb(192,192,192),0
A = 76: B = 48: C = 560
For Silver = 1 to 2
gosub Borders
Next Silver

REM Green border of puzzleboard
ink rgb(11,101,13),0
A = 78: B = 50: C = 558
gosub Borders

REM Horizontal lines between tiles of puzzleboard
line 78,106,558,106
line 78,218,558,218

REM middle line of puzzleboard
line 38,162,598,162

REM 13 vertical lines in puzzleboard
line 78,106,78,218
x = 118
For Downlines = 1 to 11
line x,50,x,274
x = x + 40
Next Downlines
line 558,106,558,218


REM Draw the puzzleboard


REM Begin Drawing Used Letter Board Box on top
REM and End Drawing Info Box on bottom
INK RGB(255,255,255),1
LINE 144, 436, 492, 436
LINE 492, 436, 492, 479
REM Dividing line between used letter and info boxes
LINE 144, 457, 492, 457
REM Dividing line between used letter and info boxes
LINE 492, 479, 144, 479
LINE 144, 479, 144, 436
REM Begin Drawing Used Letter Board Box on top
REM & End Drawing Info Box on bottom


REM Players Positions, Red, Yellow & Blue
INK RGB(190,21,24),1
BOX 144, 397, 259, 431
INK RGB(243,242,2),1
BOX 260, 397, 376, 431
INK RGB(2,1,190),1
BOX 377, 397, 492, 431

Title$ = "superstition by stevie wonder"
Title$ = upper$(Title$)
LetterCount = len(Title$)

REM Holds the individual words in the puzzle
DIM Words$(15)

TotalWords = 0 : Counter = 1
For NextLetter = 1 to LetterCount
If Mid$(Title$,NextLetter) = " " then TotalWords = TotalWords + 1
If Mid$(Title$,NextLetter) = " " then Counter = Counter + 1
If Mid$(Title$,NextLetter) = " " then goto SkipHere1
Words$(Counter) = Words$(Counter) + Mid$(Title$,NextLetter)
SkipHere1:
If NextLetter = LetterCount then TotalWords = TotalWords + 1
next NextLetter

REM Clears info box
INK RGB(0,0,0),1
BOX 145,458,491,478

ink rgb(255,255,255),0
Set Cursor 200, 460
Print "There are ";LetterCount;" letters in the puzzle."
wait (3000)

REM Clears info box
INK RGB(0,0,0),1
BOX 145,458,491,478

ink rgb(255,255,255),0
Set cursor 200, 460
Print "There are ";TotalWords;" words in the puzzle."
wait (3000)

REM Holds the individual words in the puzzle
DIM WordLength(TotalWords)
For Count = 1 to TotalWords
WordLength(Count) = len(Words$(Count))
Next Count


REM Works Fine
For T = 1 to TotalWords
REM Clears info box
INK RGB(0,0,0),1
BOX 145,458,491,478
ink rgb(255,255,255),0
Set Cursor 200, 460
Print "Word ";T;" is ";Words$(T);" and the length is ";WordLength(T);"."
wait (3000)
Next T

REM This section draws the letters in the puzzles

tile = 12 : Row = 1 : Words = 1 : x = 83 : y = Row * 56
For Drawtile = 1 to LetterCount
For Placement = 1 to 32
If Mid$(Title$,Drawtile) = Characters$(Placement) then set cursor x , y : print Mid$(Title$,Drawtile)
If Mid$(Title$,Drawtile) = Characters$(Placement) then x = x + 40
If Mid$(Title$,Drawtile) = " " then x = x + 40
Next Placement
If tile = WordLength(Words) then Words = Words + 1 : Row = Row + 1
If tile = WordLength(Words) and Row = 2 then x = 43 : y = Row * 56 : tile = 14
If tile = WordLength(Words) and Row = 3 then x = 43 : y = Row * 56 : tile = 14
If tile = WordLength(Words) and Row = 4 then x = 83 : y = Row * 56 : tile = 12
Next Drawtile

REM This section draws the letters in the puzzles
do : loop


Borders:
REM Base's the X coordinate of the top left corner of the green puzzleboard
Base = 78
line A ,B ,C ,B
line C ,B ,C ,B + 56
line C ,B + 56,C + 40,B + 56
line C + 40,B + 56,C + 40, 218 + (Base - A)
line C + 40, 218 + (Base - A),C ,218 + (Base - A)
line C ,218 + (Base - A),C, 218 + (Base - A) + 56
line C ,218 + (Base - A) + 56,A, 218 + (Base - A) + 56
line A ,218 + (Base - A) + 56,A, 218 + (Base - A)
line A ,218 + (Base - A),A - 40, 218 + (Base - A)
line A - 40,218 + (Base - A),A - 40,B + 56
line A - 40,B + 56 ,A ,B + 56
line A, B + 56,A, B
A = A - 1 : B = B - 1: C = C + 1
return

Horizlines:
For Frame = 1 to 4
For Attach = 1 to 2
line A, B, A + 6, B
line A, B + 1, A + 6, B + 1
If Horizontal = 1 then A = 569
If Horizontal = 2 then A = 609
If Horizontal = 3 then A = 569
Next Attach
If Horizontal = 1 then A = 61 : B = 79
If Horizontal = 2 then A = 21 : B = B + 33
If Horizontal = 3 then A = 61 : B = 269
Next Frame
return

Vertlines:
For Frame = 1 to 4
For Attach = 1 to 2
line A, B, A , B + 6
line A + 1, B, A + 1, B + 6
If Vertical = 1 then B = 284
If Vertical = 2 then B = 230
If Vertical = 3 then B = 284
Next Attach
If Vertical = 1 then A = 565 : B = 33
If Vertical = 2 then A = A + 24 : B = 88
If Vertical = 2 and Frame = 2 then A = A + 502
If Vertical = 3 then A = A + 122 : B = 33
If Vertical = 3 and Frame = 2 then A = A + 76
Next Frame
return

[code]
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Sep 2017 18:34 Edited at: 8th Sep 2017 16:07
Hi,

This is a good question and can be approached from a few different angles. Off of the top of my head, this is where data statements might come in handy.



The above allows you to keep all of your puzzles and the structure in the data. For the sake of the graphics, you might multiply the line number times the height of the line. nad since each word is stored individually in the array for a particular puzzle number, you would have to remember to space out the words by some value. This same method could be adapted to using a file.
Enjoy your day.
Donald Smith
22
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 10th Sep 2017 05:52
Thanks Latch. I like your explanation and the code. In your reply, you mentioned that this can be approach by a different angles. What would the different angles be? My curiosity is peaked.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 11th Sep 2017 07:27
Hi Donald,

well, here's an example that uses a delimiter in the string. A delimiter is a character or value that ends or separates a data element. When you come upon that delimiter, you perform an instruction. in this case, we want to move to the next line to display the puzzle:



Your code would have to be adapted to use either of the suggestions. You don't want to flat out display the puzzle, but you do want to figure out how to put the words or letters on the correct lines. the examples will do that, you just have to approach it with the game in mind.

Let's say I wanted to display only the S's that were guessed by the player. I've added an input statement to accept a letter. Go ahead an type s when prompted. It uses the same code as above, but will only display the character that matches the input.



Another method would be to store the puzzle as a graphic. You would record the positions of the bitmap that are the letters. For example, you could have all of the letters of the alphabet laid out at the bottom of the screen. Clicking on that particular screen position would return a value. You would match numeric values against values stored in the puzzle. You then display the graphic of the letter inn a similar method to the above using an X and Y position for the letter graphic.

Enjoy your day.
Donald Smith
22
Years of Service
User Offline
Joined: 15th Nov 2002
Location:
Posted: 12th Sep 2017 16:45
Latch, thanks for your ideas and your help> I used your second coding idea and after changing my code to work with yours, everything worked. Thanks again, Latch.

Login to post a reply

Server time is: 2024-11-17 22:41:25
Your offset time is: 2024-11-17 22:41:25