欢迎来到天天文库
浏览记录
ID:23349891
大小:65.77 KB
页数:9页
时间:2018-11-06
《c#小游戏21点代码和界面设计》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、publicpartialclassForm1:Form{publicinta;publicintb;publicinti;publicint[]ab=newint[12];//数组ab存放临时的牌的图片号publicintzhuangnumber;//用于存放庄家点数publicintgamernumber;//用于存放游戏者点数publicPictureBox[]ptb=newPictureBox[12];publicForm1(){InitializeComponent();}//生成牌与点数privatevoidFirst(o
2、utinta,outintb,intq){Randomrd=newRandom();a=rd.Next(0,51);if(a>=0&&a<=3){b=2;}elseif(a>=4&&a<=7){b=3;}elseif(a>=8&&a<=11){b=4;}elseif(a>=12&&a<=15){b=5;}elseif(a>=16&&a<=19){b=6;}elseif(a>=20&&a<=23){b=7;}elseif(a>=24&&a<=27){b=8;}elseif(a>=28&&a<=31){b=9;}elseif(a>=32&
3、&a<=47){b=10;}elseif(a>=48&&a<=51){if(q>=0&&q<=21){b=10;}elseb=1;}else{b=0;Console.Read();}}//用递归算法随即生成之前未出现的牌publicvoidBijiao(outinta,outintb,intq,int[]abc){inti;Randomrd=newRandom();a=rd.Next(0,51);if(a>=0&&a<=3){b=2;}elseif(a>=4&&a<=7){b=3;}elseif(a>=8&&a<=11){b=4;}e
4、lseif(a>=12&&a<=15){b=5;}elseif(a>=16&&a<=19){b=6;}elseif(a>=20&&a<=23){b=7;}elseif(a>=24&&a<=27){b=8;}elseif(a>=28&&a<=31){b=9;}elseif(a>=32&&a<=47){b=10;}elseif(a>=48&&a<=51){if(q>=0&&q<=21){b=10;}elseb=1;}else{b=0;Console.Read();}for(i=0;i<52;i++){if(abc[i]==a)Bijiao
5、(outa,outb,q,abc);elsebreak;}}//不要牌后比较出赢家并把庄家隐藏的牌显现privatevoidbuttonResult_Click(objectsender,EventArgse){if(zhuangnumber>gamernumber){for(i=1;i<6;i++){if(ab[i]!=100)this.ptb[i].Image=this.imageList1.Images[ab[i]];}this.label2.Text=zhuangnumber.ToString();MessageBox.Sho
6、w("庄家赢了!开始下一局!");}elseif(zhuangnumber==gamernumber){for(i=1;i<6;i++){if(ab[i]!=100)this.ptb[i].Image=this.imageList1.Images[ab[i]];}this.label2.Text=zhuangnumber.ToString();MessageBox.Show("庄家赢了!开始下一局!");}else{for(i=1;i<6;i++){if(ab[i]!=100)this.ptb[i].Image=this.imageL
7、ist1.Images[ab[i]];}this.label2.Text=zhuangnumber.ToString();MessageBox.Show("你赢了!开始下一局!");}}privatevoid结束ToolStripMenuItem_Click(objectsender,EventArgse){Application.Exit();}//游戏规则在第二个Form上privatevoid游戏规则ToolStripMenuItem_Click(objectsender,EventArgse){Form2myform=newF
8、orm2();myform.Show();}//开始在panel上添加PictureBox并设置其属性,生成四张牌,各两张(庄家有一张隐藏)privatevoid开始ToolStripMenuItem_Click_1(o
此文档下载收益归作者所有