I am trying to write a frame program that allows you to play Texas Hold'em Poker. And I am having trouble with function hasPair that decides if CurrentPlayer has a Pair:
public bool hasPair(Player CurrentPlayer)
{
bool flag;
Card[] SevenCards = new Card[7];
SevenCards[0].Color = CurrentPlayer.Card1.Color;
SevenCards[0].Number = CurrentPlayer.Card1.Number;
SevenCards[1].Color = CurrentPlayer.Color2;
SevenCards[1].Number = CurrentPlayer.Number2;
SevenCards[2] = Ground.Card1;
SevenCards[3] = Ground.Card2;
SevenCards[4] = Ground.Card3;
SevenCards[5] = Ground.Card4;
SevenCards[6] = Ground.Card5;
flag = isThere_Pair(SevenCards);
return flag;
}
And here is how CurrentPlayer receives its cards:
public void Deal_Cards(Player Player)
{
int Color1, No1, Color2, No2;
while (true)
{
dealhelper1:
Color1 = (RandomColor.Next() % 4);
No1 = ((RandomNo.Next() % 13));
if (CardDeck[Color1, No1].isChosen == true)
{
goto dealhelper1;
}
if (CardDeck[Color1, No1].isChosen == false)
{
Player.Card1.Color = Color1;
Player.Card1.Number = No1+1;
Player.Card1.imagePath = CardDeck[Color1, No1].imagePath;
Player.Color1 = CardDeck[Color1, No1].Color;
Player.Number1 = CardDeck[Color1, No1].Number;
CardDeck[Color1, No1].isChosen = true;
break;
}
}
while (true)
{
dealhelper2:
Color2 = (RandomColor.Next() % 4);
No2 = ((RandomNo.Next() % 13));
if (CardDeck[Color2, No2].isChosen == true)
{
goto dealhelper2;
}
if (CardDeck[Color2, No2].isChosen == false)
{
CardDeck[Color2, No2].isChosen = true;
Player.Card2.Color = Color2;
Player.Card2.Number = (No2)+1;
Player.Color2 = CardDeck[Color2, No2].Color;
Player.Number2 = CardDeck[Color2, No2].Number;
break;
}
}
display_Player_Cards(Player);
}
But in the hasPair function, CurrentPlayer's cards' numbers and colors are 0. I tried it in different ways but when I ask in a query, i cannot get the player cards' number values, although they have been initialized by the Deal_Cards function. Ground's cards have no problem, though.
interestingly, display_Player_Cards(Player) function works correctly (so it takes the values successfully and displays the cards) .
I use public variables of type Player (struct) like:
public Player P1 = new Player();
public Player AI = new Player();
Why can't they hold their values? How can I solve this issue? Thanks for help.
Deal_Cardsmethod even finishes execution. Thosewhile (true)loops are really, really dangerous. If it never finishes execution, then you've probably found the answer why your fields are all zero.