Jump to content



Photo

Visual basic -


  • Please log in to reply
5 replies to this topic

#1 atyemail

atyemail

    Neowinian

  • Tech Issues Solved: 2
  • Joined: 09-August 13

Posted 22 August 2013 - 06:25

So i need to make this board game called candy land and so far i am missing a thing where i need to make that everytime the user which is Player 1 or player 2 roll there must be a label showing the roll that they get for example it's random number between 1-12 and if they get 7 then the label should show 7 but i can't seem to figure that out and also that there are several special box such as to move 1 step forward, 1 step back, 2 steps forward, and 2 steps back and i need to make it whnever the user land on those special box it will do as instructed but other than that i have manage to get the player 1 and player 2 working:

    Dim lblArray(35) As Label           'array of labels that make up the game board
    Dim intRules(35) As Integer         'parallel array containing rules for the squares corresponding to lblArray entries

    Dim blnP1Turn As Boolean = True     'switches indicating whose turn it is
    Dim blnP2Turn As Boolean = False
    Dim intP1Position As Integer        'position of player 1 on board
    Dim intP2Position As Integer        'position of player 2 on board
    Dim blnDoubleOccupancy As Boolean = False   'True if both players on same square
    Dim LblP1num, lblP2num As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'This is the size of each square (Label) in the game
        Const intSQUARE_SIZE As Integer = 40
        ' this is the array of labels that make up the game board


        'This for..Next Loop sets properties of each label in the array. The Select..Case statement
        'places the labels around the edges of the form 
        For intCount = 0 To 35
            lblArray(intCount) = New Label
            lblArray(intCount).Size = New System.Drawing.Size(intSQUARE_SIZE, intSQUARE_SIZE)
            lblArray(intCount).BorderStyle = BorderStyle.FixedSingle
            lblArray(intCount).Name = "lbl" & intCount
            lblArray(intCount).Visible = True

            'The following line display the array index on each square
            'You probably will want to comment it out
            lblArray(intCount).Text = intCount.ToString

            Select Case intCount
                Case Is < 10
                    lblArray(intCount).Location = New System.Drawing.Point(intSQUARE_SIZE * intCount, 0)
                Case 10 To 18
                    lblArray(intCount).Location =
                        New System.Drawing.Point(intSQUARE_SIZE * 9, intSQUARE_SIZE * (intCount - 9))
                Case 19 To 27
                    lblArray(intCount).Location =
                        New System.Drawing.Point(intSQUARE_SIZE * 9 - intSQUARE_SIZE * (intCount - 18), intSQUARE_SIZE * 9)
                Case 28 To 35
                    lblArray(intCount).Location =
                        New System.Drawing.Point(0, intSQUARE_SIZE * 9 - intSQUARE_SIZE * (intCount - 27))
            End Select
            ' Set colors of the labels
            Select Case intCount Mod 5
                Case 0
                    lblArray(intCount).BackColor = Color.MediumOrchid
                Case 1
                    lblArray(intCount).BackColor = Color.OrangeRed
                    lblArray(intCount).ForeColor = Color.White

                Case 2
                    lblArray(intCount).BackColor = Color.Salmon
                Case 3
                    lblArray(intCount).BackColor = Color.Turquoise
                Case 4
                    lblArray(intCount).BackColor = Color.Yellow
                    lblArray(intCount).ForeColor = Color.Plum
            End Select
            Controls.Add(lblArray(intCount))
        Next

        'Initialize special squares
        SetRules()

        

    End Sub
    Private Sub SetRules()
        'Initialize special squares
        lblArray(0).Text = "Start"
        lblArray(lblArray.Length - 1).Text = "Finish Line"

        lblArray(7).Text = "2 steps back"
        intRules(7) = -2

        lblArray(13).Text = "1 step forward"
        intRules(13) = 1

        lblArray(19).Text = "2 steps forward"
        intRules(19) = 2

        lblArray(32).Text = "1 step back"
        intRules(32) = -1
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Randomize()
        Dim intDice As Integer = CInt(Fix(Rnd() * 7) + 1)

        If blnP1Turn = True Then
            lblArray(LblP1num).Text = CStr(LblP1num)
            intP1Position += intDice
            LblP1num = intP1Position
            If intP1Position >= 35 Then
                lblArray(35).Text = "P1"
                MessageBox.Show("Player One Wins!")
            Else
                If intP1Position = intP2Position Then
                    lblArray(intP1Position).Text = "P1 P2"
                Else
                    lblArray(intP1Position).Text = "P1"
                End If
            End If
            blnP1Turn  = False
            blnP2Turn = True
        Else
            MessageBox.Show("It's Not Your Turn.")
        End If
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Randomize()
        Dim intDice As Integer = CInt(Fix(Rnd() * 7) + 1)
        If blnP2Turn = True Then
            lblArray(lblP2num).Text = CStr(lblP2num)
            intP2Position += intDice
            lblP2num = intP2Position
            If intP2Position >= 35 Then
                lblArray(35).Text = "P2"
                MessageBox.Show("Player Two Wins!")
            Else
                If intP1Position = intP2Position Then
                    lblArray(intP2Position).Text = "P1 P2"
                Else
                    lblArray(intP2Position).Text = "P2"
                End If
            End If
            blnP1Turn = True
            blnP2Turn = False
        Else
            MessageBox.Show("It's Not Your Turn.")
        End If
    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

