c猜数游戏代码Word文件下载.docx
- 文档编号:5798962
- 上传时间:2023-05-05
- 格式:DOCX
- 页数:18
- 大小:16.52KB
c猜数游戏代码Word文件下载.docx
《c猜数游戏代码Word文件下载.docx》由会员分享,可在线阅读,更多相关《c猜数游戏代码Word文件下载.docx(18页珍藏版)》请在冰点文库上搜索。
#region生成随机数
Randomrand=newRandom();
correctnumber[0]=rand.Next(0,9);
correctnumber[1]=rand.Next(0,9);
correctnumber[2]=rand.Next(0,9);
correctnumber[3]=rand.Next(0,9);
while(correctnumber[0]==correctnumber[1]||
correctnumber[0]==correctnumber[2]||
correctnumber[0]==correctnumber[3]
)
while(correctnumber[1]==correctnumber[0]||
correctnumber[1]==correctnumber[2]||
correctnumber[1]==correctnumber[3]
while(correctnumber[2]==correctnumber[0]||
correctnumber[2]==correctnumber[1]||
correctnumber[2]==correctnumber[3]
while(correctnumber[3]==correctnumber[1]||
correctnumber[3]==correctnumber[2]||
correctnumber[3]==correctnumber[0]
#endregion
textBox5.Text+=&
quot;
开始游戏...&
+&
\r\n&
;
提示信息...&
for(inti=0;
i&
lt;
correctnumber.Length;
i++)
textBox6.Text+=correctnumber[i].ToString();
_beginflag=true;
BeginButton.Enabled=false;
privatevoidGuessButton_Click(objectsender,EventArgse)
intallcorrectcount=0;
intnumbercorrectcount=0;
if(_beginflag==false)
MessageBox.Show(&
游戏尚未开始!
&
);
elseif(textBox1.Text==textBox2.Text||textBox1.Text==textBox3.Text||textBox1.Text==textBox4.Text||
textBox2.Text==textBox3.Text||textBox2.Text==textBox4.Text||
textBox3.Text==textBox4.Text)
请输入不重复的四个数字且不能为空!
textBox1.Text=&
textBox2.Text=&
textBox3.Text=&
textBox4.Text=&
elseif(textBox1.Text==&
||
textBox2.Text==&
textBox3.Text==&
textBox4.Text==&
各个数字均不能为空!
else
if(textBox1.Text==correctnumber[0].ToString()&
amp;
textBox2.Text==correctnumber[1].ToString()&
textBox3.Text==correctnumber[2].ToString()&
textBox4.Text==correctnumber[3].ToString())
恭喜你猜对了!
4;
if(textBox1.Text==correctnumber[i].ToString())
if(i==0)
allcorrectcount+=1;
numbercorrectcount+=1;
if(textBox2.Text==correctnumber[i].ToString())
if(i==1)
if(textBox3.Text==correctnumber[i].ToString())
if(i==2)
if(textBox4.Text==correctnumber[i].ToString())
if(i==3)
}
本次有&
+allcorrectcount+&
个数字和位置都正确,有&
+numbercorrectcount+&
个数字正确,位置不正确。
你还有&
+(9-_guesstimes)+&
次机会!
_guesstimes++;
if(allcorrectcount==4)
恭喜你,你使用了&
+_guesstimes+&
次就猜出来了!
privatevoidClearButton_Click(objectsender,EventArgse)
privatevoidTryAgainButton_Click(objectsender,EventArgse)
textBox5.Text=&
partialclassForm1
///&
summary&
gt;
///必需的设计器变量。
///&
/summary&
privateSystem.ComponentModel.IContainercomponents=null;
///清理所有正在使用的资源。
paramname=&
disposing&
如果应释放托管资源,为true;
否则为false。
/param&
protectedoverridevoidDispose(booldisposing)
if(disposing&
(components!
=null))
components.Dispose();
base.Dispose(disposing);
#regionWindows窗体设计器生成的代码
///设计器支持所需的方法-不要
///使用代码编辑器修改此方法的内容。
privatevoidInitializeComponent()
this.label1=newSystem.Windows.Forms.Label();
this.label2=newSystem.Windows.Forms.Label();
this.textBox1=newSystem.Windows.Forms.TextBox();
this.textBox2=newSystem.Windows.Forms.TextBox();
this.textBox3=newSystem.Windows.Forms.TextBox();
this.textBox4=newSystem.Windows.Forms.TextBox();
this.textBox5=newSystem.Windows.Forms.TextBox();
this.GuessButton=newSystem.Windows.Forms.Button();
this.ClearButton=newSystem.Windows.Forms.Button();
this.TryAgainButton=newSystem.Windows.Forms.Button();
this.BeginButton=newSystem.Windows.Forms.Button();
this.textBox6=newSystem.Windows.Forms.TextBox();
this.SuspendLayout();
//
//label1
this.label1.AutoSize=true;
this.label1.Font=newSystem.Drawing.Font(&
黑体&
21.75F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));
this.label1.ForeColor=System.Drawing.Color.Green;
this.label1.Location=newSystem.Drawing.Point(12,9);
this.label1.Name=&
label1&
this.label1.Size=newSystem.Drawing.Size(216,29);
this.label1.TabIndex=0;
this.label1.Text=&
数字猜猜猜游戏&
//label2
this.label2.AutoSize=true;
this.label2.Font=newSystem.Drawing.Font(&
宋体&
12F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));
this.label2.ForeColor=System.Drawing.Color.FromArgb(((int)(((byte)(0)))),((int)(((byte)(192)))),((int)(((byte)(0)))));
this.label2.Location=newSystem.Drawing.Point(12,79);
this.label2.Name=&
label2&
this.label2.Size=newSystem.Drawing.Size(216,48);
this.label2.TabIndex=1;
this.label2.Text=&
请在下面的输入框中输入一个\r\n包含数字0-9的不要重复的4位\r\n数:
//textBox1
//
this.textBox1.Location=newSystem.Drawing.Point(50,141);
this.textBox1.Name=&
textBox1&
this.textBox1.Size=newSystem.Drawing.Size(21,21);
this.textBox1.TabIndex=2;
//textBox2
this.textBox2.Location=newSystem.Drawing.Point(77,141);
this.textBox2.Name=&
textBox2&
this.textBox2.Size=newSystem.Drawing.Size(21,21);
this.textBox2.TabIndex=2;
//textBox3
this.textBox3.Location=newSystem.Drawing.Point(104,141);
this.textBox3.Name=&
textBox3&
this.textBox3.Size=newSystem.Drawing.Size(21,21);
this.textBox3.TabIndex=2;
//textBox4
this.textBox4.Location=newSystem.Drawing.Point(131,141);
this.textBox4.Name=&
textBox4&
this.textBox4.Size=newSystem.Drawing.Size(21,21);
this.textBox4.TabIndex=2;
//textBox5
this.textBox5.BackColor=System.Drawing.Color.FromArgb(((int)(((byte)(255)))),((int)(((byte)(224)))),((int)(((byte)(192)))));
this.textBox5.Font=newSystem.Drawing.Font(&
楷体&
10.5F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));
this.textBox5.ForeColor=System.Drawing.Color.Red;
this.textBox5.Location=newSystem.Drawing.Point(234,73);
this.textBox5.Multiline=true;
this.textBox5.Name=&
textBox5&
this.textBox5.Size=newSystem.Drawing.Size(497,289);
this.textBox5.TabIndex=3;
//GuessButton
this.GuessButton.Location=newSystem.Drawing.Point(32,221);
this.GuessButton.Name=&
GuessButton&
this.GuessButton.Size=newSystem.Drawing.Size(154,43);
this.GuessButton.TabIndex=4;
this.GuessButton.Text=&
猜一猜&
this.GuessButton.UseVisualStyleBackColor=true;
this.GuessButton.Click+=newSystem.EventHandler(this.GuessButton_Click);
//ClearButton
this.ClearButton.Location=newSystem.Drawing.Point(32,270);
this.ClearButton.Name=&
ClearButton&
this.ClearButton.Size=newSystem.Drawing.Size(154,43);
this.ClearButton.TabIndex=4;
this.ClearButton.Text=&
清空&
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 游戏 代码