J
Jeff Conrad
Hi,
Using Access 97 at the moment, but the game will work across later versions.
I've created a game in Access.
Why? I'm an Access Junkie, what can I say!
Who says you can't have fun with Access?
(Incidentially, I'd be happy to share it with anyone when completed)
Impress the kids.
Anyway, the game works fine.......for now.
I still need to put a few finishing touches on it and will no doubt probably
have to pose a few questions.
My game grid right now is always the same so it's fun for about one time
only. I need a way to randomize the game grid data so the game will be
different every time. I knew this would be the most challenging part of the
process. I came really close to getting a solution, but hit a brick wall.
The game is a matching-style game. You know, match two tiles and then keep
going until you get all the matches correct. You have to try and remember
where you saw the "other" letter or number. The game is timed and I'll then
build a table to post the best times (that will be the next problem I'm
afraid). Currently I just manually put a letter or number into the Control
Source of each text box on an unbound form like so ="A". Everything fine.
Next step:
Here's what I need to do in "English":
"Randomly fill all 64 text boxes on the grid with the pre-defined game
values so the game is different evey time."
So I thought I should create a table with all the predefined values and then
through code have Access randomly pull a record, stuff the first text box
with the value, mark that record as used (so it won't get pulled again) and
then continue the process until all 64 text boxes are filled. I *thought* I
had it last night, but you'll see why it failed further down.
The table I created is like so:
tblGameData
GameDataID (Autonumber)
GameDataText (Text)
Used (Yes/No)
I only have two records right now for testing.
This structure is not set in stone, if I need to change it, by all means let
me know.
The form is called frmGamePad and the text boxes are txt1, txt2,....txt64
for simplicity.
Here is the code I have right now which is soooo close to working:
Private Sub Form_Open(Cancel As Integer)
Dim Counter As Integer
' Matches number of text boxes
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim SelectString As String
Dim RandomRecord As Integer
For Counter = 1 To 2
' Will be 64, just testing with 2 right now
Randomize
' Reset the seed
RandomRecord = Int((2 * Rnd) + 1)
' Random number between 1 and 2 at the moment
Set db = CurrentDb
SelectString = "SELECT tblGameData.* " _
& "FROM tblGameData " _
& "WHERE (((tblGameData.Used)=False)) " _
& "And ((tblGameData.GameDataID)=" _
& RandomRecord & ");"
' Randomly select a record by matching
' the Autonumber field to the RandomRecord
' But only if the record has not been used
Set rst = db.OpenRecordset(SelectString)
Me("txt" & Counter) = rst!GameDataText
' Fill the text box with the record data
' Now mark the record as used
rst.MoveFirst
With rst
.Edit
rst!Used = -1
.Update
End With
' Close everything
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
' Now loop back through until all text boxes are filled
Next Counter
End Sub
This worked!!!
.......the first time though. :-((
I think you can see why it did not work the next time.
The random number generated MAY pull up an Autonumber for a record that has
already been used. In which case Access coughs up a hairball. Not good.
So, how can I solve this? I keep thinking of ideas, but can't seem to get
anything to work.
Can I make a query that randomly grabs all the records and then stuff the
text boxes?
Any ideas, thoughts, or comments are welcome.
Thanks,
Jeff Conrad
Bend, Oregon
Using Access 97 at the moment, but the game will work across later versions.
I've created a game in Access.
Why? I'm an Access Junkie, what can I say!
Who says you can't have fun with Access?
(Incidentially, I'd be happy to share it with anyone when completed)
Impress the kids.
Anyway, the game works fine.......for now.
I still need to put a few finishing touches on it and will no doubt probably
have to pose a few questions.
My game grid right now is always the same so it's fun for about one time
only. I need a way to randomize the game grid data so the game will be
different every time. I knew this would be the most challenging part of the
process. I came really close to getting a solution, but hit a brick wall.
The game is a matching-style game. You know, match two tiles and then keep
going until you get all the matches correct. You have to try and remember
where you saw the "other" letter or number. The game is timed and I'll then
build a table to post the best times (that will be the next problem I'm
afraid). Currently I just manually put a letter or number into the Control
Source of each text box on an unbound form like so ="A". Everything fine.
Next step:
Here's what I need to do in "English":
"Randomly fill all 64 text boxes on the grid with the pre-defined game
values so the game is different evey time."
So I thought I should create a table with all the predefined values and then
through code have Access randomly pull a record, stuff the first text box
with the value, mark that record as used (so it won't get pulled again) and
then continue the process until all 64 text boxes are filled. I *thought* I
had it last night, but you'll see why it failed further down.
The table I created is like so:
tblGameData
GameDataID (Autonumber)
GameDataText (Text)
Used (Yes/No)
I only have two records right now for testing.
This structure is not set in stone, if I need to change it, by all means let
me know.
The form is called frmGamePad and the text boxes are txt1, txt2,....txt64
for simplicity.
Here is the code I have right now which is soooo close to working:
Private Sub Form_Open(Cancel As Integer)
Dim Counter As Integer
' Matches number of text boxes
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim SelectString As String
Dim RandomRecord As Integer
For Counter = 1 To 2
' Will be 64, just testing with 2 right now
Randomize
' Reset the seed
RandomRecord = Int((2 * Rnd) + 1)
' Random number between 1 and 2 at the moment
Set db = CurrentDb
SelectString = "SELECT tblGameData.* " _
& "FROM tblGameData " _
& "WHERE (((tblGameData.Used)=False)) " _
& "And ((tblGameData.GameDataID)=" _
& RandomRecord & ");"
' Randomly select a record by matching
' the Autonumber field to the RandomRecord
' But only if the record has not been used
Set rst = db.OpenRecordset(SelectString)
Me("txt" & Counter) = rst!GameDataText
' Fill the text box with the record data
' Now mark the record as used
rst.MoveFirst
With rst
.Edit
rst!Used = -1
.Update
End With
' Close everything
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
' Now loop back through until all text boxes are filled
Next Counter
End Sub
This worked!!!
.......the first time though. :-((
I think you can see why it did not work the next time.
The random number generated MAY pull up an Autonumber for a record that has
already been used. In which case Access coughs up a hairball. Not good.
So, how can I solve this? I keep thinking of ideas, but can't seem to get
anything to work.
Can I make a query that randomly grabs all the records and then stuff the
text boxes?
Any ideas, thoughts, or comments are welcome.
Thanks,
Jeff Conrad
Bend, Oregon