i have a lot of method that take ref/out
as a parameter's. I made them this way because i had my variables declared in the class that im creating the methods.Now i moved to variables to separate classes and i cant pass the variables as ref/out parameters properly.So what should i do instead ? Those methods take a lot of parameters and they are all needed at some point. So maybe returning a tuple is solution, but i have heard that returning tuple with a lot of variables in it it's not good at all (im not sure if this is correct for .net 4.5 framework). I will post just some of those methods here because there's more than 25 of them..
private void SetPlayers(int start, int end, Panel panel, int chips, int turn, ref bool check, int newHorizontal, int newVertical, AnchorStyles one, AnchorStyles two)
{
if (chips > 0)
{
foldedPlayers--;
if (turn < start || turn > end) return;
if (Holder[start].Tag != null)
{
Holder[end].Tag = Reserve[end];
}
Holder[start].Tag = Reserve[start];
if (!check)
{
horizontal = newHorizontal;
vertical = newVertical;
}
check = true;
Holder[turn].Anchor = (one | two);
Holder[turn].Image = backImage;
//Holder[turn].Image = Deck[i];
Holder[turn].Location = new Point(horizontal, vertical);
horizontal += Holder[turn].Width;
Holder[turn].Visible = true;
Controls.Add(panel);
panel.Location = new Point(Holder[start].Left - 10, Holder[start].Top - 10);
panel.BackColor = Color.DarkBlue;
panel.Height = _settings.Height + 20;
panel.Width = (_settings.Width + 10) * 2;
panel.Visible = false;
if (i == end)
{
check = false;
}
}
}
This one might actually be done with tuple i think :
private void Combinations(int c1, int c2, ref int current, ref int power, Control lFold)
{
for (i = 0; i < 16; i++)
{
if (Reserve[i] == int.Parse(Holder[c1].Tag.ToString()) &&
Reserve[i + 1] == int.Parse(Holder[c2].Tag.ToString()))
{
RHighCard(ref current, ref power);
RPairFromTable(ref current, ref power);
RPairInHand(ref current, ref power);
RPairFromHand(ref current, ref power);
RTwoPairFromTable(ref current, ref power);
RHandTableTwoPair(ref current, ref power);
RTableHandTwoPair(ref current, ref power);
RTwoPair(ref current, ref power);
RThreeOfAKind(ref current, ref power, straight);
RStraight(ref current, ref power, straight);
RFlush(ref current, ref power, straight1);
RFullHouse(ref current, ref power, ref done, straight);
RFourOfAKind(ref current, ref power, straight);
RStraightFlush(ref current, ref power, st1, st2, st3, st4);
}
}
}
I will just post a few of those methods. They all change power and current the same way :
private void RHighCard(ref int current, ref int power)
{
if (current != -1) return;
current = -1;
power = Kicker;
Win.Add(new Type { Power = power, Current = current });
}
private void RPairFromTable(ref int current, ref int power)
{
if (current != -1) return;
for (int tc = 16; tc >= 12; tc--)
{
int max = tc - 12;
for (int k = 1; k <= max; k++)
{
if (tc - k < 12)
{
max--;
}
if (tc - k < 12) continue;
if (Reserve[tc] / 4 == Reserve[tc - k] / 4 && Reserve[tc] / 4 == 0)
{
current = 0;
power = 13 + Kicker;
Win.Add(new Type { Power = power, Current = current });
}
else if (Reserve[tc] / 4 == Reserve[tc - k] / 4 && Reserve[tc] / 4 != 0)
{
current = 0;
power = Reserve[tc] / 4 + Kicker;
Win.Add(new Type { Power = power, Current = current });
}
}
}
}
Again i must pass a class property as input to those methods and it wont return the value edited that's the main problem. Any alternative is welcome.
Also some info for my class variables :
public class UsersProperties
{
public int Chips;
public int Type;
public int Power;
public bool Turn;
public bool FoldTurn;
public AnchorStyles CardsAnchor;
public readonly Panel Panel = new Panel();
}
public class Player : UsersProperties
{
public Player()
{
Chips = 100000;
Type = -1;
Power = 0;
Turn = true;
FoldTurn = false;
CardsAnchor = AnchorStyles.Bottom;
}
}