Discussion in 'Game programming' started by stuka, Apr 19, 2009.

1. ### stukaNew Member

Joined:
Apr 19, 2009
Messages:
6
0
Trophy Points:
0
Hello Guys wondering if you could help me,
Ok atm im doing a computer course at college and one of the units its games programming and im USELESS at it lol, well so far i have created a game where it draws a game board, doors and a player with GDI, you click a button and it will role a dice (1-6) and the player will move along to board depending on the dice roll. once it reaches a trap door it will go up to level 2 and so on.
The thing is i dont know how i'd go about coding it so when the player reaches a door it will ask a question, if the player gets it right they can roll again if they get it wrong they have to go back to the spot they was before they rolled the number that got them to the door. i have the doors in a collection if thats any help and there in the order which the player gets to them. so like when player reaches door1, ask question but coding that not a clue.
ps. like i said im usless at coding lol so try simplyfy it Any help would be appreciated.

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
You'll need to store various bits of information such as where the player was before the move (which you may be able to calculate from the dice roll and current position instead, if storing it is a problem), also implement backward moving (i.e. to restore the board, player position etc to the starting point). When the player reaches the destination square you need to write a block of code that asks the question, gets the answer, determines if that is right or wrong then works out what will happen next. Probably you'll want to implement a "move loop" that continues while they can make moves and terminates when they can no longer make a move, something like:
Code:
```player_can_move <= 1
while (player_can_move) loop
throw dice
move player
ask question - is it right?
if no then move player back* and player_can_move <= 0
end loop
```
* back to where: back to the starting point for the whole turn or back to the start of the last dice roll?
Presumably the latter otherwise nobody gets anywhere until someone wins.

What can help is if you outline the logic using a semi-formal flowchart; write some text (on paper) that indicates what happens, then some more text that indicates what happens after that, and draw an arrow from one to the other, e.g.
throw dice ---> move player

Keep this fairly free form; you're just playing with ideas here, then just draw arrows and more text while you sort the process out in your head, dry running it as you go. Once you've got a working algorithm, tidy it up if necessary, then you should be able to work out from the arrows where the loops should go, what storage is needed and so on.

3. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
so for example you might end up with something like this.

#### Attached Files:

• ###### 19042009.jpg
File size:
157.6 KB
Views:
3
shabbir likes this.
4. ### stukaNew Member

Joined:
Apr 19, 2009
Messages:
6
0
Trophy Points:
0
Thx for the reply your help is greatly appreciated, the problem is i dont want it to ask the question every time the player moves. for the player to reach a door it would require 7 spaces (max ya can roll is 6) i did this so it cant got through 2 doors at once and requires atleast 2 rolls to pass the first door.

This is the code that moves my player when dice is rolled
Code:
``` Private Sub BtnRoll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRoll.Click
Dim g As Graphics
g = Pic1.CreateGraphics
Dim diescore As Byte

aboard.Draw(g)
Randomize()
diescore = Int(Rnd() * 6) + 1

Txtrolled.Text = diescore
aplayer.move(g, diescore * 20, aboard)
aplayer.Draw(g)```
This is the code that moves my player up a level when it reaches the end of a level
Code:
```Sub move(ByVal g As Graphics, ByVal distance As Short, ByVal aboard As Board)

aboard.Draw(g)

If level = 2 Then
x = x - distance
Else
x = x + distance
End If
Me.Draw(g)

Form1.txtlevel.Text = level

If level = 3 And x >= 550 Then
x = 550
MsgBox("You have Reached The Golden Door", , "Winnner")
MsgBox("The Treasure is yours!", MsgBoxStyle.ApplicationModal, "Winner!")
MsgBox("Click ok END Game", MsgBoxStyle.YesNo, "!")
End
End If

If x >= 550 Then
x = 525
y = y - 140
x = 525
level = 2
Form1.txtlevel.Text = level
MsgBox("Congratz You've reached level 2", MsgBoxStyle.Exclamation, "Next Level!")
aboard.Draw(g)
Me.Draw(g)

ElseIf x < 60 And level = 2 Then
x = 35
y = y - 140
x = 35
level = 3
Form1.txtlevel.Text = level
MsgBox("Congratz You've Reached level 3!", MsgBoxStyle.Exclamation, "Next Level!")
aboard.Draw(g)
Me.Draw(g)
End If
End Sub
End Class```
im sure the coded i need to write has to go somwhere in either of these 2 sections lol

5. ### stukaNew Member

Joined:
Apr 19, 2009
Messages:
6
0
Trophy Points:
0
This is basibly where my doors are drawn on the board
Code:
```  Dim door1 As New door(135, 380, 10, 40)
door1.Draw(g)
Dim door2 As New door(275, 380, 10, 40)
door2.Draw(g)
Dim door3 As New door(415, 380, 10, 40)
door3.Draw(g)

'Spawn Trapdoor
Dim Tdoor4 As New door(500, 275, 40, 10)
Tdoor4.Trapdoor(g)

Dim door5 As New door(135, 240, 10, 40)
door5.Draw(g)
Dim door6 As New door(275, 240, 10, 40)
door6.Draw(g)
Dim door7 As New door(415, 240, 10, 40)
door7.Draw(g)

'Spawn Trapdoor
Dim Tdoor8 As New door(20, 135, 40, 10)
Tdoor8.Trapdoor(g)

Dim door9 As New door(135, 100, 10, 40)
door9.Draw(g)
Dim door10 As New door(275, 100, 10, 40)
door10.Draw(g)
Dim door11 As New door(415, 100, 10, 40)
door11.Draw(g)

'Spawn Gold Door
Dim Gdoor12 As New door(555, 100, 10, 40)
Gdoor12.Goldendoor(g)
so like somhow i need like to check each each time the nice is rolled to see if it has passed the first door, if it has as question then but the problem i have is if i set it to ask question when its passed the first it will keep asking me every time i roll the nice after that door

Joined:
Aug 6, 2004
Messages:
3,012