Scrabble and Drag / Drop Class

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:31
Joined
May 21, 2018
Messages
9,067
@murray83 started to demo a scrabble game here.

I had a class I have been using to demo moveable controls. I thought I could do something with that. I wanted to see if I could use some "drag and drop" to make this more useable. It worked surprisingly well and makes this feel more like a real game. I have used this moveable control class on several projects and it provides some real utility.

I recently worked with another member on a Risk database and was able to use to use this idea very successfully in tagging risks on schematics of a work location. I figured I try that with simulating a Scrabble tile.

The drag and drop was really easy to implement since I simply reused an existing class. Since that was easy and worked so well, I ended up going down the rabbit hole to see what it would take to make a complete game. That part became very labor intensive. The hard part is the flow of the game and the synchronizing and showing / hiding of buttons and other controls. Nothing real technical but requires a lot of clean code called at the right time. Then you have to account for all the caveats. Player wants to exchange a tile/s, player wins a challenge, player loses a challenge, player creates more than one word, player must play the center tile. Each feature simply added on to the next.

The other thing I wanted to try was finding all words created and score them properly. I thought this would be very challenging and require a complex breadth first or depth first search using a connected graph. Something demonstrated here, and others I have done.

But after some thought spanning all possible words can be done in a simple loop and does not require complex search techniques.

The video demonstrates how to play. It is pretty useable.
Features include.
1. Players choosing tiles to go first
2. Can exchange tiles and lose turn
4. Can accept a played word or challenge it
5. Can search for the challenged word
6 Can win a challenge and current player tiles removed from board
7. Can lose a challenge and challenging player then loses your turn
8. Can find all created words and shows the details for each scored word. It figures out if the Multipliers (Double/Triple leter, Double/Triple word) get applied because they were played in current round not previously on the board.
9. Will draw tiles until no more tiles. (I think. I have not played a full game yet)
10. Allows you to skip if you cannot play a word
11. Adds 50 point bonus if using all 7 letters.
12. Adds and subtracts points when game over and players have tiles in hand.
13. Shows number of each letter played along with total amount.
14. Searchable library

The logic on this is actually very simple.
There is really only one data table. TblGameLetters. It has all information about each letter: Value, SortOrder (set at beginning of game/exchange), status (inhand, onboard, played), what grid it was played in, who played it, when played (round, player turn counter).
Letters that have not been played or in a player had are "popped" off the top and the status is updated. If they are exchanged the status is updated.

There is another table TblBoard that has every control that makes up the board, its multiplier (DW, TW, DL, TL), row, col, and color. The control name is pushed into the tblGameLetters as foreign key once it is played linking the two tables. The row and col allow spanning the grid squares to determine words created.

I think it is pretty useable. I have played a couple games by myself. Simple and easy. I have not tried it with two players, but in theory it could be done because only one hand is shown at a time. It might need a couple more pop up messages to allow a player to click before showing their tiles.

However this is really for demo purposes only to show some things that can be done in access and might be interesting to others. I am sure if you really wanted to play scrabble, an on-line version would be the way to go.

Overview of features:

Demo two words scored:
 

Attachments

THAT Looks and sounds amazing (y)will have to check it out at home this afternoon
 
2nd - The ? tile which is for the blank. is there a way you could make it so can input what letter you require ?
3rd - can it be made to shuffle the letters ( i did this in my last version ) but not sure how you would implement in yours, im just casing you would shuffle the letters and not move the tiles
2. Yes, I have to think of an easy way to do that. You want to be able to but it on the board and at that time specify what letter it is, but if it gets pulled off (like a challenge) then it needs to go back to a ?. Then I have to figure out how to score it as a 0 and not the letter shown I believe to do this I have to add another field to the tblGameLetters for "AlternateDisplay". Then whey you play a ? it asks you what you want to display and saves that letter. Then when you display it does an if check to see if alternate display has a value and uses that instead.

3.This may be somewhat easy. If I drag a tile that is in the hand over another tile it will swap their locations. I somewhat already have code like that to align a tile to a grid on the board.
 
