Question :
Write a C# program to simulate a slot machine draw. Each draw consists of 4 characters (2 alternating letters 2 numbers, like a1b2, c3x4, f5e3 etc.)
Have a method (say, 'ChaChing') which returns a random 4 characters in the above format. However, if a draw has occurred in the last 10 tries, then return a different draw.
In order for a jackpot, the draw will need to have both letters and numbers to be the same, i.e. a1a1, b4b4, h9h9 etc. Ensure that there is at least one jackpot in every 30 draws.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;
namespace examples
{
class Program
{
static void Main(string[] args)
{
Queue myQueue = new Queue();
Random r = new Random();
int JackpotNumber = r.Next(30);
for (int i = 0; i < 30; i++)
{
if (i == JackpotNumber)
{
string queueString = pattern(true);
myQueue.Enqueue(queueString);
}
else
{
string NonJP = pattern(false);
if (myQueue.Contains(NonJP))
{
string NonJP2 = pattern(false);
myQueue.Enqueue(NonJP2);
Console.WriteLine(NonJP2); }
else
{
myQueue.Enqueue(NonJP);
Console.WriteLine(NonJP);
}
}
} Console.ReadKey();
if (myQueue.Count > 30)
{
myQueue.Dequeue();
}
}
public static string pattern(bool IsJackpot)
{
Random random = new Random();
int i = random.Next(9);
int j = random.Next(9);
string[] strArr = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
StringBuilder str = new StringBuilder();
if (IsJackpot)
{
int index = random.Next(25);
str.Append(strArr[index]);
str.Append(i);
str.Append(strArr[index]);
str.Append(i);
return str.ToString();
}
else
{
int index = random.Next(25);
int index1 = random.Next(25);
if (index == index1 && i == j)
{
str.Append(strArr[index + 1]);
str.Append(i + 1);
str.Append(strArr[index]);
str.Append(i);
}
else
{
str.Append(strArr[index]);
str.Append(i);
str.Append(strArr[index1]);
str.Append(j);
}
return str.ToString();
}
}
}
}