00001 using System; 00002 00006 public class Lottery{ 00007 00008 private static Random rdm = new Random(unchecked((int)DateTime.Now.Ticks)); 00009 00010 private int difficulty; 00011 private readonly int winningNumber; 00012 private readonly decimal amountWon; 00013 private static Lottery uniqueInstance = null; 00014 00015 private Lottery(int difficulty){ 00016 this.difficulty = difficulty; 00017 this.winningNumber = rdm.Next(difficulty); 00018 this.amountWon = 500000.00M; 00019 } 00020 00023 public static Lottery Instance(int difficulty){ 00024 if (uniqueInstance == null) 00025 uniqueInstance = new Lottery(difficulty); 00026 return uniqueInstance; 00027 } 00028 00030 public int DrawLotteryNumber{ 00031 get {return rdm.Next(difficulty);} 00032 } 00033 00035 public bool WinningNumber(int n){ 00036 return n == winningNumber; 00037 } 00038 00044 public decimal AmountWon(int luckyNumber){ 00045 decimal res; 00046 if (WinningNumber(luckyNumber)) 00047 res = amountWon; 00048 else 00049 res = 0.0M; 00050 return res; 00051 } 00052 }