@murray83
Needs some validation, but appears to work. This version allows reordering tiles in hand by dragging them on top of another tile and they switch position.

Have not added the feature for the question mark.

@murray83
You asked about how I was able to do this so clean.
1. I am not building this from scratch. A lot of code, concepts, and design comes from other applications and years of doing this
2. Writing good code is like having a giant box of organized Legos. Code is designed to be reused, flexible, and encapsulated. So you just plug pieces together and add existing groups of pieces.
 

Attachments

Last edited:
This should allow you to tell what letter you want for the ?. Then these will be identified in red font. If you drag the off the board then they go back.
To test this
1. Start a new game and then minimize the game.
2. Go to the tblGameLetters as set the letterorder for the ?s to something like 5 and 10.
3. Continue the game.

after I posted I noticed a problem with one function in mdlUtilities. It should read
Code:
Public Function isLetter(strLetter As String)
  strLetter = Trim(strLetter)
  If Len(strLetter) > 0 Then
    strLetter = Left(strLetter, 1)
    strLetter = UCase(strLetter)
    If Asc(strLetter) >= Asc("A") And Asc(strLetter) <= Asc("Z") Then isLetter = True
  End If
End Function
 

Attachments

Last edited:
This should allow you to tell what letter you want for the ?. Then these will be identified in red font. If you drag the off the board then they go back.
To test this
1. Start a new game and then minimize the game.
2. Go to the tblGameLetters as set the letterorder for the ?s to something like 5 and 10.
3. Continue the game.

after I posted I noticed a problem with one function in mdlUtilities. It should read
Code:
Public Function isLetter(strLetter As String)
  strLetter = Trim(strLetter)
  If Len(strLetter) > 0 Then
    strLetter = Left(strLetter, 1)
    strLetter = UCase(strLetter)
    If Asc(strLetter) >= Asc("A") And Asc(strLetter) <= Asc("Z") Then isLetter = True
  End If
End Function

I Have to say firstly again WOW. amazing

just played a few rounds till i got a ? and worked just as you would like

also the player board shuffle function is also ACE

but haven't ran into an issue with the code posted yet ?

sorry one last edit of post for the week. when placing letters/tiles you can place when not touching another tile so for example you can leave a gap but had a look at your code and i see ( and presume ) it looks at neighbor before allowing ( but that could of also been for scoring )

again

its a masterpiece
 
Last edited:
but haven't ran into an issue with the code posted yet ?
If you get the Input box to give the ? a letter value and do not put in anything it will throw an error. May also do that on an illegal value like !@#$$%^...

sorry one last edit of post for the week. when placing letters/tiles you can place when not touching another tile so for example you can leave a gap but had a look at your code and i see ( and presume ) it looks at neighbor before allowing ( but that could of also been for scoring )
This is not done yet. If a player puts a word down and it does not touch any existing word (after the first player), I do not yet have a check for that yet. So they could have a floating word. And if they then hit submit it would go forward.
In the short term the player can challenge. Type in some bogus word and hit reject. This would remove the tiles from the board and the player would lose their turn.

I need to work on it. Some of that code exists already. I already check the tiles the first time to make sure they are using the center. I loop the tiles to find the created words. So this is a modification of those to see if every tile has a neighbor and that at least one tile is touching an existing letter.

Again, my goal was not really to make a game, although I got carried away. It was to demo some features. If you want to make other games in VBA then I imagine this drag and drop may be useful. To do the basics is very easy. The code all exists in two classes and you just call it and add controls to the class. If you want to collaborate or get explanation on how to use it on something just hit me up.
 
Here is a partial fix.
If you place a word on the board and do not touch an existing word it will catch that. That is an easy check. You just loop the played tiles and make sure at least one is touching an existing letter. The harder check which I would have to think about. Suppose you play the word "CAT". If one of those letters touch something then it would pass the check. But the other letters could be floating somewhere. Or touching letters but not connected in any way to the other letters. It is not realistic, but could happen.
 

Attachments

Users who are viewing this thread

Back
Top Bottom