We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Each player has to start with 1000 points and then wagers a certain amount on a horse (picked with a click). If you win, you get 9 times your wager back. If you lose, you lose the amount you wagered. At the end of the race, the name of the player that won is displayed, along with the amount of their winnings. Each player's "bank" is then updated to reflect the win/loss.
Answers
You don't have a proper use of arrays.
Arrays are lists, therefore they can and should be used with a for loop.
This belongs into
setup
after loadImages, because it is time consuming for the processorit can also be done with a for loop, e.g.
Similarly this
becomes
Similarly this
becomes
(this should become an array too:
)
Better than if
for
better use a
construct or even
Name the states
also I would name your states 0,1,2.... with names like
A sub function for each state
also make a sub function for each state. Your
draw()
would look like this:ALSO
also, we can't run your code since you use images.
make a secondary version with
text()
instead of images for the forumYour issue
You don't really say what is missing in your code.
Maybe you need this:
register the click on a horse in wager mode.
Best store these positions in two arrays
Then for loop over the array and use dist() for each horse and store the clicked horse number (index in the array) in extra variable and store the wager.
At the end of the game check for each player if index of winner horse is equal the initial clicked horse number.
What I need is for each player to click on a car and then that will be the one they bet on, if the horse they get on wins the wager/bet they put will be multiplied by 9 and put into their total bank. If they pick the wrong horse then they lose the amount they wagered/bet on.
Yes, I told you how to do that
Step by step.....
See end of my last post
Ok I made all my code organized now.
Does the wager work now?
You need to conpare the index of the car the player bet on and the index of the winner car
OK I did this:
Bu, I don't know how to make it say if the player chooses the 1st place car, then their wager is multiplied by 9 and put into the bank.
And if the player chooses the wrong car then they lose the amount they wagered.
That looks correct, if
currPlace
is the car that won. Is it?does it work?
did you define currPlace and p1Choice?
I don't know how to make a variable that is the car that won.
show your entire current code please
Do you know how to identify the car that has been clicked on to bet the wager in the beginning?
this line
should be in setup() please after you loaded this image
ok
you wrote:
here:
this is your old code
change this to
this
becomes
OK?
YES! THANK YOU!
this
becomes
see, when you now want to change the line spacing, you just change one number (
30
) and not 10 (or 8)the winner thing does not work, it goes from -1 to 0 every time, after the race goes to state 2 the winner becomes 0
even if I println the winner it stays at 1 every time
Forget about it I fixed it
well done!
thx
Does it work now completely, like selecting car to bet a wager, winner gets wager in his bank; bank amount gets displayed, new gane with this bank amount until one bank is empty...?
I have everything, except this constantly goes on, and adds, and subtracts the wager from/to the bank more than once:
plz help so the wager is either added/subtracted only once.
make sure those lines get called only once.
This means, you can implement the whole block into an if-clause
before setup say
boolean wagerIsAdded=false;
also set wagerIsAdded=false; when placing a new wager etc.
(since you work with states there is also a place where you move onto the state; it could be right before it, but let's skip that here)
I did this but it doesn't work: