Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
public class GameRules
{
// Calculate winnings based on the bet, winning number, and winning color
public int CalculateWinnings(Bet bet, int winningNumber, string winningColor)
{
// Split the bet type into its parts
string[] betParts = bet.Type.ToLower().Split(' ');
int betNumber;
string betColor = null;
// Check if the bet type consists of one part
if (betParts.Length == 1)
{
// If the bet type is a number
if (int.TryParse(betParts[0], out betNumber))
{
// Check if the bet number matches the winning number
if (betNumber == winningNumber)
{
// If the bet number matches, return the winnings (36 times the bet amount)
return bet.Amount * 36;
}
}
// If the bet type is a color
else if (betParts[0] == "red" || betParts[0] == "black")
{
// Assign the bet color
betColor = betParts[0];
}
}
// Check if the bet type consists of two parts
else if (betParts.Length == 2)
{
// If the bet type is a number and a color
if (int.TryParse(betParts[0], out betNumber) && (betParts[1] == "red" || betParts[1] == "black"))
{
// Assign the bet color
betColor = betParts[1];
// Check if the bet number and color match the winning number and color
if (betNumber == winningNumber && betColor == winningColor.ToLower())
{
// If the bet number and color match, return the winnings (36 times the bet amount)
return bet.Amount * 36;
}
}
}
// Check if the bet color matches the winning color
if (betColor != null && betColor == winningColor.ToLower())
{
// If the bet color matches, return the winnings (2 times the bet amount)
return bet.Amount * 2;
}
// If no winning condition is met, return 0
return 0;
}
// Check if the bet type is valid
public bool IsValidBetType(string betType)
{
// Split the bet type into its parts
string[] betParts = betType.ToLower().Split(' ');
// Check if the bet type consists of one part and is either a color or a number
return (betParts.Length == 1 && (betParts[0] == "red" || betParts[0] == "black" || int.TryParse(betParts[0], out _))) ||
// Check if the bet type consists of two parts and the first part is a number and the second part is a color
(betParts.Length == 2 && int.TryParse(betParts[0], out _) && (betParts[1] == "red" || betParts[1] == "black"));
}
}