Results 1 to 10 of 10

Thread: making a game

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    making a game

    Hi, i am doin some coursework and i need to know how to use arrays properly and how to insert values into it correctly. i think i need to use the for... loop.. or something like that. i have a strict deadline so plz reply asap!

    i am making a snakes and ladders game and the user needs to insert the position and size of 10 snakes and 10 ladders. the board will be an array, and i have created the array with 100 spaces.

    i am getting the input from the user 1 by 1, so the size of the snake is stored, and then its position, i then need to somehow put these values onto the board. the code i have so far is as following:


    For d = 1 To 100 'for all values in the array
    board(d) = 0 'turn them into 0
    Next d 'complete initialisation of array


    no_of_snakes = 10 'the number of snakes = 10
    no_of_ladders = 10 'the number of ladders = 10
    snakecount = 0 'set snake counter to 0

    Do Until snakecount = no_of_snakes
    Do
    size_of_snake = InputBox("Enter size of snake between 10 and 30 for snake number " & snakecount + 1)
    If size_of_snake < 10 Or size_of_snake > 30 Then
    MsgBox ("The size of the snake has to be between 10 and 30, please retry")
    End If

    Loop Until size_of_snake > 9 And size_of_snake < 31
    Do
    position_of_snake = InputBox("Enter start position of snake for snake number " & snakecount + 1)
    If position_of_snake < 11 Or position_of_snake > 99 Then
    MsgBox ("Invalid position, try again")
    End If
    Loop Until position_of_snake > 10 And position_of_snake < 100

    board(position_of_snake) = size_of_snake * -1
    snakecount = snakecount + 1
    Loop

    the orange bit is where i need help
    thank u
    Last edited by mrsingh; Apr 28th, 2005 at 12:36 PM.

  2. #2
    Member
    Join Date
    Feb 2005
    Posts
    56

    Re: making a game

    Hi,

    Two things:

    1.) Can't get people to help too much with your coursework, for obvious reasons! (I don't mean to sound harsh, I'm a college student myself!)

    2.) Try uploading the code so far, as a .zip?

    Snowblind

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    Re: making a game

    here is the code as a zip
    Attached Files Attached Files

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: making a game

    Put code between <VBCODE> and </VBCODE> (< = [ and > = ]) to preserve indentation and keep it readable.
    VB Code:
    1. For d = 1 To 100 'for all values in the array
    2.    board(d) = 0  'turn them into 0
    3. Next d           'complete initialisation of array
    4.    
    5.    
    6. no_of_snakes  = 10 'the number of snakes  = 10
    7. no_of_ladders = 10 'the number of ladders = 10
    8. snakecount    = 0  'set snake counter     to 0
    9.  
    10. Do Until snakecount = no_of_snakes
    11.   Do
    12.     size_of_snake = InputBox("Enter size of snake between 10 and 30 for snake number " & snakecount + 1)
    13.     If size_of_snake < 10 Or size_of_snake > 30 Then
    14.       MsgBox ("The size of the snake has to be between 10 and 30, please retry")
    15.     End If
    16.   Loop Until size_of_snake > 9 And size_of_snake < 31
    17.  
    18.   Do
    19.     position_of_snake = InputBox("Enter start position of snake for snake number " & snakecount + 1)
    20.     If position_of_snake < 11 Or position_of_snake > 99 Then
    21.       MsgBox ("Invalid position, try again")
    22.     End If
    23.   Loop Until position_of_snake > 10 And position_of_snake < 100
    24.  
    25.   [COLOR=Orange]board(position_of_snake) = size_of_snake * -1[/COLOR]
    26.   snakecount = snakecount + 1
    27. Loop
    How is this board supposed to work?
    I see a one-dimensional array, shouldn't that be two-dimensional?
    Why didn't you declare the Board?
    VB Code:
    1. Private Board(100) As Long        'is it a long?
    2. Private 2D_Board(100,100) As Long 'this one is twodimensional

    What you are doing in your orange statement is store the size of the current snake (minus 1) in the element of Board where the index is the snake's position.
    What do you expect/want to happen?

    If I have a snake with a length of 10 and a position of 20, should the elements Board(10) to Board(30) be filled with the snake's number?
    In that case you sould make a For Next loop.
    VB Code:
    1. For d = position_of_snake To position_of_snake + size_of_snake
    2.   If d > 100 Then Exit For
    3.   Board(d) = snakecount
    4. Next d
    But what if the next snake starts at 20 with a length of 5?
    It would overwrite some of the elements filled by the previous snake and cut it in half.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    Re: making a game

    what i am tryin to achieve is to get the snakes onto the board in the right places. i dont mind if they overwrite existing snakes for the time being, i should be able to hopefully adjust that later on. i have declared all my variables and done the 1 dimensional array... dim board(100) as integer... but i did not include everything in my post as fear of people stealing it because it is my coursework!

    i want only the snakes head which is going to be the snakes position to make the player go down the size of the snake... if that makes sense?! in otherwords, if they choose a position of 20, and a size of 10, then array(20) should hold the value (-10). however the player is going to put in a positive integer, so this needs to be turned into a negative integer.

    additionally i was wondering if u could tell me how to somehow output a file so i can check to make sure that the info is actualy being correctly written in the array?
    thanx
    Last edited by mrsingh; Apr 28th, 2005 at 02:51 PM.

  6. #6
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: making a game

    LOL, stealing your coursework.

    But what do you need help with?
    Your code does what you describe.

    But how do you want to find the snakes back later in the game?
    And why the 1D array? Are the snakes crawling along a rope?

    IMO it would be better to assign a few variables for each snake so you can use their data later on.

    Are you just coding along or have you made a design?

    msdn.microsoft.com
    Look for Open, Freefile, Close, WriteLine, Input, get, Put, EOF.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    Re: making a game

    the 1d array is because the task says use a 1d array lol... and erm im just coding. its too long to create different variables for each snake!

    if ne1 can help me on the last few questions gr8! if not i ave some more questions... does ne1 know how to count the number of times i click the command button, and write it in a label.. because i need to somehow count the number of throws taken by a player. at the moment it is being designed for 1 player...

  8. #8
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: making a game

    For counting clicks on a button, declare a variable (Long) and increase it by 1 when the button is clicked.
    VB Code:
    1. Dim Counter As Long
    2. Private Sub Btn_Click()
    3.   Counter = Counter + 1
    4. End Sub
    its too long to create different variables for each snake!
    What do you mean by that?
    How do you intend to keep track of the snake's status later on if you don't store any of the snake's data?
    How will you make the snakes do things if you don't know anything about them?
    With your current code it will be near impossible to find out where each snake is.
    Retrieving the data you threw away will be much longer than declaring a few variables to keep the data.

    What exactly is your task?
    What is the idea behind the game?
    What are the snakes supposed to do?
    Why does the task say you need to use a 1D array? Wil you get punished if you deviate a bit?

    I would advise to plan/design things before you start writing code.
    It will help you code with clear goals and structure and will save you time otherwise spent on changing code.
    Last edited by jeroen79; Apr 28th, 2005 at 04:23 PM.

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    Re: making a game

    i am going to write the values to the array as i get them. the game is like any other normal snakes and ladders game, only thing is that the user gets to choose where to put the snakes and the ladders. if i use a 2d array i will not get ne marks.
    i think thats enuff for 2day, thanx for ur help, ill back to u and ne1 else whos willing to help 2moz with some more questions!

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    8

    Re: making a game

    in making the game, i have now drawn out the board using labels and done a dice counter to count the number of throws.. i now need to be able to get the values being input for the snakes sizes and positions onto the board from the array. ne ideas? i then need to be able to make some kind of counter, or perhaps change the colour of the labels to indicate where a player is, i also need to be able to move the player the amount the dice rolls. wow i have a lot of work to do! can ne1 help me?!?!

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