1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
|
using TwoColorBall.Common;
namespace TwoColorBall.Main;
public class Lottery { private Wallet _wallet = new(); private ReadData _readData = new(); private WriteData _writeData = new(); private Random _random = new();
private Dictionary<string, bool> _ballIsRecord = new();
private decimal _lottery = 0;
private decimal _bonusCumulative = 0;
private decimal _bonusTotal = 0;
private decimal _bonusAmount = 0;
private decimal _bonusAmounts = 0;
private int[] _prizeBall = new int[7];
private int[] _prizeCount = new int[7];
private string _prizeGrade = string.Empty;
public void Prize() { _readData.DeleteFile(this.GetType().Name); _readData.DeleteFile(@"PrizeRecord"); bool isPrize = WhetherPrize(); if (isPrize) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("\t存在购号记录,即将开奖!\n"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(" ================模拟开奖开始================"); StartPrize(); ComparativeData(); Console.WriteLine(" ================模拟开奖结束================"); Console.WriteLine(); } else { Console.ForegroundColor = ConsoleColor.Green; Console.Write("\t你没有任何形式的购号记录,请先购号后开奖!\n"); Console.ResetColor(); Console.WriteLine(); } _readData.DeleteFile(typeof(BallAutomatic).Name); _readData.DeleteFile(typeof(BallManual).Name); }
private bool WhetherPrize() { _readData.DeleteFile(this.GetType().Name); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\t正在判断是否开奖..."); Console.ResetColor(); _ballIsRecord = FindData(); bool isFind = _ballIsRecord.ToList().Any(e => e.Value == true); return isFind; }
private Dictionary<string, bool> FindData() { Console.ForegroundColor = ConsoleColor.Green; Console.Write("\t正在判断是否存在购号记录..."); Console.ResetColor(); Dictionary<string, bool> isFind = new Dictionary<string, bool> { { typeof(BallAutomatic).Name,false}, { typeof(BallManual).Name,false} }; return _readData.FindData(isFind); }
private void StartPrize() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\t正在产生开奖号码..."); Console.ResetColor(); BallAutomatic myBallAutomatic = new BallAutomatic(); Console.Write("【开奖号码】"); Red(); Blue(); Console.Write("\t【模拟开奖】"); string time = DateTime.Now.ToString(); Console.Write("时间:{0}", time); Console.WriteLine(); Console.WriteLine("\t开奖号码已产生!"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.Write("\t正在计算奖池金额..."); Console.ResetColor(); _lottery = _random.Next(10000000, 999999999); _bonusCumulative = _random.Next(1000000, 99999999); _bonusTotal = _lottery + _bonusCumulative; Task.Delay(1000).Wait(); Console.Write("\t本次开奖奖池金额为:{0}元;奖池中累积的奖金之和为:{1}元;奖金总额为:{2}元;", _wallet.FormatMoneyToDecimal(_lottery), _wallet.FormatMoneyToDecimal(_bonusCumulative), _wallet.FormatMoneyToDecimal(_bonusTotal)); Console.WriteLine(); _writeData.RecordLottery(this.GetType().Name, _prizeBall, time, _wallet.FormatMoneyToDecimal(_lottery), _wallet.FormatMoneyToDecimal(_bonusCumulative), _wallet.FormatMoneyToDecimal(_bonusTotal)); }
public void Red() { int[] redballs = new int[6]; for (int i = 0; i < redballs.Length; i++) { int ball = _random.Next(1, 34); for (int j = 0; j < i; j++) { while (ball == redballs[j]) { ball = _random.Next(1, 34); } } redballs[i] = ball; } for (int i = 0; i < redballs.Length - 1; i++) { for (int j = 0; j < redballs.Length - 1 - i; j++) { if (redballs[j] > redballs[j + 1]) { int max = redballs[j]; redballs[j] = redballs[j + 1]; redballs[j + 1] = max; } } } Console.Write("红色球:"); for (int i = 0; i < redballs.Length; i++) { Task.Delay(50).Wait(); Console.ForegroundColor = ConsoleColor.Red; Console.Write("{0,2:D2} ", redballs[i]); _prizeBall[i] = redballs[i]; Console.ResetColor(); } }
public void Blue() { int blueball = _random.Next(1, 17); Console.Write("蓝色球:"); Task.Delay(50).Wait(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("{0,2:D2} ", blueball); _prizeBall[6] = blueball; Console.ResetColor(); }
public void ComparativeData() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\t正在查找数据,请稍候..."); Console.ResetColor(); Console.WriteLine(" ========查看中奖开始========"); foreach (var br in _ballIsRecord) { string tip = br.Key == typeof(BallAutomatic).Name ? "系统购号" : "手动购号"; if (br.Value) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\t查找到{tip}数据,正在读取..."); Console.ResetColor(); JudgeData(br.Key); } else { Console.WriteLine($"\t你没有{tip}数据!"); } } if (_prizeCount[6] == 0) { Console.WriteLine("\t抱歉,你没有中奖!"); } else { Console.WriteLine($"\t你共中奖{_prizeCount[6]}注,获得总奖金:{_bonusAmounts}元!其中:" + $"一等奖{_prizeCount[0]}注;" + $"二等奖{_prizeCount[1]}注;" + $"三等奖{_prizeCount[2]}注;" + $"四等奖{_prizeCount[3]}注;" + $"五等奖{_prizeCount[4]}注;" + $"六等奖{ _prizeCount[5]}注;"); } _wallet.RechargeOrConsumptAutomatic(_bonusAmounts); _writeData.RecordPrizeAmounts(_prizeCount, _wallet.FormatMoneyToDecimal(_bonusAmounts)); Console.WriteLine(" ========查看中奖结束========"); Array.Clear(_prizeCount, 0, _prizeCount.Length); _bonusAmounts = 0; }
public void JudgeData(string name) { int rows = _readData.GetRowsCount(name); string tip = name == typeof(BallAutomatic).Name ? "系统购号" : "手动购号"; for (int everyrow = 1; everyrow <= rows; everyrow++) { string[] datastr = new string[4]; datastr = _readData.ReadBallData(name, everyrow); int[] databall = new int[7]; string sequence = datastr[1]; string redballstr = datastr[2]; for (int i = 0; i < 6; i++) { databall[i] = int.Parse(redballstr.Substring(i * 2, 2)); } databall[6] = int.Parse(datastr[3]); string time = datastr[4]; int red = 0; int blue = 0; for (int i = 0; i < _prizeBall.Length; i++) { if (_prizeBall[i] == databall[i]) { _ = i < 6 ? red++ : blue++; } } JudgePrize(sequence, databall, time, tip, red, blue); } }
public void JudgePrize(string sequence, int[] databall, string time, string tip, int red, int blue) { bool output = false; if (red == 6 && blue == 1) { _prizeGrade = "一"; _bonusAmount = _bonusTotal * 0.75m; if (_bonusAmount >= 10000000) { _bonusAmount = 10000000; } _prizeCount[6]++; _prizeCount[0]++; output = true; } if (red == 6 && blue == 0) { _prizeGrade = "二"; _bonusAmount = _bonusTotal * 0.25m; if (_bonusAmount >= 10000000) { _bonusAmount = 5000000; } _prizeCount[6]++; _prizeCount[1]++; output = true; } if (red == 5 && blue == 1) { _prizeGrade = "三"; _bonusAmount = 3000; _prizeCount[6]++; _prizeCount[2]++; output = true; } if ((red == 5 && blue == 0) || (red == 4 && blue == 1)) { _prizeGrade = "四"; _bonusAmount = 200; _prizeCount[6]++; _prizeCount[3]++; output = true; } if ((red == 4 && blue == 0) || (red == 3 && blue == 1)) { _prizeGrade = "五"; _bonusAmount = 10; _prizeCount[6]++; _prizeCount[4]++; output = true; } if ((red == 2 && blue == 1) || (red == 1 && blue == 1) || (red == 0 && blue == 1)) { _prizeGrade = "六"; _bonusAmount = 5; _prizeCount[6]++; _prizeCount[5]++; output = true; } if (output) { _bonusAmounts += _bonusAmount; Console.Write("第【{0}】注:红色球:", sequence); Console.ForegroundColor = ConsoleColor.Red; for (int i = 0; i < 6; i++) { Console.Write("{0,2:D2} ", databall[i]); } Console.ResetColor(); Console.Write("蓝色球:"); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("{0,2:D2}", databall[6]); Console.ResetColor(); Console.Write("\t【{0}】", tip); Console.Write("时间:{0}", time); Console.Write("\t[该注中了{0}等奖!获得奖金:{1}元;]", _prizeGrade, _wallet.FormatMoneyToDecimal(_bonusAmount)); _writeData.RecordPrize(sequence, databall, time, tip, _prizeGrade, _wallet.FormatMoneyToDecimal(_bonusAmount)); Console.WriteLine(); } } }
|