Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Blackjack Win/Loss Issue

Author
Message
Rannxz
12
Years of Service
User Offline
Joined: 2nd Dec 2011
Location:
Posted: 2nd Dec 2011 23:14 Edited at: 3rd Dec 2011 00:49


When I play the game, only sometimes does it give me the win/loss ending before restarting the hand. It sometimes just ends the loop and goes straight to a new hand without giving me a popup telling me that I won or lost.

When it runs, whenever you or the AI reaches 21 it's supposed to tell you if you won or lost. Meanwhile the same is supposed to apply if you or the AI go over 21, it's supposed to tell you if you won or lost. However, I've noticed that it'll restart the game if both the player and AI go over 21 or if just the player goes over 21, it won't tell me that I've lost, instead it just restarts the game.

Also, I have another issue. When the player either wins or loses, if theres only 3 cards on the screen for each player, instead of restarting the loop like it should, it continues to play the hand. How would I fix this? Every attempt I've tried either causes the program to stop working or the game doesn't sync and the scores from multiple hands starts to pile up.

Attachments

Login to view attachments
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 3rd Dec 2011 06:05


At cursory glance, the first line of your conditional doesn't make sense. I think you mean to say VALTOTAL and VALTOTALE.
I'd highly suggest that you adopt better practices when naming variables. Use unique, descriptive names. Something like:
ValueTotal_Player and ValueTotal_PC

Next I'd suggest using a case select statement for this area which might make things more clear, but it can be done with all of these conditionals just the same.

Let's look at these conditions a bit closer. The first two conditions look OK on their own.

Condition 3 looks fine, but you need a WAIT KEY command before you execute GOTO Game again...or should.
WAIT KEY is missing from all the rest of the conditionals.

Condition 4 is confusing, I don't think you want that to execute if ValTOTAL is equal to 21, but you are using an operator => . I'm not even sure if that's a legal operator, it should be >= (greater than or equal to) just like you would say it, but then again I've never tried reversing the two to see if that makes a difference.

Condition 5 and 6 seem fine.
Condition 7 is confusing, but should work. I'd suggest using something clearer:
if ValueTotal > 21 and ValueTotalE > 21
center text 320,200, "It's a tie! Though players in black jack hit, stay, or bust before dealers even begin to hit..."
endif


I hope these suggestions help. I don't think they'll fix all of your problems, because there are likely a few more in the code. I'm sorry I can't go into further but your code is really difficult to read. Also I can't compile it without making massive changes since I don't have all of the resource files you have and don't really want to download them.

I'd highly suggest working through a book that explains program structure utilizing functions.
Hands on DarkBASIC Pro Vol 1 is great and a breeze to get through. Also I find that DarkBASIC Pro Game Programming is just as good, if not better. there are also a number of basic tutorials out there by TDK man that are extremely helpful. Basically if you can write it as a function, do it, especially when starting out because it gets really hard to debug spaghetti code like you're creating here. Compartmentalizing routines inside functions makes it a ton easier to test.

Keep up the work, you'll get there!

~Napland Games~
Rannxz
12
Years of Service
User Offline
Joined: 2nd Dec 2011
Location:
Posted: 3rd Dec 2011 14:55
Thank you for taking the time to look at my code. Unfortunately, the problem with the code just restarting itself whenever a certain condition was met is still there.

I added the wait key before each goto statement, however whenever that condition was met, it actually froze my game up and continued to play the hand even though the screen wasn't being refreshed(the cards from the previous hand were still on screen) and the score wasn't being adjusted.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 3rd Dec 2011 17:28
at second glance it also looks like you are resetting the variables at the wrong time. try setting them all to 0 when the game loop starts. I'm not sure why they're in the conditionals that are checking for winning/losing game conditions. it looks like if you or the dealer get less than 21 then the variables get reset. there are also a lot more mistakes in there that i dont have time to point out. id highly suggest a start over, map out your logic in plain english first (pseudo code) then rewrite to code. remember to use functions more and subroutines a lot less. good luck!

~Napland Games~
Rannxz
12
Years of Service
User Offline
Joined: 2nd Dec 2011
Location:
Posted: 3rd Dec 2011 19:49
Thanks, I'm gonna try to edit the code now based on your suggestions. I'll edit to let you know if it works.

I'm still pretty new at this, I'm not really sure how to recreate this code using mainly functions instead of subroutines and goto statements though. Any advice you could give me?
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 3rd Dec 2011 23:58
There's quite a few suggestions in my posts, best advice I can give is stay away from subroutines as much as you can, name variables clearly, write out game logic first in structured english (or pseudo code), and use functions instead of subroutines. Lots of tutorials out there for beginners will help you with this.

This book is great http://www.digital-skills.co.uk/DBProVol1.pdf
That will show you the first 4 chapters. I highly suggest buying it. There are a couple of typos in the code in the book, but pretty minimal as far as other tutorials.

The book takes you from knowing nothing about programming (which it looks like you have some programming skill already) to making some actual graphical games. He concentrates on how to structure game logic and game documentation so that you can write the code quickly with minimal need for debugging.

Work hard to make clean code. People can help you with clean code.

Good luck and keep it up.

~Napland Games~
Rannxz
12
Years of Service
User Offline
Joined: 2nd Dec 2011
Location:
Posted: 4th Dec 2011 01:32
Based on what you've told me, I was able to 'fix' the code to a certain extent.

Now, each time I play the game, a win or loss condition WILL pop up which is great, however, no matter what it does, it'll continue to play the hand until all 8 button presses are finished.

Is there a better statement to put instead of "GOTO Game" after each win/loss condition? The code seems like it doesn't want to perform the GOTO Game step until all button presses have been completed.

Thank you for all your help. I understand its difficult to deal with disorganized code. I guess we all gotta start somewhere , unfortunately for me, all my problems in life get worse before they start to get better
Rannxz
12
Years of Service
User Offline
Joined: 2nd Dec 2011
Location:
Posted: 4th Dec 2011 05:31
I'd edit my previous post but since I'm a new member, I don't actually see it yet(they haven't approved my post yet )

I was able to successfully 'fix' the code. Instead of continuing to use 't' to do everything, I just added a inkey$() and I made it reset everything. It might not be the best way to deal with it, but as I learn more about programming, I'll edit and improve on it.

Thank you Naphier, you've been a great help and I plan to get that book sometime in the near future.
danctodd
14
Years of Service
User Offline
Joined: 31st Jul 2010
Location:
Posted: 4th Dec 2011 16:47
He's definitely right suggesting that you get the "Hands on DarkBASIC Pro Volume 1" book. It is a great read. I'm struggling with programming but the book helps immensely.

As for the small errors in the book, hopefully most of those will be fixed in the near future. I am helping re-proofread the books and am taking my time to spot inconsistent coding structure, small errors in code and simple grammatical issues.
The author of the books is a great guy, so if you are having any issues, you can always send an email his way.

Login to post a reply

Server time is: 2024-11-22 11:18:21
Your offset time is: 2024-11-22 11:18:21