public void SortHands(THand[] handArray) { for (int i = 0; i < 4; i++) { handArray[i].sortHand(); } }
public string ToString(THand[] handArray) { String AllHands = ""; for (int i = 0; i < 4; i++) { AllHands += "Player " + (i + 1) + ": \r\n"; AllHands += handArray[i].ToString(); AllHands += "Points: " + handArray[i].calcPoints() + "\r\n \r\n"; } return AllHands; }
public void DealCards(THand[] handArray) { int cardIndex = 0; for (int i = 0; i < deckSize / numPlayers; i++) { for (int j = 0; j < numPlayers; j++) { handArray[j].addCard(cards[cardIndex]); cardIndex++; } } }
private void button1_Click(object sender, EventArgs e) { TDeck newDeck = new TDeck(); THand[] fourHands = new THand[4]; for (int i = 0; i < 4; i++) { fourHands[i] = new THand(); } newDeck.ShuffleDeck(); newDeck.DealCards(fourHands); //newDeck.SortHands(fourHands); CardBox.Text = newDeck.ToString(fourHands); findWinner(fourHands); }
private void findWinner(THand[] fourHands) { int maxPoints = 0; int maxPos = 0; bool tie = false; int[] allPoints = new int[4]; int[] tiePos = new int[4]; int numTies = 0; for (int i = 0; i < 4; i++) { int thisPoints = fourHands[i].calcPoints(); allPoints[i] = thisPoints; if (thisPoints > maxPoints) { maxPos = i; maxPoints = thisPoints; tie = false; numTies = 0; } else if (thisPoints == maxPoints) { tiePos[numTies] = maxPos; tiePos[++numTies] = i; maxPos = i; tie = true; } } if (tie) { String Winner = "Player " + (tiePos[0] + 1); int j; for (j = 1; j <= numTies; j++) { Winner += ", Player " + (tiePos[j] + 1); } Winner += " are tied with " + allPoints[tiePos[j]] + " points!"; WinnerBox.Text = Winner; } else WinnerBox.Text = "Player " + (maxPos + 1) + " wins with " + maxPoints + " points!"; Score1.Text = "" + allPoints[0]; Score2.Text = "" + allPoints[1]; Score3.Text = "" + allPoints[2]; Score4.Text = "" + allPoints[3]; }