Solved

For bhess1

Posted on 2000-04-06
6
182 Views
Last Modified: 2010-08-05
Ya know, I still can't get the code to work right-I am doing something really wrong!!!  WHERE should I place the code to check that you are not jumping over an empty space???  HELLLPPP!!!!  I know it is probably something really simple but for some reason I am not getting it to work!  Thanks again!  TAmara
0
Comment
Question by:floridagrrrlll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 2691416
Okay, let's see your current code.
0
 

Author Comment

by:floridagrrrlll
ID: 2691794
'I deleted the code I put in re: jumping over holes-I got so frustrated with it!!!  So far this works out well, it just needs to stop the user from jumping over an empty hole!

Option Explicit




Private Sub Form_Load()
'Declare x as variable
    Dim intx
'Declare inthole as integer
    Dim inthole As Integer
'Declare pieces of game
    For intx = 0 To 99
        imgGame(intx).Picture = imgPeg.Picture
        imgGame(intx).DragIcon = imgIcon.Picture
    Next intx
 'Random hole
    Randomize
    inthole = CInt(Rnd * 99)
    imgGame(inthole).Picture = imgHole.Picture
    imgGame(inthole).Tag = "H"
    imgGame(inthole).DragMode = vbManual
End Sub

Private Sub imgGame_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
'Declare intmid as integer
    Dim intmid As Integer
'Declare jumpDist as integer
    Dim jumpDist As Integer
 'Legal jump?
    jumpDist = Index - Source.Index
    If Abs(jumpDist) <> 2 And Abs(jumpDist) <> 20 Then
  'Illegal destination
      Exit Sub
      End If
'Jump distance=jump distance divided by 2 + control being dragged
    intmid = jumpDist / 2 + Source.Index
  If imgGame(Index).Tag = "H" Then
'Change source
    Source.Picture = imgHole.Picture
    Source.Tag = "H"
    Source.DragMode = vbManual
'Change middle
    imgGame(intmid).Picture = imgHole.Picture
    imgGame(intmid).Tag = "H"
    imgGame(intmid).DragMode = vbManual
'Change destination
    imgGame(Index).Picture = imgPeg.Picture
    imgGame(Index).Tag = "P"
    imgGame(Index).DragMode = vbAutomatic
 End If
   
End Sub
0
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 50 total points
ID: 2693844
Here's the code as it should have been - changes are marked with ' *****

In the load, you weren't setting the tag to 'P' for all holes.

In the jump code, I've placed the test for jump over code in place as it should be.

This should do it.

Private Sub Form_Load()
'Declare x as variable
    Dim intx
'Declare inthole as integer
    Dim inthole As Integer
'Declare pieces of game
    For intx = 0 To 99
        imgGame(intx).Picture = imgPeg.Picture
        imgGame(intx).DragIcon = imgIcon.Picture
        imgGame(intx).Tag = "P"   ' ***** Needed
    Next intx
 'Random hole
    Randomize
    inthole = CInt(Rnd * 99)
    imgGame(inthole).Picture = imgHole.Picture
    imgGame(inthole).Tag = "H"
    imgGame(inthole).DragMode = vbManual
End Sub


Private Sub imgGame_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
'Declare intmid as integer
    Dim intmid As Integer
'Declare jumpDist as integer
    Dim jumpDist As Integer
 'Legal jump?
    jumpDist = Index - Source.Index
    If Abs(jumpDist) <> 2 And Abs(jumpDist) <> 20 Then
  'Illegal destination
      Exit Sub
      End If
'Jump distance=jump distance divided by 2 + control being dragged
    intmid = jumpDist / 2 + Source.Index
  If imgGame(Index).Tag = "H" Then
    If imgMame(intMid).Tag = "P" Then   ' ***** Is intermediate hole pegged
'Change source
      Source.Picture = imgHole.Picture
      Source.Tag = "H"
      Source.DragMode = vbManual
'Change middle
      imgGame(intmid).Picture = imgHole.Picture
      imgGame(intmid).Tag = "H"
      imgGame(intmid).DragMode = vbManual
'Change destination
      imgGame(Index).Picture = imgPeg.Picture
      imgGame(Index).Tag = "P"
      imgGame(Index).DragMode = vbAutomatic
   Else   ' *****
       ' ***** Trying to jump over a hole!
   End If '*****
 End If
     
End Sub

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:floridagrrrlll
ID: 2696474
Thanks!  You're the best!  It is working perfectly now!  Tamara
0
 

Author Comment

by:floridagrrrlll
ID: 2696476
PS-Did you get all the points for this question???
floridagrrrlll@hotmail.com
0
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 2704217
Yes, I did - thanks!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question