CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 44
  1. #1
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Question Need help with a whole bunch of things

    I'm just an around basic/medium leveled programmer and decided to make a partially complex game for a class project. Now, my teacher has basically the same skill level I do so he asked his brother, the expert programmer, for help, and I got back a whole bunch of things that make hardly any sense to me.

    To give a little background about what I am actually trying to do, and where I asked him for help with.

    It is a labryinth type game, where you move around trying to reach the exit. He told me to use the graph theory, which I do slightly know a bit about from math, but have no clue about for vb. The maze itself is a 5000x5000 pixel map, with the characters I use to represent the player being 50x50 pixels, so each square is 50x50, resulting in a 100x100 square map.

    1. I have an 9 slot inventory with 5 possible items a person can get. He told me that dynamic programming it would be too hard, if finding the items were to be random, as I had originally planned, so to use static. He said I may have used double-linked-lists, which I have no clue about, and then he said to use a stack for my item list.
    "Also it would be best to use a stack for your item list. You will then have a function that uses the system clock and random number generator to create a number. Pop an item off of the stack and use the random number generator to define which square the item will be assigned to. Loop through this till the stack is empty"
    And then he said to use a list to store the items, set to size 9, so when it is full, it will say I am full on items.

    2. I wanted to have random events happen in the maze, like pit traps and fire traps, he said that it would be best to keep the pits static, and to do the fire traps dynamically, based off the system clock and random number generator. What would be the coding for it to happen every step or so?

    3. An event list. It would display the 4 most recent events happening, with any event after that, simply dropping off the list. He told me I can do it very easily using a heap, which I have no clue how to properly implement. He said to use a counter that increases every time an event is added to the heap, and when it reaches 4, decrease the counter then pop off the top item, and add the next event, and increase again.

    4. Movement using arrow keys. He told me that I would have to use scroll bars to properly do what I wanted, but to instead, just use a graph, and when an arrow key is pressed, check if there is a wall, which I have no clue how to do, and if there isn't one, move the person in the matrix, and refresh the screen.

    If you could help me, it would be greatly appreciated. I want to have at least something done out of everything he told me to do before I go back to ask him about everything thing else since I had no clue what was being said. And then he also said that to make it truely impressive, store the items in a seperate file. He said "text would be easy, but xml is the way of the future", to make it so I don't have to compile everytime.

    So yeah, if you can help, that you so much, if you can't, I'll try my best to do as much as I can, which won't be very much, before I am forced to ask him for simpler instructions, or a nice 15 page sheet telling me how do everything....

  2. #2
    Join Date
    Jun 2002
    Location
    Clane, Ireland
    Posts
    766

    Re: Need help with a whole bunch of things

    Number 3 the event list.

    If you have an array which has four elements, to start off with the array is empty, your first event goes into element 1, and the other elements are empty. Then you have another event, so move element 1 to element 2 and put the new event into element 1.
    eg:
    Code:
    dim intCnt as integer
    for intCnt = 2 to 4
      array(intcnt) = array(intcnt-1)
    next
    array(1) = ??? 'Your new event
    Number 1 the double linked list:
    I'm guessing here he is talking about having two arrays, one with nine elements containing the list of things you can have, and the other array having 5 elements which indicates what items on the list you have, so your array would point to the relevant element on the big list (array with nine items). I remember doing linked lists in college, but that was a long time ago!!

    How are you going to store your labyrinth? Are you going to keep it in an array?, because if you were, you could set up an array eg 100 by 100, and each element of the array would be a single character which could be used to contain what was in the relevant position eg W for Wall, P for player or blank for nothing etc.

    This is one way of doing what you want, but I'm sure there are better ways and hopefully someone here will be able to give you a point in the right direction.

    HTH
    JP

    Please remember to rate all postings.

  3. #3
    Join Date
    Sep 2004
    Posts
    135

    Write algorithm first

    If the problem is because of any lack of knowledge in VB, then I suggest that you write the algorithm first. That can be done without having the knowledge of VB. Once you have written the algorithm, start writing code based on that. Now, you will require knowledge of VB. At this stage you can ask whatever specific doubts you have.

  4. #4
    Join Date
    Oct 2003
    Location
    Timisoara, Romania
    Posts
    460

    Re: Need help with a whole bunch of things

    What you want is very complex, not very hard but complex. I can tell you where to start each time you want to build anything with mazes: backtracking. Backtracking is method that programmers use when it comes to a problem with more solutions. If you do a search on the net you will find a lot of links to tutorials of this technique. It's not an easy technigue but once mastered will make your programming days much easyer
    Want a smarter mouse to get out of the maze quicker? Use Recursive Backtracking Now here lies the true power of programming
    You liked it? Please show your gratitude and rate it!

    There is no 'patch' for stupidity.

  5. #5
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    Quote Originally Posted by jp140768
    Number 3 the event list.

    If you have an array which has four elements, to start off with the array is empty, your first event goes into element 1, and the other elements are empty. Then you have another event, so move element 1 to element 2 and put the new event into element 1.
    eg:
    Code:
    dim intCnt as integer
    for intCnt = 2 to 4
      array(intcnt) = array(intcnt-1)
    next
    array(1) = ??? 'Your new event
    Number 1 the double linked list:
    I'm guessing here he is talking about having two arrays, one with nine elements containing the list of things you can have, and the other array having 5 elements which indicates what items on the list you have, so your array would point to the relevant element on the big list (array with nine items). I remember doing linked lists in college, but that was a long time ago!!

    How are you going to store your labyrinth? Are you going to keep it in an array?, because if you were, you could set up an array eg 100 by 100, and each element of the array would be a single character which could be used to contain what was in the relevant position eg W for Wall, P for player or blank for nothing etc.

    This is one way of doing what you want, but I'm sure there are better ways and hopefully someone here will be able to give you a point in the right direction.

    HTH
    Like I said, I hardly have any knowledge of vb, so arrays are a bit beyond me, and the person who handled the installation of vb at our school was mentally handicapped because he forgot to install mdsn, and also greatly messed up the installation of it in general.

    Once I finish the maze, I'll zip the folder with all the stuff and upload it so you can see what I am actually doing. It may make it easier to give me some easier to follow advice

  6. #6
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    And here we go... I have it zipped with all the work I have done so far... I view it as pretty good as it contains most of the knowledge I currently know in use.

    If you want to chance the code to reduce the mess or make it easier to work around, feel free to do so. It is in the very early stages so the coding is very messy anyways.

    NOTE: The maze itself and the sound files aren't in there due to size limitations but oh well
    Attached Files Attached Files

  7. #7
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Need help with a whole bunch of things

    I'm quite curious about this one so I might help out a little at a time.

    the first tip i can give you is to indent your code - it will make it SOOOO much easier for you (and any codegurus) to read because you can see the program flow without havingto analyse the code.

    so, as an example of your code, in sub form load you have this:
    Code:
    Private Sub Form_Load()
    HP = 100
    If TotalSeconds = 0 Then
        cmdhit.Enabled = False
        cmdpit.Enabled = False
        cmdpause.Enabled = False
        End If
        TotalSeconds = 0
    End Sub
    it would be much easier to read as this:
    Code:
    Private Sub Form_Load()
        HP = 100
        If TotalSeconds = 0 Then
            cmdhit.Enabled = False
            cmdpit.Enabled = False
            cmdpause.Enabled = False
        End If
        TotalSeconds = 0
    End Sub
    next, if you want to be able to do this you DEFINITELY need to learn arrays. they are pretty simple. example, you have Dim Event1 ... all the way to Event15. you would need to specifically address each instance whenever you want to go through them all. instead make them an array (it really is simple, don't worry!), example:
    Code:
    Dim Event(1 to 15) As String
    
    ' demo
    Private Sub ListEvents()
        Dim i As Integer
    
    'list all events
        For i = 1 to 15
            msgBox Event(i), vbOkOnly
        Next
    
    'or, to just display, say event 14
        msgBox Event(14), vbOkOnly
    End Sub
    Your instructor has suggested the use of stacks alot. A stack is whats called LIFO - last in first out, similar to a queue which is FIFO - first in first out. So, the last thing to go into the stack is the first one to come out. Vb has inbuilt stack funcionality, but if you don't have MSDN it could be a bit difficult to figure out. BUT, if yo ucan figure out arrays, then jp140768's post details how simple way to make your own stack.

    finally, in many other languages (C++, .Net, etc) you can declare variables like you have at the top:
    Code:
    Dim TotalTenthSeconds, TotalSeconds, TenthSeconds, Seconds, _
    Minutes, Hours As Integer
    in VB6 though, be aware that only Hours will be created as Integer. The rest will be variant - which may well appear to work as an integer for you, but could cause problems and is not an efficient way to program as every time you wish to do something (i.e. TotalTenthSeconds = TotalTenthSeconds + 1) then VB will do all sorts of checks and conversions to see if it can actually do it. as an integer though, it knows it can add 1 to it and just does it. see, a variant can be anything. it would be possible to do this without generating a compile error:
    Code:
    dim x as variant
    
    x = 1
    x = "zeb"
    'oops - this will crash your program
    x = x + 1
    thats enough for now from me! good luck. it's a pretty ambitious first attempt, but it's definately do-able (it's how i started!)
    Last edited by Zeb; October 27th, 2004 at 11:42 PM. Reason: it's for...next not for...loop. i'm such an idi*t!!

  8. #8
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    The timer code wasn't actually my own... I took it from a tutorial site my teacher told the class to go through. Random sites is where the harder coding, ie the making it so .wavs could be played, although I could have done that myself, just copying from a vb book I have, but meh.

    I'll indent the code to make it easier to understand, and implement arrays to shorten the coding, although I probably won't actually need any arrays since all those event strings will be gone if a heap is used, just a guess though since I don't quite know how they work. I may use one for the items though... depending on how I set those up.

    And also, I can understand my messy coding just fine, just like my writing. It is partly something I do to prevent people from copying what I do, or to just generally make their life harder, whether they be a friend or a faculty member.

    I'll do some work on it before I go to bed, and pray for more helpful people to help me out for when I check this again, which will be during programming class... and hopefully my teacher's brother will have also e-mailed me back.

  9. #9
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    Made it so the game allows you to pick another character to be when you die and start over again. Yay.

    And when I made it into an exe so I could show a friend how much I had done, the sounds in it failed to load the first attempt, as in I had to press a button twice to actually get the sounds to play, instead of them working right off the bat. It isn't really annoying, but it is something I'll try to smooth out near the end, even though those testing buttons will be gone in the final version, I don't want them falling into their first pit and not hearing anything until their 2nd pit onward

  10. #10
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    Yay... now I have movement implemented... although it is buggy because I have yet to find the magic numbers that will enable perfect movement throughout my maze since it seems VB uses a different measurement system than Fireworks, since what is 5000x5000 pixels in fireworks, it is 75000x75000 in VB, and while movement, the background I put behind the maze so that the edge, if reached, isn't a bland grey, twitches if the character moves too fast, along with the character having some black twitches.

    The person helping me said he wouldn't be able to help me properly put in a system for the maze until the weekend though so I'm stuck for now.... Anyone know how to make it so I can use the actual arrow keys for movement instead of commands buttons?

  11. #11
    Join Date
    Jun 2002
    Location
    West Virginia
    Posts
    131

    Re: Need help with a whole bunch of things

    The 75000 is not pixels. It is Twips. Click on your picturebox and look in properties for ScaleMode and click on the down arrow and choose 3-Pixels. This will give you your 5000 pixels.
    Wayne

  12. #12
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    Well that will solve one problem. Thanks.

  13. #13
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Need help with a whole bunch of things

    for your keypresses, check this link:
    http://www.codeguru.com/forum/showth...lobal+keyboard

  14. #14
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    75

    Re: Need help with a whole bunch of things

    And that makes 2 problems solved. Thanks again.

    Now... I just need to take out that annoying flickering, and then set up the coding for the pits and fire traps... If I turned their mathematics into functions, so they call be called upon when needed. Would that be better, or does it really matter all that much?

  15. #15
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Need help with a whole bunch of things

    whats the flickering?

    as to the functions, looking at the original project i don't think they need to be in functions, although maybe put the hp adjustments in a sub so that it updates the value and sets the label in one place instead of 2 (3, 4,5...).

    sounds like you have done a bit since you posted the original project though so maybeit owuld be worthwhile posting again. also, you are pointing to some things outside of the project folder so we can't access them!

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured