sounds good but I will implement AI at a later date, thx for the input.
poker game
I have a very simple problem I want to draw text to the screen and then erase it and redraw new text to the screen I am using if/else commands to do it, I will stub out some code to see if I can figure out the problem,
well I have been working on my problem and it appears that when the if statement is executed it ignores the first else statement but falls through to the next else statement ignoring the second if statement I want it to also ignore the second else statement as well.
here is my code snippet
#include <iostream>
using namespace std;
int main()
{
int count = 0;
if (count == 0)
{
cout << "Draw text" << endl;
}
else
{
cout << "Draw second text" << endl;
}
if (count == 1)
{
cout << "Draw third text" << endl;
}
else
{
cout << "Draw fourth text" << endl;
}
return 0;
}
Desired Effect :
- At first if() ignore first else. (oh)
- also ignore second else ignoring the second if() (sure, why not)
// Probably you want something more like this
int main()
{
int count = 0;
if(count == 0) cout << "Draw text" << endl;
if(count == 1) cout << "Draw second text" << endl;
if(count == 2) cout << "Draw third text" << endl;
if(count == 3) cout << "Draw fourth text" << endl;
return 0;
}
Dev careful. Pixel on board.
That makes both of us.
Get some rest. Tomorrow is another day.
Dev careful. Pixel on board.
here is some updated code
#include <iostream>
using namespace std;
int main()
{
int count = 0;
if (count == 0)
{
cout << "Flush" << endl;
}
else
{
cout << "High Card" << endl;
}
if (count == 1)
{
cout << "Straight" << endl;
}
else
{
cout << "High Card" << endl;
}
return 0;
}
here is the code I am working on, I am trying to get the text to print to the screen depending if it is a flush or high card not at the same time, I don't want the text to overlap
bool flush = true;
if (shuffled_state[0] < 14 && shuffled_state[1] < 14 && shuffled_state[2] < 14 && shuffled_state[3] < 14 && shuffled_state[4] < 14&&flush==true)
{
surface_thirteen = TTF_RenderText_Solid(font, text_six, textColor);
SDL_BlitSurface(surface_thirteen, NULL, gScreenSurface, &score_one);
flush = true;
}
if ((shuffled_state[0] > 13 && shuffled_state[0] < 27) && (shuffled_state[1] > 13 && shuffled_state[1] < 27) && (shuffled_state[2] > 13 && shuffled_state[2] < 27) && (shuffled_state[3] > 13 && shuffled_state[3]) < 27 && (shuffled_state[4] > 13 && shuffled_state[4] < 27&&flush==true))
{
surface_thirteen = TTF_RenderText_Solid(font, text_six, textColor);
SDL_BlitSurface(surface_thirteen, NULL, gScreenSurface, &score_one);
flush = true;
}
if ((shuffled_state[0] > 26 && shuffled_state[0] < 40) && (shuffled_state[1] > 26 && shuffled_state[1] < 40) && (shuffled_state[2] > 26 && shuffled_state[2] < 40) && (shuffled_state[3] > 26 && shuffled_state[3]) < 40 && (shuffled_state[4] > 26 && shuffled_state[4] < 40)&&flush==true)
{
surface_thirteen = TTF_RenderText_Solid(font, text_six, textColor);
SDL_BlitSurface(surface_thirteen, NULL, gScreenSurface, &score_one);
flush = true;
}
if (shuffled_state[0] > 39 && shuffled_state[1] > 39 && shuffled_state[2] > 39 && shuffled_state[3] > 39 && shuffled_state[4] > 39&&flush==true)
{
surface_thirteen = TTF_RenderText_Solid(font, text_six, textColor);
SDL_BlitSurface(surface_thirteen, NULL, gScreenSurface, &score_one);
flush = true;
}
if (flush == false)
{
surface_one = TTF_RenderText_Solid(font, text, textColor);
SDL_BlitSurface(surface_one, NULL, gScreenSurface, &score_one);
}
can you respond to my latest post I am trying really hard to resolve my problem
There are a number of things we should work on.
Let's tackle the easier ones first.
You need to immediately improve your variable naming before continuing. shuffled_state
I recognize from the example code I've suggested, it refers to the deck of 52 cards.
That is not what you want here. You want to be testing a hand of five cards.
Refer to the sample structure named HandInfo
. In that structure is an array named cards
.
Those are the items we should be testing when referring to a hand of cards.
Your ranges look good but the Flush==true
does not belong in these tests.
The ranges are the test, so remove flush==true
The flush=true
in the body of each is correct but the bool flush=true
at the beginning probably should be bool flush=false
initially.
Resuming the discussion on variable naming, surface_thirteen
, text_six
and score_one
could be better.
Make them so that they describe what their use is. This is called self-commenting.
You're dealing with a SDL_Surface
, a const char*
and a SDL_Rect
respectively.
As an example, a better naming for surface_thirteen would be src_surface
, text_six would be probably text_flush, and score_one would be dst_rect
or something similar. score_one
doesn't say SDL_Rect at all.
Maybe that's a bit of a nit-pick but try it. See if it helps, especially for when you read your own code at a later date.
Next up, code duplication. What are we doing here?
Both your SDL calls can be removed from every conditional block.
After your range tests, the boolean flush
will be in one or the other state.
In your last test, if (flush==false)
do what you are doing there. That's fine, then else for the other we've just removed above that.
Now…I'm not saying this is exactly what you should do.
But it might be an improvement.
Lastly, instead of “here is my code, I want this”, let's try to ask better questions.
It's difficult to guess what you are trying to do from what you do show.
Tell us what tutorial you're following, that might reveal some insight.
You should also be reading the SDL documentation for the functions you are using.
Also, I see you are using pieces of my code. That's great, have at it.
Feel free to ask about anything you don't understand with that as well.
http://gamedev.net/forums/topic/717647-poker-game/5467306/?page=2
http://gamedev.net/forums/topic/717647-poker-game/5467512/?page=6
For clarity, the above is all just words.
Here is the same thing but in code form.
bool flush_found = false;
if (hand.cards[0] < 14 && hand.cards[1] < 14 && hand.cards[2] < 14 && hand.cards[3] < 14 && hand.cards[4] < 14)
{
flush_found = true;
}
if ((hand.cards[0] > 13 && hand.cards[0] < 27) && (hand.cards[1] > 13 && hand.cards[1] < 27) && (hand.cards[2] > 13 && hand.cards[2] < 27) && (hand.cards[3] > 13 && hand.cards[3]) < 27 && (hand.cards[4] > 13 && hand.cards[4] < 27))
{
flush_found = true;
}
if ((hand.cards[0] > 26 && hand.cards[0] < 40) && (hand.cards[1] > 26 && hand.cards[1] < 40) && (hand.cards[2] > 26 && hand.cards[2] < 40) && (hand.cards[3] > 26 && hand.cards[3]) < 40 && (hand.cards[4] > 26 && hand.cards[4] < 40))
{
flush_found = true;
}
if (hand.cards[0] > 39 && hand.cards[1] > 39 && hand.cards[2] > 39 && hand.cards[3] > 39 && hand.cards[4] > 39)
{
flush_found = true;
}
// note I don't use SDL2. so this text writing is untested. Not the point.
if (flush_found == false)
{
src_surface = TTF_RenderText_Solid(font, text_highcard, textColor);
SDL_BlitSurface(src_surface, NULL, gScreenSurface, &dst_rect);
} else {
src_surface = TTF_RenderText_Solid(font, text_flush, textColor);
SDL_BlitSurface(src_surface, NULL, gScreenSurface, &dst_rect);
}
Still not great. As we advance in skill, there are cleaner ways.
I've shown you an example already with bitset from the standard library.
You seem to be resisting that, but here is what it would look like.
bool flush_found = false;
std::bitset<4> suit_bitset;
for (int i = 0; i < 5; i++)
{
if (hand.cards[i] < 14) suit_bitset.set(0); // clubs
if (hand.cards[i] > 13 && hand.cards[i] < 27) suit_bitset.set(1); // diamonds
if (hand.cards[i] > 26 && hand.cards[i] < 40) suit_bitset.set(2); // spades
if (hand.cards[i] > 39) suit_bitset.set(3); // hearts
}
if (suit_bitset.count() == 1) flush_found = true;
if (flush_found == false)
{
src_surface = TTF_RenderText_Solid(font, text_highcard, textColor);
SDL_BlitSurface(src_surface, NULL, gScreenSurface, &dst_rect);
} else {
src_surface = TTF_RenderText_Solid(font, text_flush, textColor);
SDL_BlitSurface(src_surface, NULL, gScreenSurface, &dst_rect);
}
Dev careful. Pixel on board.