|
-
Dec 2nd, 2011, 09:14 AM
#1
Thread Starter
New Member
Monopoly Game
so i'm working on developing a Monopoly game for class in VB and i'm having difficulties with moving the game pieces. how i have it set up right now is that the pieces are moved by the location property through a loop that's as big as the dice roll. the difficulty lies in how can i detect when the player is at the corner pieces and instead of going left off the form instead goes up on the board instead of left into nothingness.
so far i have:
Code:
Private Sub btnRoll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoll.Click
Dim die1, die2 As Integer
Dim rnd As New Random()
Randomize()
die1 = rnd.Next(1, 7)
die2 = rnd.Next(1, 7)
lblDiceRoll1.Text = die1.ToString
lblDiceRoll2.Text = die2.ToString
playerPosition = die1 + die2
Randomize()
die1 = rnd.Next(1, 7)
die2 = rnd.Next(1, 7)
lblAiRoll1.Text = die1.ToString
lblAiRoll2.Text = die2.ToString
aiPosition = die1 + die2
tmrMove.Enabled = True
End Sub
Private Sub tmrMove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
If (playerPosition > 0 And aiPosition > 0) Then
movePlayer()
moveComputer()
ElseIf (playerPosition > 0) Then
movePlayer()
ElseIf (aiPosition > 0) Then
moveComputer()
Else
tmrMove.Enabled = False
End If
playerPosition -= 1
aiPosition -= 1
End Sub
Private Sub movePlayer()
lblPlayer1.Left -= 42
End Sub
to make it easier for others, 42 is the difference on the boards from left to right on the board and 37 is the distance from top to bottom between places
-
Dec 2nd, 2011, 11:45 PM
#2
Re: Monopoly Game
Which version of VB.NET are you using?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Dec 3rd, 2011, 01:20 PM
#3
Thread Starter
New Member
Re: Monopoly Game
im using visual studio 2008 with .NET Framework 3.5
-
Dec 5th, 2011, 11:29 AM
#4
Re: Monopoly Game
You need a "direction" variable assigned at the class level. You set it for whichever "direction" your piece needs to move. It can be anything, a pro would make an Enum, but a String or an Integer would do.
Then, when your movement loop happens, the first thing it does is check to see if the piece is in one of the corner squares and if it is, changes the direction variable appropriately. Otherwise, it just moves the piece one square in whatever direction the variable tells it to.
Just to throw a wrench in the whole thing, remember there are a couple of "go back 3 spaces" Chance cards. You'll need an override to your routine that reverses everything 
When board game programming, it's best to handle the game board as an abstract chain. You have a bunch of nodes. Each node knows what node is before it and after it and how to move a token there. All you then do is tell the node to move the token forward or backward along the chain.
-
Dec 6th, 2011, 09:43 PM
#5
Re: Monopoly Game
JP
One possible way is to give each "square" a number.
If memory serves me, there are
- a total of 40 squares, comprising
- 4 corners
- 9 intermediary squares on each side
so, numbering would be from 1 to 40.
Each piece will need to "retain" it's position, and would respond
to an algo along these lines (assuming GO is in lower left, and
movement is clockwise)
Code:
If pos >= 1 And pos <= 11 Then
' move up 1 square
ElseIf pos > 11 And pos <= 21 Then
' move right 1 square
ElseIf pos > 21 And pos <= 31 Then
' move down 1 square
Elseif pos > 31 Then
' move left 1 square
End If
A similar algo could be developed for going backwards.
Does that get you off of (ahem) square one?
Spoo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|