Forums Register Login

Five Card Draw Poker Game Registering 6+ cards

+Pie Number of slices to send: Send
So this wednesday I decided to make a poker game since I thought I knew everything I needed to make to make it. then I ran into the attached error. The first place where it says "your new hand is" should say your cards from 2 to ace. but if you look at the numbers there are two tens. The following code is whats responsible for changing these numbers. Sorry for the messy code. also sorry it is so long, but it is divided into 5 almost identical parts. I just dont understand why this is occuring. it should subtract whatever it adds.

problem.PNG
error
[problem.PNG]
+Pie Number of slices to send: Send
It's very hard to read your code, especially when the first thing is an uninitialized variable. Is this all in one method? Break it out into smaller methods. Also, repeated code should be put in a method and called. Just doing this is going to make your code easier to debug.
+Pie Number of slices to send: Send
And get rid of those switch blocks. They can probably be replaced by the appropriate data structure.
+Pie Number of slices to send: Send
yeah really sorry about how hard it is to read. I was just trying to get it done and didn't separate it into different methods, this is approximately lines 500 to 1000 out of 1200 in my program, its technically not repeated each repeat is checking a different variable. but this is the only block where the card counters are decreased and before the program run that I went through with the picture I've never had any added just had problems with keeping cards from previous hand so I figured the problem was probably here. all variables have been initialized. and I realize that the error would be next to impossible to find. but I'm thinking it is almost definitely a logical error. If you want I can upload the whole problem, but I figured even 500 lines of code is stretching what is reasonable.

edit: oh and the reason I am using switch statements is they are easy to use. also why not use them. If they serve the purpose they were meant for and are easy to read it does its job.
+Pie Number of slices to send: Send
 

joseph Anderson wrote: . . . its technically not repeated each repeat is checking a different variable. . . .

No, that is repeated code which you are pretending is different on each occasion

. . . switch statements . . . are easy to use. . . . they serve the purpose they were meant for and are easy to read it does its job.

Are you trying to tell us those blocks are easy to read? Each consists of 14 13 repeated lines, and squeezing the code together into single lines makes it more difficult to read.
+Pie Number of slices to send: Send
This is repeated code, even if you do use a different variable:


it should be put into a method where you pass in your four variables one after another (hmmm...maybe that suggests a loop)
+Pie Number of slices to send: Send
Yeah, I just went over it with my brother, and when I told him that I only used one method/class he said "how did you even do that", he was kinda surprised at the lack of methods and thought it could be condensed to about a third the total volume. He did however give me an idea for how to solve the issue, though it will take several hundred lines of code which I don't feel like putting in right now. instead of reducing as I am putting the cards into the deck do the card scoring right before the hand scoring.

I appreciate your help. And will put this as solved.
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 549 times.
Similar Threads
Help With 5 card stud program
Keyboard response from user
Need help with an applet
How to get a card deck applet working
Using arrays to randomly generate images? (applet)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 21:55:57.