using System;
/// A class which assists LotteryAccount with the selection
/// of lucky accounts. Encapsulates a secret winning number
/// and the amount won. A singleton class.
public class Lottery{
private static Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
private int difficulty;
private readonly int winningNumber;
private readonly decimal amountWon;
private static Lottery uniqueInstance = null;
private Lottery(int difficulty){
this.difficulty = difficulty;
this.winningNumber = rdm.Next(difficulty);
this.amountWon = 500000.00M;
}
/// Returns the unique instance of this class
/// A measure of the difficulty of winning.
public static Lottery Instance(int difficulty){
if (uniqueInstance == null)
uniqueInstance = new Lottery(difficulty);
return uniqueInstance;
}
/// Draw and return a lottery number
public int DrawLotteryNumber{
get {return rdm.Next(difficulty);}
}
/// Return if n is equal to the winning number
public bool WinningNumber(int n){
return n == winningNumber;
}
///
/// Return the encapsulated amount won if
/// luckyNumber is the winning number.
///
/// Some integer number
public decimal AmountWon(int luckyNumber){
decimal res;
if (WinningNumber(luckyNumber))
res = amountWon;
else
res = 0.0M;
return res;
}
}