问题描述
usingSystem;usingSystem.Collections.Generic;namespaceConsole_Test{classProgram{staticvoidMain(){//请裁判Judgmentment=Judgment.Instance;//告诉裁判这次要跑多远ment.TrackLength=1000;//玄武参赛ment.Join(newTortoise());//玉兔参赛ment.Join(newRabbit());//开始ment.Start();Console.ReadKey();}}///<summary>///欢迎伟大的裁判///</summary>publicclassJudgment{///<summary>///为了防止裁判太多造成不必要的混乱///也为了节省赛事的经费///本大赛只请一名裁判///</summary>privateJudgment(){}///<summary>///哈哈,就一个裁判啊///</summary>privatestaticJudgmentinstance=newJudgment();///<summary>///哥就是那个闪亮的唯一的伟大裁判///</summary>publicstaticJudgmentInstance{get{returninstance;}}privateintlength=-1;///<summary>///赛道长度,你不说,我怎么会知道会跑到神马时候啊///</summary>publicintTrackLength{get{returnlength;}set{if(length<0){length=value;}}}///<summary>///哥是裁判///神马选手哥看不见啊///全洗干净脚底板等我///哈哈///</summary>privateList<IRunner>runners=newList<IRunner>();///<summary>///来报名参赛哈///</summary>///<paramname="runner"></param>publicvoidJoin(IRunnerrunner){if(runners.Contains(runner)){Console.WriteLine("报过名了,就不要再报了");return;}runners.Add(runner);}///<summary>///开不开始///哥一句话///</summary>publicvoidStart(){if(TrackLength<0){Console.WriteLine("大家都不知道要跑多远,再等等!");return;}if(runners.Count<2){Console.WriteLine("神马,就你一个人,不用比了,勇气可嘉啊,奖杯给你了!");return;}Console.WriteLine("裁判:好了,欢迎大家参加本届神宠速度大比拼,此次参赛的选手有");foreach(IRunnerrunnerinrunners){Console.Write("【");Console.Write(runner.Name);Console.Write("】,");}Console.WriteLine("希望大家赛出成绩,赛出特色,比赛开始。。。");Console.WriteLine("3");Console.WriteLine("2");Console.WriteLine("1");Console.WriteLine("Start!");Console.WriteLine();newSystem.Threading.Thread(delegate(){boolisNotEnd=true;while(isNotEnd){foreach(IRunnerrunnerinrunners){runner.Run();if(runner.Score>=TrackLength){isNotEnd=false;Console.WriteLine("裁判:选手【{0}】成功夺冠!",runner.Name);break;}Console.WriteLine("裁判:选手【{0}】已经跑了{1}米,距终点还有{2}米",runner.Name,runner.Score,TrackLength-runner.Score);}System.Threading.Thread.Sleep(1000);}}).Start();}}///<summary>///没有我,谁也别想跑步///</summary>publicinterfaceIRunner{stringName{get;}///<summary>///我的正常速度///</summary>intSpeed{get;}///<summary>///爆发的速度///</summary>intSuperSpeed{get;}///<summary>///我的成绩///</summary>intScore{get;}///<summary>///跑一个给你看看///</summary>voidRun();}///<summary>///姐不是路过打酱油滴///姐不是芙蓉,玉凤///姐是Runner///姐是能跑的人的祖先///鸿星尔克ToBeNO.1///</summary>publicabstractclassRunner:IRunner{///<summary>///谁没有点小问题,只不过问题是随机的///</summary>protectedstaticRandomrandom=newRandom();publicstringName{get;protectedset;}publicintSpeed{get;protectedset;}publicintSuperSpeed{get;protectedset;}publicintScore{get;protectedset;}publicabstractvoidRun();}///<summary>///四大神兽之北宫玄武///前来助阵的有///白虎,朱雀,青龙///</summary>publicclassTortoise:Runner{publicTortoise(){Name="玄武";Speed=25;//不要惊奇,爷是神兽啊,跑得快不是爷的错SuperSpeed=30;}publicoverridevoidRun(){//哥有1/2的概率爆发啊,嘿嘿if(random.Next(1,3)<2){Console.WriteLine("{0}:看来扶老人过马路还是不错的啊,人品大爆发了!",Name);Score+=SuperSpeed;}else{Console.WriteLine("{0}:佛曰,缓者远行!嘿嘿!",Name);Score+=Speed;}}}///<summary>///顶级萌宠之月宫玉兔///前来助阵的有///嫦娥,吴刚,八戒(你来搞毛啊)///</summary>publicclassRabbit:Runner{privateboolisSleeped=false;publicRabbit(){Name="玉兔";Speed=40;SuperSpeed=45;}publicoverridevoidRun(){//如果发现自己睡过了,就有1/3的概率爆发if(isSleeped){if(random.Next(1,4)<2){Console.WriteLine("{0}:看我风一般的速度,yoyoyoyoyoyoyoyooooo!",Name);Score+=SuperSpeed;return;}}if(random.Next(1,3)<2){isSleeped=true;Console.WriteLine("{0}:昨晚偷了一夜的菜,睡一会,撑不住了",Name);}else{Console.WriteLine("{0}:比个赛么,何必那么认真呢?做兔子呢,最重要的开心!",Name);Score+=Speed;}}}}
解决方案
解决方案二:
解决方案三:
不懂
解决方案四:
楼主应该学习一下发贴如何插入代码。
解决方案五:
http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/28.gif