![]() |
Doors asking questions
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. |
Re: Doors asking questions
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 <= 1Presumably 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. |
Re: Doors asking questions
1 Attachment(s)
so for example you might end up with something like this.
|
Re: Doors asking questions
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.ClickCode:
Sub move(ByVal g As Graphics, ByVal distance As Short, ByVal aboard As Board) |
Re: Doors asking questions
This is basibly where my doors are drawn on the board
Code:
Dim door1 As New door(135, 380, 10, 40) |
Re: Doors asking questions
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. |
| All times are GMT +5.5. The time now is 13:20. |