关闭

关闭

封号提示

内容

首页 c#纸牌小游戏代码.doc

c#纸牌小游戏代码.doc

c#纸牌小游戏代码.doc

上传者: gui莉容 2017-12-08 评分 5 0 112 15 511 暂无简介 简介 举报

简介:本文档为《c#纸牌小游戏代码doc》,可适用于外语资料领域,主题内容包含c#纸牌小游戏代码*项目三*usingSystemusingSystemCollectionsGenericusingSystemTextusing符等。

c#纸牌小游戏代码*项目三*usingSystemusingSystemCollectionsGenericusingSystemTextusingSystemThreadingnamespaceConsoleApplication{classGame{stringstr=newstringintnumber=newintinti=inta=newintintb=newintintc=newintintd=newintinte=newintRandomra=newRandom(unchecked((int)DateTimeNowTicks))publicvoidgetnum(intnumber,intminnum,intmaxnum){intflagflag=numberi=raNext(,)intf=while(f<i){if(numberf==flag)getnum(number,,)f}}publicvoidGetRandomNum()给number随机赋从到不同的值{while(i<){intflagflag=numberi=raNext(,)intf=while(f<i){if(numberf==flag){getnum(number,,)break}f}i}}publicvoidEnterCard()给每个字符串数组赋上牌值{str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="oftheclub"str="Jackoftheclub"str="queenoftheclub"str="kingoftheclub"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="ofthediamond"str="Jackofthediamond"str="queenofthediamond"str="kingofthediamond"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="oftheheart"str="Jackoftheheart"str="queenoftheheart"str="kingoftheheart"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="ofthespade"str="Jackofthespade"str="queenofthespade"str="kingofthespade"}publicvoidFaPai(intPersonNum)发牌{for(intj=j<PersonNumj){aj=numberj*bj=numberj*cj=numberj*dj=numberj*ej=numberj*}}publicvoidPrint(stringPersonName,intj)显示玩家的牌{ConsoleWriteLine("玩家{}的牌",PersonNamej)ConsoleWriteLine("{}",straj)ConsoleWriteLine("{}",strbj)ConsoleWriteLine("{}",strcj)ConsoleWriteLine("{}",strdj)ConsoleWriteLine("{}",strej)}publicvoidPrint(stringPersonName,intj)显示玩家的牌{ConsoleWriteLine("玩家{}剩下的牌",PersonNamej)ConsoleWriteLine("{}",straj)ConsoleWriteLine("{}",strbj)ConsoleWriteLine("{}",strcj)ConsoleWriteLine("{}",strdj)ConsoleWriteLine("{}",strej)ConsoleWriteLine("按ENTER建进入下一个玩家")ConsoleReadLine()}publicboolCompareAns(intj,stringPersonName,intn,boolbool)对玩家的牌与胜利的结果进行比较{intmin=,max=max=(aj>bj)aj:bjmax=(cj>max)cj:maxmax=(dj>max)dj:maxmax=(ej>max)ej:maxmin=(aj<bj)aj:bjmin=(cj<min)cj:minmin=(dj<min)dj:minmin=(ej<min)ej:minif(min>=max<||min>=max<||min>=max<||min>=max<){ConsoleClear()ConsoleWriteLine("恭喜玩家{}赢得游戏~",PersonNamej)bool=false}判断是否还有底牌可供玩家拿取elseif(n==){ConsoleClear()ConsoleWriteLine("没有底牌了~~重新开始。")bool=false}returnbool}publicvoidTakeCard(stringPersonName,intPersonNum)玩家打牌{GetRandomNum()intn=,botton=intf=intup=,up=boolbool=trueboolbool=false发牌FaPai(PersonNum)玩家打牌n=*PersonNumwhile(bool){for(intj=j<PersonNumj){显示玩家的牌ConsoleClear()if(bool){ConsoleWrite("上一玩家打出的牌是")ConsoleWriteLine("{}",strup)}bool=truePrint(PersonName,j)玩家从剩下的牌中拿牌或拿上一玩家扔出来的牌charD='f'if(n==*PersonNum){try{ConsoleWriteLine("按D从剩下的牌中拿一张牌")D=ConvertToChar(ConsoleReadLine())}catch(Exceptione){ConsoleWriteLine(eMessage)ThreadSleep()SystemEnvironmentExit()}if(D=='D'||D=='d'){f=numbernnPrint(PersonName,j)ConsoleWriteLine("{}",strf)}}else{ConsoleWriteLine("按D从剩下的牌中拿一张牌或者按T拿被上一玩家打的牌")D=ConvertToChar(ConsoleReadLine())if(D=='D'||D=='d'){f=numbernnPrint(PersonName,j)ConsoleWriteLine("{}",strf)}elseif(D=='t'||D=='T'){Print(PersonName,j)ConsoleWriteLine("{}",strup)}}打牌try{ConsoleWriteLine("输入你想要打出牌的序号:")botton=ConvertToInt(ConsoleReadLine())}catch(Exceptione){ConsoleWriteLine(eMessage)ThreadSleep()SystemEnvironmentExit()}switch(botton){case:{ConsoleWriteLine("被打出的牌是{}",straj)up=upup=ajaj=bjbj=cjcj=djdj=ejif(D=='d'||D=='D')ej=felseif(D=='t'||D=='T')ej=upPrint(PersonName,j)break}case:{ConsoleWriteLine("被打出的牌是{}",strbj)up=upup=bjbj=cjcj=djdj=ejif(D=='d'||D=='D')ej=felseif(D=='t'||D=='T')ej=upPrint(PersonName,j)break}case:{ConsoleWriteLine("被打出的牌是{}",strcj)up=upup=cjcj=djdj=ejif(D=='d'||D=='D')ej=felseif(D=='t'||D=='T')ej=upPrint(PersonName,j)break}case:{ConsoleWriteLine("被打出的牌是{}",strdj)up=upup=djdj=ejif(D=='d'||D=='D')ej=felseif(D=='t'||D=='T')ej=upPrint(PersonName,j)break}case:{ConsoleWriteLine("被打出的牌是{}",strej)up=upup=ejif(D=='d'||D=='D')ej=felseif(D=='t'||D=='T')ej=upPrint(PersonName,j)break}case:{ConsoleWriteLine("被打出的牌是{}",strf)up=fPrint(PersonName,j)break}default:ConsoleWriteLine("输入错误")break}判断结果bool=CompareAns(j,PersonName,n,bool)if(bool==false)break}}}}classExeMain{staticvoidMain(stringargs){intPersonNum=Gameobj=newGame()ConsoleWriteLine("第一个输入的名字将作为第一个开始拿牌的人:")ConsoleWriteLine("游戏的人数:")try{PersonNum=ConvertToInt(ConsoleReadLine())}catch(Exceptione){ConsoleWriteLine(eMessage)ThreadSleep()SystemEnvironmentExit()}stringPersonName=newstringPersonNumfor(inti=i<PersonNumi){ConsoleWriteLine("输入玩家{}的名字",i)PersonNamei=ConsoleReadLine()}objEnterCard()给每个字符串数组赋值objTakeCard(PersonName,PersonNum)给每个玩家发牌ConsoleReadLine()}}}

精彩专题

职业精品

上传我的资料

热门资料

资料评价:

/ 15
所需积分:0 立即下载

意见
反馈

返回
顶部

Q