Computer Science Canada Issue With Methods Not Being Called |
Author: | Varsteil [ Thu Jan 10, 2013 10:22 am ] | ||||||
Post subject: | Issue With Methods Not Being Called | ||||||
Occasionally, when I run my Blackjack program, when it comes to the option to call a different method, when I choose to go to my method to "hit", my program just keeps going back to the options, but when I choose to "fold" or "stay", everything is fine. I noticed that seems to occur with specific cards, such as Twos or Threes. Here's an example of my console output:
Here's my block of code for changing methods:
Here's my block of code for selecting my cards:
Thanks for reading, does anyone know what might be causing this? The cards I noticed this happening with are mostly the Two and Three of Spades and the Three of Clubs. |
Author: | DemonWasp [ Thu Jan 10, 2013 11:53 am ] | ||
Post subject: | RE:Issue With Methods Not Being Called | ||
This code does not do what you want it to do:
|
Author: | Varsteil [ Fri Jan 11, 2013 10:19 am ] | ||
Post subject: | Re: Issue With Methods Not Being Called | ||
Thanks for pointing that out to me, I made a revision to it
Do you have any idea how I could fix the bugs I mentioned in the OP? |
Author: | DemonWasp [ Fri Jan 11, 2013 11:14 pm ] |
Post subject: | RE:Issue With Methods Not Being Called |
First, that block of revised code still doesn't do what you want it to do. What if the "Pick a new card" bit also picks a card that's already used? Second, that switch statement looks very suspicious to me, since it's always assigning to cardNames[0] rather than cardNames[variable], as I would generally expect. Other than that, though, you haven't actually given us the full code of hitMethod() and an explanation of what your variables are used for. Without more details, I can't help you. |
Author: | Varsteil [ Mon Jan 14, 2013 9:54 am ] | ||
Post subject: | Re: Issue With Methods Not Being Called | ||
The ***** is the long list of card names Here's my code for the hit method, from what I can see, only the hit method causes bugs. What I'm trying to do is; it checks for whether or not the card in the hand already has a value, and if it does, it moves onto the next card, to a maximum of 5 cards in the hand since, from what I googled, the maximum hand size for blackjack is 5 cards. |