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.
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.
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
This is basibly where my doors are drawn on the board Code: Dim door1 As New door(135, 380, 10, 40) door1.Draw(g) doors.Add(door1) Dim door2 As New door(275, 380, 10, 40) door2.Draw(g) doors.Add(door2) Dim door3 As New door(415, 380, 10, 40) door3.Draw(g) doors.Add(door3) 'Spawn Trapdoor Dim Tdoor4 As New door(500, 275, 40, 10) Tdoor4.Trapdoor(g) doors.Add(Tdoor4) Dim door5 As New door(135, 240, 10, 40) door5.Draw(g) doors.Add(door5) Dim door6 As New door(275, 240, 10, 40) door6.Draw(g) doors.Add(door6) Dim door7 As New door(415, 240, 10, 40) door7.Draw(g) doors.Add(door7) 'Spawn Trapdoor Dim Tdoor8 As New door(20, 135, 40, 10) Tdoor8.Trapdoor(g) doors.Add(Tdoor8) Dim door9 As New door(135, 100, 10, 40) door9.Draw(g) doors.Add(door9) Dim door10 As New door(275, 100, 10, 40) door10.Draw(g) doors.Add(door10) Dim door11 As New door(415, 100, 10, 40) door11.Draw(g) doors.Add(door11) 'Spawn Gold Door Dim Gdoor12 As New door(555, 100, 10, 40) Gdoor12.Goldendoor(g) doors.Add(Gdoor12) 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
If it were me I'd move the dice throw into the move function and have the move function handle all aspects of the player's turn, not just a single throw and move from one square to another but the whole thing including multiple rolls, questions, answers, promotion and demotion. As the code is currently written it would be hard to incorporate the logic I suggested, unless you duplicate the dice roll part in the move function, but then you may as well just move it in.