WFM练手之猜数字小游戏

来源:互联网 编辑:wan玩得好手游小编更新:2024-03-20 05:24:47 人气:

form1.cs代码

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;
namespace czyx{ public partial class Form1 : Form { public Form1() { InitializeComponent(); }
int dL = 0; //设置一个难度变量, 0 为简单 ,1 为一般 ,2 为困难 int gCount = 3; //设置猜数字的次数变量 int rd = 0; int maxNum = 9; //设置一个最大数字 int gNum = 0; int count = 0;
public void 简单10个数三次ToolStripMenuItem_Click(object sender, EventArgs e) //默认级别 { dL = 0; lvText.Text = "简单难度"; gCount = 3; maxNum = 9; }
public void 一般50个数10次ToolStripMenuItem_Click(object sender, EventArgs e) { dL = 1; lvText.Text = "一般难度"; gCount = 5; maxNum = 49;
} public void 困难100个数20ToolStripMenuItem_Click(object sender, EventArgs e) { dL = 2; lvText.Text = "困难难度"; gCount = 5; maxNum = 99; }
public void intFace() { startBtn.Hide(); lvText.Hide(); mS.Hide(); tsText4.Hide(); } public void StartBtn_Click(object sender, EventArgs e) { startBtn.Hide(); lvText.Hide(); mS.Hide(); tsText4.Hide(); tsText1.Show(); tsText2.Show(); tsText3.Show(); button1.Show(); textBox1.Show(); tsText1.Text = "当前还剩猜数字次数:" + gCount + "次"; tsText2.Text = "请第1次输入你的数字"; switch (dL) { case 0: maxNum = 10; break; case 1: maxNum = 50; break; case 2: maxNum = 100; break; } Random rdom = new Random(); rd = rdom.Next(0, maxNum); }
public void TextBox1_TextChanged(object sender, EventArgs e) { try { gNum = int.Parse(textBox1.Text); if (gNum > maxNum) { MessageBox.Show("你输入的数字超出了猜数字的范围!","提示"); textBox1.Text = ""; } } catch { MessageBox.Show("请输入数字!", "提示"); textBox1.Text = ""; }
}
private void Button1_Click(object sender, EventArgs e) { count++; int TempCount = gCount - count; if (count { int countTemp = count + 1; tsText1.Text = "当前还剩猜数字次数:" + TempCount + "次"; tsText2.Text = "请第" + countTemp + "次输入你的数字";
if (gNum == rd) { tsText4.Show(); tsText4.Text = "恭喜你猜对了!"; tsText1.Hide(); tsText2.Hide(); tsText3.Hide(); button1.Hide(); textBox1.Hide(); reGameBtn.Show(); } else if (gNum > rd) { tsText3.Text = "你的数字大了!"; } else { tsText3.Text = "你的数字小了!"; } } if(count > gCount) { tsText1.Hide(); tsText2.Hide(); tsText3.Hide(); button1.Hide(); textBox1.Hide(); tsText4.Show(); tsText4.Text = "次数已经用完了,你失败了!!正确数字为"+gNum+"。"; reGameBtn.Show(); } }
private void ReGameBtn_Click(object sender, EventArgs e) { startBtn.Show(); lvText.Show(); mS.Show(); reGameBtn.Hide(); tsText4.Hide(); } }}

主要功能:可以设置猜数字游戏的难度,根据输入数字的判断提示来决定下一次输入数字的大小等。

界面简陋,望见谅。。。。


百度网盘:https://pan.百度.com/s/1RqkTH9-4LuJ1RpOhe-3vOg

欢迎玩家到【wan玩得好手游】查看最新变态版手游攻略,只需要在百度输入【wan玩得好手游】就可以浏览最新上线送满vip的变态手游攻略了,更多有关BT手游的攻略和资讯,敬请关注玩得好手游!

更多...

热门推荐

更多...

相关文章