Attached Images

  • w.png

Attached Files




#2 FloatingFatMan

FloatingFatMan

    Resident Fat Dude

  • Tech Issues Solved: 1
  • Joined: 23-August 04
  • Location: UK

Posted 22 August 2013 - 07:46

Are you going to ask people to do ALL your homework assignments, or what?  At this point you don't even seem to be trying to do it yourself...

 

What have you tried to get it to work? Do you understand why it didn't work?



#3 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 11
  • Joined: 26-October 05

Posted 22 August 2013 - 20:02

 the label should show 7

You need to assign the string you want to display to the Text property of the label.

 

 

also that there are several special box such as to move 1 step forward, 1 step back, 2 steps forward, and 2 steps back and i need to make it whnever the user land on those special box it will do as instructed

You need to look on which square the player has landed and adjust his final position based on the set of rules you described. Apparently you have an array containing the position adjustement for each label, so you just need to index it at the label's number to get the correct adjustement.

 

Frankly I don't think asking that many "how do I do this assignment" on this forum is the most efficient way for you to learn, but I've already given you my advice in a previous thread. It's your call.



#4 soccerstar206

soccerstar206

    Neowinian

  • Joined: 19-August 13

Posted 22 August 2013 - 23:17

insert 2 labels and write code for player 1 click and player 2 click

 

label1.Text = CStr(intDice)



#5 fusi0n

fusi0n

    Don't call it a come back

  • Tech Issues Solved: 3
  • Joined: 08-July 04
  • OS: OSX 10.9\Elementary OS
  • Phone: LG G3

Posted 22 August 2013 - 23:31

Are you going to ask people to do ALL your homework assignments, or what?  At this point you don't even seem to be trying to do it yourself...

 

What have you tried to get it to work? Do you understand why it didn't work?

I look up stuff all the time for my real job



#6 FloatingFatMan

FloatingFatMan

    Resident Fat Dude

  • Tech Issues Solved: 1
  • Joined: 23-August 04
  • Location: UK

Posted 23 August 2013 - 06:17

I look up stuff all the time for my real job

 

There's a big difference between looking up stuff and asking people to do your homework.  At this rate, Atyemail is never going to learn because he's not even trying.  Come on, he can't even figure out the .Text property of a label?  He clearly didn't even try.

 

Atyemail; sorry, I'm not being rude, but that's the impression you're giving.  Helping people is fine, as +Asik has been helping you, but you need to at least try.  You can start by describing some of the things you've tried to solve the problems you're hitting.