Please help a newbie that is totally confused....
-
I'm making a solitaire game and figured out that the shuffle code doesn't show the Image1(0) card when the cards are shuffled in the design view. So that is one problem. I also am trying to drag and drop images from image1(0) to 12 from the left hand side of the design view to the right hand side where hearts(0) cards are. One thing, the hearts cards already have other bitmaps on them; they are blank boxes to show up for the person playing to automatically drop the image1 card in that slot. Here's what my newbie experience is so far...Oh, I also made tags in the design view to think they might help out. Public Sub Main() Start_Game.Show End Sub Private Sub Exit_Click() MsgBox ("Thank you for playing. Good Bye.") End End Sub Private Sub Start_Click() Dim arrDeck(52) Randomize Dim Cardcount As Integer Dim Counter As Integer Dim Card1 As Integer Dim Card2 As Integer ' Fill deck with cards in order 1 to 52 Do While Cardcount <= 52 arrDeck(Cardcount) = Cardcount Cardcount = Cardcount + 1 Loop ' Shuffle the deck - end value (100) Dim Temp As Image Dim Index As Integer For Index = 0 To 51 For Counter = 0 To 100 Card1 = Int(51 * Rnd) Card2 = Int(51 * Rnd) If (Card1 <> Card2) Then Temp(Index).Picture = Image1(Card1).Picture Image1(Card1).Picture = Image1(Card2).Picture Image1(Card2).Picture = Temp(Index).Picture End If Next Index Next Counter ' Now output images in order For Counter = 0 To 51 Image1(Counter).Visible = True Next Counter End Sub Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Private Sub Image1_Click(Index As Integer) If Image1(Index).Tag = Hearts(Index).Tag Then Image1(Index).Picture = Hearts(Index).Picture Hearts(Index).Picture = Source.Picture &nb
-
I'm making a solitaire game and figured out that the shuffle code doesn't show the Image1(0) card when the cards are shuffled in the design view. So that is one problem. I also am trying to drag and drop images from image1(0) to 12 from the left hand side of the design view to the right hand side where hearts(0) cards are. One thing, the hearts cards already have other bitmaps on them; they are blank boxes to show up for the person playing to automatically drop the image1 card in that slot. Here's what my newbie experience is so far...Oh, I also made tags in the design view to think they might help out. Public Sub Main() Start_Game.Show End Sub Private Sub Exit_Click() MsgBox ("Thank you for playing. Good Bye.") End End Sub Private Sub Start_Click() Dim arrDeck(52) Randomize Dim Cardcount As Integer Dim Counter As Integer Dim Card1 As Integer Dim Card2 As Integer ' Fill deck with cards in order 1 to 52 Do While Cardcount <= 52 arrDeck(Cardcount) = Cardcount Cardcount = Cardcount + 1 Loop ' Shuffle the deck - end value (100) Dim Temp As Image Dim Index As Integer For Index = 0 To 51 For Counter = 0 To 100 Card1 = Int(51 * Rnd) Card2 = Int(51 * Rnd) If (Card1 <> Card2) Then Temp(Index).Picture = Image1(Card1).Picture Image1(Card1).Picture = Image1(Card2).Picture Image1(Card2).Picture = Temp(Index).Picture End If Next Index Next Counter ' Now output images in order For Counter = 0 To 51 Image1(Counter).Visible = True Next Counter End Sub Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Private Sub Image1_Click(Index As Integer) If Image1(Index).Tag = Hearts(Index).Tag Then Image1(Index).Picture = Hearts(Index).Picture Hearts(Index).Picture = Source.Picture &nb
-
I'm making a solitaire game and figured out that the shuffle code doesn't show the Image1(0) card when the cards are shuffled in the design view. So that is one problem. I also am trying to drag and drop images from image1(0) to 12 from the left hand side of the design view to the right hand side where hearts(0) cards are. One thing, the hearts cards already have other bitmaps on them; they are blank boxes to show up for the person playing to automatically drop the image1 card in that slot. Here's what my newbie experience is so far...Oh, I also made tags in the design view to think they might help out. Public Sub Main() Start_Game.Show End Sub Private Sub Exit_Click() MsgBox ("Thank you for playing. Good Bye.") End End Sub Private Sub Start_Click() Dim arrDeck(52) Randomize Dim Cardcount As Integer Dim Counter As Integer Dim Card1 As Integer Dim Card2 As Integer ' Fill deck with cards in order 1 to 52 Do While Cardcount <= 52 arrDeck(Cardcount) = Cardcount Cardcount = Cardcount + 1 Loop ' Shuffle the deck - end value (100) Dim Temp As Image Dim Index As Integer For Index = 0 To 51 For Counter = 0 To 100 Card1 = Int(51 * Rnd) Card2 = Int(51 * Rnd) If (Card1 <> Card2) Then Temp(Index).Picture = Image1(Card1).Picture Image1(Card1).Picture = Image1(Card2).Picture Image1(Card2).Picture = Temp(Index).Picture End If Next Index Next Counter ' Now output images in order For Counter = 0 To 51 Image1(Counter).Visible = True Next Counter End Sub Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Private Sub Image1_Click(Index As Integer) If Image1(Index).Tag = Hearts(Index).Tag Then Image1(Index).Picture = Hearts(Index).Picture Hearts(Index).Picture = Source.Picture &nb
Here is one problem:
Card1 = Int(51 * Rnd)
This will give you a random number with 51 possible values, i.e. from 0 to 50. That means that you are never touching the last card in the deck. You are doing 100 times as much work as you need to in order to shuffle the deck. You don't have to make more than 51 swaps to completely shuffle the deck, you just have to make sure that each card has an equal chance to be swapped into each position in the deck:
For card1 = 0 To 50
card2 = card1 + Int((52 - card1) * Rnd)
If card1 <> card2 Then
Temp = Image1(card1).Picture
Image1(card1).Picture = Image1(card2).Picture
Image1(card2).Picture = Temp
End If
Next IndexDespite everything, the person most likely to be fooling you next is yourself.
-
Here is one problem:
Card1 = Int(51 * Rnd)
This will give you a random number with 51 possible values, i.e. from 0 to 50. That means that you are never touching the last card in the deck. You are doing 100 times as much work as you need to in order to shuffle the deck. You don't have to make more than 51 swaps to completely shuffle the deck, you just have to make sure that each card has an equal chance to be swapped into each position in the deck:
For card1 = 0 To 50
card2 = card1 + Int((52 - card1) * Rnd)
If card1 <> card2 Then
Temp = Image1(card1).Picture
Image1(card1).Picture = Image1(card2).Picture
Image1(card2).Picture = Temp
End If
Next IndexDespite everything, the person most likely to be fooling you next is yourself.
Thank you for your comment, however, I did try 0 to 50 and 52 *RND first; It still has the same effect. I lose the Image1(0) card; the King of Hearts. If I use Temp as an Image for tghe shuffle it does not work. Says it is not a proper variable or is not set as one ; I try set command and that doesn't work. I try Image1(0).Picture in place of temp and I lose the King of Hearts card too of course; hence Image1(0). How do I shuffle the images with using a third variable for the shuffle correctly and not lose any cards at run time at display of images? Much appreciation in advance.
-
Thank you for your comment, however, I did try 0 to 50 and 52 *RND first; It still has the same effect. I lose the Image1(0) card; the King of Hearts. If I use Temp as an Image for tghe shuffle it does not work. Says it is not a proper variable or is not set as one ; I try set command and that doesn't work. I try Image1(0).Picture in place of temp and I lose the King of Hearts card too of course; hence Image1(0). How do I shuffle the images with using a third variable for the shuffle correctly and not lose any cards at run time at display of images? Much appreciation in advance.
maybe you'll have to use a clone ?
Jarno Burger Video Jockey
-
maybe you'll have to use a clone ?
Jarno Burger Video Jockey
-
maybe you'll have to use a clone ?
Jarno Burger Video Jockey
Well, that was it! Thank you for the suggestion. I made a clone, made it invisible and used it in the swap, like this: f (posn1 z<> posn2) Then KingH(0).Picture = Image1 posn1).Picture Image1(posn1).Picture = Image1(posn2).Picture Image1(posn2).Picture = KingH(0).Picture
-
Well, that was it! Thank you for the suggestion. I made a clone, made it invisible and used it in the swap, like this: f (posn1 z<> posn2) Then KingH(0).Picture = Image1 posn1).Picture Image1(posn1).Picture = Image1(posn2).Picture Image1(posn2).Picture = KingH(0).Picture
yeah ! cool ! whahoo ! we solved it !
Jarno Burger Video Jockey
-
yeah ! cool ! whahoo ! we solved it !
Jarno Burger Video Jockey
Yep we did; thanks! I have another question. Trying to move the image1(12) card (drag and drop) to the hearts(12) card. Testing to see if the tags are equal first, which they are set in design view, then setting the same image bitmap of image1(12) card over (dropped on) the blank image of hearts(12) card. What happens at run time is ALL the cards 0 - 12 of image1 can only be dropped in hearts(12) spot. None of the other cards in the image1 stack (up to 52, remember, I'm just doing a sample first) can be dropped over the hearts cards, but no "shirley" error message pops up either. Any suggestions? Pardon the format; just testing now 'Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) 'Image1(Index).Picture = Source.Picture 'End Sub Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) 'Dim ImageIndex As Integer Dim HeartsPic0 As Image HeartsPic0.Picture = Source.Picture Source.Picture = LoadPicture("C:\Program1\013h.gif") If Image1(12).Tag = Hearts(12).Tag Then Hearts(12).Picture = HeartsPic0.Picture &
-
Yep we did; thanks! I have another question. Trying to move the image1(12) card (drag and drop) to the hearts(12) card. Testing to see if the tags are equal first, which they are set in design view, then setting the same image bitmap of image1(12) card over (dropped on) the blank image of hearts(12) card. What happens at run time is ALL the cards 0 - 12 of image1 can only be dropped in hearts(12) spot. None of the other cards in the image1 stack (up to 52, remember, I'm just doing a sample first) can be dropped over the hearts cards, but no "shirley" error message pops up either. Any suggestions? Pardon the format; just testing now 'Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) 'Image1(Index).Picture = Source.Picture 'End Sub Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) 'Dim ImageIndex As Integer Dim HeartsPic0 As Image HeartsPic0.Picture = Source.Picture Source.Picture = LoadPicture("C:\Program1\013h.gif") If Image1(12).Tag = Hearts(12).Tag Then Hearts(12).Picture = HeartsPic0.Picture &
.tag is normally object. comparing object with object sometimes work. but to be sure , do a ctype(image(x).tag , string/integer/double/your class type ) first. Your watch window in visual studio does some neat tricks to show you what is in the tags. But the bad thing is , that your code doesn't know, only that watch-window does (thats called reflection). You have to "convert the object back to your type of class"->ctype(thingie , class-type) . Just to make sure your tag is ok. And maybe Debug.WriteLine all the tag info constantly to your debugger window. Maybe something goes wrong somewhere else , working with tags , (that could behave like any object) , can be tedious. In your case , are your tags your game-data , or are there other array's of stuff with game-data ? Try to make a mental split-up of game-data and interface. Build a 'huge' game-data class . You'll add / remove / update /load / save / (de)serialize your gamedata. In that way , maybe in the future you only have to type in the intermediatewindow or debugwatcher :'gamedata.show' , to show all the gamedata in one list in the debugwindow or debugwatcher. Later in the future you can remember multiple "states" of gamedata , to have a undo/replay function.
Jarno Burger Video Jockey