基本信息
源码名称:C# 双色球示例源码下载
源码大小:3.68KB
文件格式:.zip
开发语言:C#
更新时间:2014-05-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
namespace CPExample { using System; using System.ComponentModel; public class BallEventArgs : EventArgs { private readonly bool snoozePressed; private readonly int nrows = 0; public BallEventArgs(bool snoozePressed, int nrows) { this.snoozePressed = snoozePressed; this.nrows = nrows; } public bool SnoozePressed { get { return snoozePressed; } } public int NRows { get { return nrows; } } } public delegate void BallEventHandler(object sender, BallEventArgs e); public class DoubleColorBall { private int nrows = 0; private bool snoozePressed = false; private bool stop = false; public bool SnoozePressed { get { return snoozePressed; } set { snoozePressed = value; } } public bool Stop { get { return stop; } set { stop = value; } } public event BallEventHandler Notify; protected virtual void OnStart(BallEventArgs e) { BallEventHandler headler = Notify; if (headler != null) headler(this, e); } public void Start() { for (; ; ) { nrows ; if (stop) { break; } else if (snoozePressed) { System.Threading.Thread.Sleep(1000); { BallEventArgs e = new BallEventArgs(snoozePressed, nrows); OnStart(e); } } else { System.Threading.Thread.Sleep(300); BallEventArgs e = new BallEventArgs(snoozePressed, nrows); OnStart(e); } } } } public class WakeMeUp { public void Notify(object sender, BallEventArgs e) { output(); if (!(e.SnoozePressed)) { if (e.NRows % 5 == 0) { Console.WriteLine(); Console.WriteLine(" 继续显示 请按 Y"); Console.WriteLine(" 暂停 请按 N"); Console.WriteLine(" 退出 请按 Q"); Console.WriteLine(); String input = Console.ReadLine(); if (input.Equals("Y") || input.Equals("y")) return; else if (input.Equals("N") || input.Equals("n")) { ((DoubleColorBall)sender).SnoozePressed = true; return; } else { ((DoubleColorBall)sender).Stop = true; return; } } } else { Console.WriteLine(); Console.WriteLine(" 继续显示一行 请按 Y"); Console.WriteLine(" 退出 请按 Q"); Console.WriteLine(); String input = Console.ReadLine(); if (input.Equals("Y") || input.Equals("y")) return; else { ((DoubleColorBall)sender).Stop = true; return; } } } public void output() { int p; int[] b = new int[7]; Random r = new Random(); b[0] = r.Next(1, 34); for (int j = 1; j < 6; ) { b[j] = r.Next(1, 34); for (p = 0; p < j; p ) { if (b[p] == b[j]) { break; } } if (p == j) { j ; } } int temp = 0; for (int i = 0; i < b.Length - 2; i ) { for (int j = i 1; j < b.Length - 1; j ) { if (b[j] < b[i]) { temp = b[i]; b[i] = b[j]; b[j] = temp; } } } b[6] = r.Next(1, 17); for (int k = 0; k < 7; k ) { System.Console.Write(b[k]); System.Console.Write((b[k].ToString().Length==2)?" ":" "); } System.Console.WriteLine(); } } public class DoubleColorBallDriver { public static void Main() { DoubleColorBall ball = new DoubleColorBall(); WakeMeUp w = new WakeMeUp(); ball.Notify = new BallEventHandler(w.Notify); ball.Start(); System.Console.ReadLine(); } } }