以下是图片资料
以下是图片对应的名字,顺序要和图片一样
以下是界面设计
以下是源代码
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; using System.IO; using System.Data.SqlClient; namespace 猜猜看 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int model = new int(); // 判断是模式几 int[] sumHeroPhoto = new int[125]; // 记录imagelist1的数组,图片出现的总数 int[] modelTwoName = new int[125]; // 记录模式二随机出现的名字出现的总次数 String[] sumHeroNames=new String[125]; // 记录英雄的名字 int m,n ; // 记录两个错误名字选项的下标 int p1, p2; // 记录两个错误图片选项的下标 int t = 0; // 记录正确答案数组的下标 int t2 = 0; // 记录模式二正确答案数组的下标 int x1,x2,x3; // 三个选项的参数 int[] num = new int[3]; // 获得模式一 三个选项的名字数组的下标 int[] num2 = new int[3]; // 获得模式二 三个选项的名字数组的下标 bool re_elect=new bool(); // 坚持玩家是否重选了 float[] percent = new float[125]; // 认识率 float[] percent2 = new float[125]; //模式二认识率 int[] trueGuessNum = new int[125]; // 记录每张图片猜对的次数 int[] trueGuessPhoto = new int[125]; // 记录每个名字猜对的次数 int[] tp = new int[125]; // 控制高认识率英雄出现的概率 int[] tp2 = new int[125]; // 模式二控制高认识率英雄出现的概率 int m0, m1, m2, m3, m4, m5; // 显示认识程度变量 int n0, n1, n2, n3, n4, n5; // 模式二认识度变量 // 筛选英雄类型数组 int[] ci_keNum = new int[15]; int[] tan_keNum = new int[16]; int[] she_shouNum = new int[19]; int[] zhan_shiNum = new int[36]; int[] fa_shiNum = new int[28]; int[] fu_zhuNum = new int[11]; // 模式二筛选英雄类型数组 int[] ci_keNum2 = new int[15]; int[] tan_keNum2 = new int[16]; int[] she_shouNum2 = new int[19]; int[] zhan_shiNum2 = new int[36]; int[] fa_shiNum2 = new int[28]; int[] fu_zhuNum2 = new int[11]; private void Form1_Load(object sender, EventArgs e) { modelOneVisible(false); modelTwoVisible(false); textBox1.ReadOnly = true; // 文本框不可修改 // 将名字存入数组 getHeroName(); comboBox1.SelectedIndex=0; // 默认显示"全部" comboBox1.SelectionChangeCommitted += new System.EventHandler(this.scc_Click); } // 模式一按钮 private void modelOne_Click(object sender, EventArgs e) { model = 1; //模式一 // 连接数据库 String con = (@"server=LONG-PC\LONG;database=caicaikan;user id=sa;password=123456"); SqlConnection conn = new SqlConnection(con); // 读取数据库数据 conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from modelOne"; cmd.Connection = conn; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); DataTable dt = new DataTable(); dt = ds.Tables[0].Copy(); double[] a = new double[125]; for (int i = 0; i < 125; i++) { sumHeroPhoto[i] = (int)dt.Rows[i].ItemArray[0]; trueGuessNum[i] = (int)dt.Rows[i].ItemArray[1]; // 先将数据库中的float转换为c#中的double a[i] = (double)dt.Rows[i].ItemArray[2]; percent[i] = (float)a[i]; tp[i] = (int)dt.Rows[i].ItemArray[3]; } conn.Close(); conn.Dispose(); //释放内存空 // 显示模式一的控件 modelOneVisible(true); // 隐藏模式二相关控件 aRandomName.Visible = false; pictureBox2.Visible = false; pictureBox3.Visible = false; pictureBox4.Visible = false; randomHero(); // 得到随机图片 messageRecord(); // 显示英雄认识度信息 cleanRadio123(); // 清空radiobutton选项 getThreeChecked(); // 得到三个选项的值 continueGame.Visible = false; // 隐藏继续游戏按钮 correctResult.Visible = false; // 隐藏查看正确答案按钮 this.textBox1.Text = "请选择答案"; re_elect = false; // 默认没有重选 label4.Text = "选择答案查看"; } // 第一个选项按钮 private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (re_elect == true) //检测是否重选 { textBox1.Text = "只能选择一次"; } else { if (num[x1] == t) { textBox1.Text = "正确"; trueGuessNum[num[x1]]++; } else { textBox1.Text = "错误"; } } continueGame.Visible = true; // 显示继续游戏按钮 correctResult.Visible = true; // 查看正确答案按钮 re_elect = true; // 打开检查重选 //计算认识率 percent[t] = (float)trueGuessNum[t] / (sumHeroPhoto[t] + 2); label4.Text = percent[t].ToString("0.00%"); } // 第二个选项按钮 private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (re_elect == true) { textBox1.Text = "只能选择一次"; } else { if (num[x2] == t) { textBox1.Text = "正确"; trueGuessNum[num[x2]]++; } else { textBox1.Text = "错误"; } } continueGame.Visible = true; correctResult.Visible = true; re_elect = true; //计算认识率 percent[t] = (float)(trueGuessNum[t]) / (sumHeroPhoto[t] + 2); label4.Text = percent[t].ToString("0.00%"); } // 第三个选项按钮 private void radioButton3_CheckedChanged(object sender, EventArgs e) { if (re_elect == true) { textBox1.Text = "只能选择一次"; } else { if (num[x3] == t) { textBox1.Text = "正确"; trueGuessNum[num[x3]]++; } else { textBox1.Text = "错误"; } } continueGame.Visible = true; correctResult.Visible = true; re_elect = true; //计算认识率 percent[t] =(float) trueGuessNum[t] / (sumHeroPhoto[t] + 2); label4.Text = percent[t].ToString("0.00%"); } // 继续游戏按钮 private void continueGame_Click(object sender, EventArgs e) { this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; if (model == 1) { switch (comboBox1.SelectedIndex) { case 0: randomHero(); getThreeChecked(); cleanRadio123(); messageRecord(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; case 1: getCi_ke(); getThreeChecked(); cleanRadio123(); ci_keMessage(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; case 2: getTan_ke(); getThreeChecked(); cleanRadio123(); tan_keMessage(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; case 3: getShe_shou(); getThreeChecked(); cleanRadio123(); she_shouMessage(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; case 4: getZhan_shi(); getThreeChecked(); cleanRadio123(); zhan_shiMessage(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; case 5: getFa_shi(); getThreeChecked(); cleanRadio123(); fa_shiMessage(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; case 6: getFu_zhu(); getThreeChecked(); cleanRadio123(); fu_zhuMessage(); this.textBox1.Text = "请选择答案"; this.label4.Text = "选择答案查看"; re_elect = false; break; } } else { switch (comboBox1.SelectedIndex) { case 0: getName(); // 获得随机名字 getThreeChecked2(); // 获得3个选项 messageRecord2(); break; case 1: getCi_ke2(); getThreeChecked2(); // 获得3个选项 ci_keMessage2(); break; case 2: getTan_ke2(); getThreeChecked2(); tan_keMessage2(); break; case 3: getShe_shou2(); getThreeChecked2(); she_shouMessage2(); break; case 4: getZhan_shi2(); getThreeChecked2(); zhan_shiMessage2(); break; case 5: getFa_shi2(); getThreeChecked2(); fa_shiMessage2(); break; case 6: getFu_zhu2(); getThreeChecked2(); fu_zhuMessage2(); break; } } } // 随机产生三个选项 void getThreeChecked() { Random rn=new Random(); int p = randomHeroName1(); int q = randomHeroName2(); num[0] = t; num[1] = p; num[2] = q; // 生成第一个选项 x1 = rn.Next(3); radioButton1.Text = sumHeroNames[num[x1]].ToString(); // 生成第二个选项 x2 = rn.Next(3); while (x2 == x1) // 排除重复 { x2 = rn.Next(3); } radioButton2.Text = sumHeroNames[num[x2]].ToString(); // 生成第三个选项 x3 = rn.Next(3); while (x3 == x1 || x3 == x2) // 排除重复 { x3 = rn.Next(3); } radioButton3.Text = sumHeroNames[num[x3]].ToString(); } // 模式一可见性函数 void modelOneVisible(bool mv) { if (mv == true) { pictureBox1.Visible = true; label1.Visible = true; label2.Visible = true; label3.Visible = true; label4.Visible = true; radioButton1.Visible = true; radioButton2.Visible = true; radioButton3.Visible = true; textBox1.Visible = true; continueGame.Visible = false; correctResult.Visible = false; label6.Visible = true; label7.Visible = true; label8.Visible = true; label9.Visible = true; label10.Visible = true; label11.Visible = true; label12.Visible = true; label13.Visible = true; label14.Visible = true; label15.Visible = true; label16.Visible = true; label17.Visible = true; label18.Visible = true; label19.Visible = true; } else { pictureBox1.Visible = false; label1.Visible = false; label2.Visible = false; label3.Visible = false; label4.Visible = false; radioButton1.Visible = false; radioButton2.Visible = false; radioButton3.Visible = false; textBox1.Visible = false; continueGame.Visible = false; correctResult.Visible = false; label6.Visible = false; label7.Visible = false; label8.Visible = false; label9.Visible = false; label10.Visible = false; label11.Visible = false; label12.Visible = false; label13.Visible = false; label14.Visible = false; label15.Visible = false; label16.Visible = false; label17.Visible = false; label18.Visible = false; label19.Visible = false; } } // 清除三个选项的选择记录 void cleanRadio123() { radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; } // 随机显示英雄 void randomHero() { bool boo=new bool(); boo = true; Random ran = new Random(); t = ran.Next(125); while (t == m || t == n) { t = ran.Next(125); } imageList1.ImageSize = new Size(120, 120); // 判断英雄认识率是否大于 60% while (boo) { if (percent[t] >= 0.6) { // 英雄认识率高于99%时,出现的概率为原来的1/10 if (percent[t] >= 0.99) { m5++; if (tp[t] == 9) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在90%到99%之间,出现的概率为原来的1/5 if (percent[t] >= 0.9 && percent[t] < 0.99) { m4++; if (tp[t] == 4) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在80%到90%之间,出现的概率为原来的1/4 if (percent[t] >= 0.8 && percent[t] < 0.9) { m3++; if (tp[t] == 3) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在70%到80%之间,出现的概率为原来的1/3 if (percent[t] >= 0.7 && percent[t] < 0.8) { m2++; if (tp[t] == 2) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在60%到70%之间,出现的概率为原来的1/2 if (percent[t] >= 0.6 && percent[t] < 0.7) { m1++; if (tp[t] == 1) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } } //英雄认识率低于60%,出现的概率为1/125 else { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; boo = false; } } this.label3.Text = sumHeroPhoto[t].ToString(); } // 将名字存入sumHeroName[] void getHeroName() { StreamReader reader = new StreamReader(@"D:\c#\GuessFile\names.txt", Encoding.GetEncoding("gb2312")); String line = reader.ReadLine(); int i = 0; while (line != null) { sumHeroNames[i] = line; i++; line = reader.ReadLine(); } reader.Close(); } // 随机产生英雄名字1(错误答案) int randomHeroName1() { Random ran = new Random(); m = ran.Next(125); while (m == n || m == t) { m = ran.Next(125); } return m; } // 随机产生英雄名字2(错误答案) int randomHeroName2() { Random ran = new Random(); n = ran.Next(125); while(n == m||n==t) { n = ran.Next(125); } return n; } // 获取随机刺客 void getCi_ke() { // 获取随机刺客 int[] s = new int[] { 3, 4, 10, 12, 16, 22, 31, 33, 52, 87, 99, 107, 109, 115, 116 }; for (int i = 0; i < 15; i++) { ci_keNum[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(15); t = ci_keNum[c]; imageList1.ImageSize = new Size(120, 120); pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); } // 获取随机坦克 void getTan_ke() { // 获取随机坦克 int[] s = new int[] { 18, 55, 56, 65, 66, 67, 69, 75, 78, 80, 81, 84, 91, 96, 108, 121 }; for (int i = 0; i < 16; i++) { tan_keNum[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(16); t = tan_keNum[c]; imageList1.ImageSize = new Size(120, 120); pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); } // 获取随机射手 void getShe_shou() { // 获取随机射手 int[] s = new int[] { 1, 6, 13, 20, 24, 29, 35, 59, 70, 74, 79, 82, 85, 89, 94, 98, 113, 114, 118 }; for (int i = 0; i < 19; i++) { she_shouNum[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(19); t = she_shouNum[c]; imageList1.ImageSize = new Size(120, 120); pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); } // 获取随机战士 void getZhan_shi() { // 获取随机战士 int[] s = new int[] {2,15,17,19,25,30,34,38,40,42,43,44, 47,48,49,53,54,58,60,61,62,68,71,72, 77,83,88,90,92,97,100,101,106,119,120,124}; for (int i = 0; i < 36; i++) { zhan_shiNum[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(36); t = zhan_shiNum[c]; imageList1.ImageSize = new Size(120, 120); pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); } // 获取随机法师 void getFa_shi() { // 获取随机法师 int[] s = new int[] {0,7,8,9,11,14,21,23,28,32,36,41, 45,46,50,51,57,63,64,76,93,95,103,105, 110,111,117,122}; for (int i = 0; i < 28; i++) { fa_shiNum[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(28); t = fa_shiNum[c]; imageList1.ImageSize = new Size(120, 120); pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); } // 获取随机辅助 void getFu_zhu() { // 获取随机战士 int[] s = new int[] { 5, 26, 27, 37, 39, 73, 86, 102, 104, 112, 123 }; for (int i = 0; i < 11; i++) { fu_zhuNum[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(11); t = fu_zhuNum[c]; imageList1.ImageSize = new Size(120, 120); pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); } // 全部信息记录 void messageRecord() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "125".ToString(); // 总英雄 for (int i = 0; i < 125; i++) { // 初认识 if (sumHeroPhoto[i] != 0) { m0++; } // 较熟悉 if (percent[i] >= 0.6 && percent[i] < 0.7) { m1++; } // 已认识 if (percent[i] >= 0.7 && percent[i] < 0.8) { m2++; } // 很熟悉 if (percent[i] >= 0.8 && percent[i] < 0.9) { m3++; } // 完全熟悉 if (percent[i] >= 0.9 && percent[i] < 0.99) { m4++; } // 一眼辨认 if (percent[i] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 刺客信息 void ci_keMessage() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "15".ToString(); // 总英雄 for (int i = 0; i < 15; i++) { // 初认识 if (sumHeroPhoto[ci_keNum[i]] != 0) { m0++; } // 较熟悉 if (percent[ci_keNum[i]] >= 0.6 && percent[ci_keNum[i]] < 0.7) { m1++; } // 已认识 if (percent[ci_keNum[i]] >= 0.7 && percent[ci_keNum[i]] < 0.8) { m2++; } // 很熟悉 if (percent[ci_keNum[i]] >= 0.8 && percent[ci_keNum[i]] < 0.9) { m3++; } // 完全熟悉 if (percent[ci_keNum[i]] >= 0.9 && percent[ci_keNum[i]] < 0.99) { m4++; } // 一眼辨认 if (percent[ci_keNum[i]] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 坦克信息 void tan_keMessage() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "16".ToString(); // 总英雄 for (int i = 0; i < 16; i++) { // 初认识 if (sumHeroPhoto[tan_keNum[i]] != 0) { m0++; } // 较熟悉 if (percent[tan_keNum[i]] >= 0.6 && percent[tan_keNum[i]] < 0.7) { m1++; } // 已认识 if (percent[tan_keNum[i]] >= 0.7 && percent[tan_keNum[i]] < 0.8) { m2++; } // 很熟悉 if (percent[tan_keNum[i]] >= 0.8 && percent[tan_keNum[i]] < 0.9) { m3++; } // 完全熟悉 if (percent[tan_keNum[i]] >= 0.9 && percent[tan_keNum[i]] < 0.99) { m4++; } // 一眼辨认 if (percent[tan_keNum[i]] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 射手信息 void she_shouMessage() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "19".ToString(); // 总英雄 for (int i = 0; i < 19; i++) { // 初认识 if (sumHeroPhoto[she_shouNum[i]] != 0) { m0++; } // 较熟悉 if (percent[she_shouNum[i]] >= 0.6 && percent[she_shouNum[i]] < 0.7) { m1++; } // 已认识 if (percent[she_shouNum[i]] >= 0.7 && percent[she_shouNum[i]] < 0.8) { m2++; } // 很熟悉 if (percent[she_shouNum[i]] >= 0.8 && percent[she_shouNum[i]] < 0.9) { m3++; } // 完全熟悉 if (percent[she_shouNum[i]] >= 0.9 && percent[she_shouNum[i]] < 0.99) { m4++; } // 一眼辨认 if (percent[she_shouNum[i]] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 战士信息 void zhan_shiMessage() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "36".ToString(); // 总英雄 for (int i = 0; i < 36; i++) { // 初认识 if (sumHeroPhoto[zhan_shiNum[i]] != 0) { m0++; } // 较熟悉 if (percent[zhan_shiNum[i]] >= 0.6 && percent[zhan_shiNum[i]] < 0.7) { m1++; } // 已认识 if (percent[zhan_shiNum[i]] >= 0.7 && percent[zhan_shiNum[i]] < 0.8) { m2++; } // 很熟悉 if (percent[zhan_shiNum[i]] >= 0.8 && percent[zhan_shiNum[i]] < 0.9) { m3++; } // 完全熟悉 if (percent[zhan_shiNum[i]] >= 0.9 && percent[zhan_shiNum[i]] < 0.99) { m4++; } // 一眼辨认 if (percent[zhan_shiNum[i]] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 法师信息 void fa_shiMessage() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "28".ToString(); // 总英雄 for (int i = 0; i < 28; i++) { // 初认识 if (sumHeroPhoto[fa_shiNum[i]] != 0) { m0++; } // 较熟悉 if (percent[fa_shiNum[i]] >= 0.6 && percent[fa_shiNum[i]] < 0.7) { m1++; } // 已认识 if (percent[fa_shiNum[i]] >= 0.7 && percent[fa_shiNum[i]] < 0.8) { m2++; } // 很熟悉 if (percent[fa_shiNum[i]] >= 0.8 && percent[fa_shiNum[i]] < 0.9) { m3++; } // 完全熟悉 if (percent[fa_shiNum[i]] >= 0.9 && percent[fa_shiNum[i]] < 0.99) { m4++; } // 一眼辨认 if (percent[fa_shiNum[i]] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 辅助信息 void fu_zhuMessage() { // 清空数据 m0 = 0; m1 = 0; m2 = 0; m3 = 0; m4 = 0; m5 = 0; label13.Text = "11".ToString(); // 总英雄 for (int i = 0; i < 11; i++) { // 初认识 if (sumHeroPhoto[fu_zhuNum[i]] != 0) { m0++; } // 较熟悉 if (percent[fu_zhuNum[i]] >= 0.6 && percent[fu_zhuNum[i]] < 0.7) { m1++; } // 已认识 if (percent[fu_zhuNum[i]] >= 0.7 && percent[fu_zhuNum[i]] < 0.8) { m2++; } // 很熟悉 if (percent[fu_zhuNum[i]] >= 0.8 && percent[fu_zhuNum[i]] < 0.9) { m3++; } // 完全熟悉 if (percent[fu_zhuNum[i]] >= 0.9 && percent[fu_zhuNum[i]] < 0.99) { m4++; } // 一眼辨认 if (percent[fu_zhuNum[i]] >= 0.99) { m5++; } } label14.Text = m0.ToString(); label15.Text = m1.ToString(); label16.Text = m2.ToString(); label17.Text = m3.ToString(); label18.Text = m4.ToString(); label19.Text = m5.ToString(); } // 退出游戏按钮 private void exitGame_Click(object sender, EventArgs e) { // 连接数据库 String con = (@"server=LONG-PC\LONG;database=caicaikan;user id=sa;password=123456"); SqlConnection conn = new SqlConnection(con); // 定义对象,用于sql语句将数据写入数据库 StringBuilder sqlstr = new StringBuilder(); conn.Open(); if (model == 1) { // 清空数据表原数据 SqlCommand sc = new SqlCommand(); sc.CommandText = ("truncate table modelOne"); sc.Connection = conn; sc.ExecuteNonQuery(); for (int i = 0; i < 125; i++) { sqlstr.Append("insert into modelOne(sumHeroPhoto,trueGuessNum,[percent],tp)"); sqlstr.Append("values"); sqlstr.Append("('" + sumHeroPhoto[i] + "','" + trueGuessNum[i] + "','" + percent[i] + "','" + tp[i] + "')"); using (SqlCommand cmd = new SqlCommand(sqlstr.ToString(), conn)) //定义连接命令 { //cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery();//执行sql语句 } sqlstr.Clear(); } } else { // 清空数据表原数据 SqlCommand sc2 = new SqlCommand(); sc2.CommandText = ("truncate table modelTwo"); sc2.Connection = conn; sc2.ExecuteNonQuery(); for (int i = 0; i < 125; i++) { sqlstr.Append("insert into modelTwo(modelTwoName,trueGuessPhoto,percent2,tp2)"); sqlstr.Append("values"); sqlstr.Append("('" + modelTwoName[i] + "','" + trueGuessPhoto[i] + "','" + percent2[i] + "','" + tp2[i] + "')"); using (SqlCommand cmd2 = new SqlCommand(sqlstr.ToString(), conn)) //定义连接命令 { //cmd.CommandType = CommandType.StoredProcedure; cmd2.ExecuteNonQuery();//执行sql语句 } sqlstr.Clear(); } } conn.Close(); conn.Dispose(); //释放内存空 this.Close(); } // 查看正确答案按钮 private void correctResult_Click(object sender, EventArgs e) { if (model == 1) { if (num[x1] == t) radioButton1.Checked = true; if (num[x2] == t) radioButton2.Checked = true; if (num[x3] == t) radioButton3.Checked = true; textBox1.Text = "该英雄的名字为:"; } else { if (num2[x1] == t2) { // 第一张边框设置为卡其色 Graphics g = Graphics.FromHwnd(this.pictureBox2.Handle); PaintEventArgs a = new PaintEventArgs(g, this.pictureBox2.ClientRectangle); this.pictureBox2_Paint(this.pictureBox2, a); g.Dispose(); delay(100); pictureBox2.Image = imageList1.Images[num2[x1]]; } if (num2[x2] == t2) { Graphics g = Graphics.FromHwnd(this.pictureBox3.Handle); PaintEventArgs a = new PaintEventArgs(g, this.pictureBox3.ClientRectangle); this.pictureBox3_Paint(this.pictureBox3, a); g.Dispose(); delay(100); pictureBox3.Image = imageList1.Images[num2[x2]]; } if (num2[x3] == t2) { Graphics g = Graphics.FromHwnd(this.pictureBox4.Handle); PaintEventArgs a = new PaintEventArgs(g, this.pictureBox4.ClientRectangle); this.pictureBox4_Paint(this.pictureBox4, a); g.Dispose(); delay(100); pictureBox4.Image = imageList1.Images[num2[x3]]; } textBox1.Text = "该英雄的头像为:"; } } // 晒选英雄类型按钮 private void scc_Click(object sender, EventArgs e) { continueGame.Visible = false; correctResult.Visible = false; this.textBox1.Text = "请选择答案"; re_elect = false; this.label4.Text = "选择答案查看"; //筛选 if (model == 1) { switch (comboBox1.SelectedIndex) { case 0: randomHero(); getThreeChecked(); cleanRadio123(); messageRecord(); break; case 1: getCi_ke(); getThreeChecked(); cleanRadio123(); ci_keMessage(); break; case 2: getTan_ke(); getThreeChecked(); cleanRadio123(); tan_keMessage(); break; case 3: getShe_shou(); getThreeChecked(); cleanRadio123(); she_shouMessage(); break; case 4: getZhan_shi(); getThreeChecked(); cleanRadio123(); zhan_shiMessage(); break; case 5: getFa_shi(); getThreeChecked(); cleanRadio123(); fa_shiMessage(); break; case 6: getFu_zhu(); getThreeChecked(); cleanRadio123(); fu_zhuMessage(); break; } } else { switch (comboBox1.SelectedIndex) { case 0: getName(); // 获得随机名字 getThreeChecked2(); // 获得3个选项 messageRecord2(); break; case 1: getCi_ke2(); getThreeChecked2(); // 获得3个选项 ci_keMessage2(); break; case 2: getTan_ke2(); getThreeChecked2(); tan_keMessage2(); break; case 3: getShe_shou2(); getThreeChecked2(); she_shouMessage2(); break; case 4: getZhan_shi2(); getThreeChecked2(); zhan_shiMessage2(); break; case 5: getFa_shi2(); getThreeChecked2(); fa_shiMessage2(); break; case 6: getFu_zhu2(); getThreeChecked2(); fu_zhuMessage2(); break; } } } /**************************** 模式二 ********************************/ // 模式二按钮 private void moderTwo_Click(object sender, EventArgs e) { model = 2; // 连接数据库 String con = (@"server=LONG-PC\LONG;database=caicaikan;user id=sa;password=123456"); SqlConnection conn = new SqlConnection(con); // 读取数据库数据 conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from modelTwo"; cmd.Connection = conn; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); DataTable dt = new DataTable(); dt = ds.Tables[0].Copy(); double[] a = new double[125]; for (int i = 0; i < 125; i++) { modelTwoName[i] = (int)dt.Rows[i].ItemArray[0]; trueGuessPhoto[i] = (int)dt.Rows[i].ItemArray[1]; // 先将数据库中的float转换为c#中的double a[i] = (double)dt.Rows[i].ItemArray[2]; percent2[i] = (float)a[i]; tp2[i] = (int)dt.Rows[i].ItemArray[3]; } conn.Close(); conn.Dispose(); //释放内存空 // 显示模式二控件,同时隐藏模式一相关按钮 modelTwoVisible(true); pictureBox1.Visible = false; radioButton1.Visible = false; radioButton2.Visible = false; radioButton3.Visible = false; getName(); // 获得随机名字 getThreeChecked2(); // 获得3个选项 this.textBox1.Text = "请选择答案"; re_elect = false; // 默认没有重选 label4.Text = "选择答案查看"; messageRecord2(); // 显示模式二进度 } // 模式二可见性函数 void modelTwoVisible(bool mv) { if (mv == true) { pictureBox2.Visible = true; pictureBox3.Visible = true; pictureBox4.Visible = true; textBox1.Visible = true; continueGame.Visible = false; correctResult.Visible = false; label1.Visible = true; label2.Visible = true; label3.Visible = true; label4.Visible = true; label6.Visible = true; label7.Visible = true; label8.Visible = true; label9.Visible = true; label10.Visible = true; label11.Visible = true; label12.Visible = true; label13.Visible = true; label14.Visible = true; label15.Visible = true; label16.Visible = true; label17.Visible = true; label18.Visible = true; label19.Visible = true; aRandomName.Visible = true; } else { pictureBox2.Visible = false; pictureBox3.Visible = false; pictureBox4.Visible = false; textBox1.Visible = false; continueGame.Visible = false; correctResult.Visible = false; label1.Visible = false; label2.Visible = false; label3.Visible = false; label4.Visible = false; label6.Visible = false; label7.Visible = false; label8.Visible = false; label9.Visible = false; label10.Visible = false; label11.Visible = false; label12.Visible = false; label13.Visible = false; label14.Visible = false; label15.Visible = false; label16.Visible = false; label17.Visible = false; label18.Visible = false; label19.Visible = false; aRandomName.Visible = false; } } // 随机得到一个名字 void getName() { bool boo = new bool(); boo = true; Random ran = new Random(); t2 = ran.Next(125); while (t2 == p1 || t2 == p2) { t2 = ran.Next(125); } // 判断英雄认识率是否大于 60% while (boo) { if (percent2[t2] >= 0.6) { // 英雄认识率高于99%时,出现的概率为原来的1/10 if (percent2[t2] >= 0.99) { n5++; if (tp2[t2] == 9) { pictureBox1.Image = imageList1.Images[t2]; sumHeroPhoto[t2]++; this.label3.Text = sumHeroPhoto[t2].ToString(); tp2[t2] = 0; boo = false; } else { tp2[t2]++; t2 = ran.Next(125); } } // 英雄认识率在90%到99%之间,出现的概率为原来的1/5 if (percent2[t2] >= 0.9 && percent2[t2] < 0.99) { n4++; if (tp2[t2] == 4) { pictureBox1.Image = imageList1.Images[t2]; sumHeroPhoto[t2]++; this.label3.Text = sumHeroPhoto[t2].ToString(); tp2[t2] = 0; boo = false; } else { tp2[t2]++; t2 = ran.Next(125); } } // 英雄认识率在80%到90%之间,出现的概率为原来的1/4 if (percent2[t2] >= 0.8 && percent2[t2] < 0.9) { n3++; if (tp2[t2] == 3) { pictureBox1.Image = imageList1.Images[t2]; sumHeroPhoto[t2]++; this.label3.Text = sumHeroPhoto[t2].ToString(); tp2[t2] = 0; boo = false; } else { tp2[t2]++; t2 = ran.Next(125); } } // 英雄认识率在70%到80%之间,出现的概率为原来的1/3 if (percent2[t2] >= 0.7 && percent2[t2] < 0.8) { n2++; if (tp2[t2] == 2) { pictureBox1.Image = imageList1.Images[t2]; sumHeroPhoto[t2]++; this.label3.Text = sumHeroPhoto[t2].ToString(); tp2[t2] = 0; boo = false; } else { tp2[t2]++; t2 = ran.Next(125); } } // 英雄认识率在60%到70%之间,出现的概率为原来的1/2 if (percent2[t2] >= 0.6 && percent2[t2] < 0.7) { n1++; if (tp2[t2] == 1) { pictureBox1.Image = imageList1.Images[t2]; sumHeroPhoto[t2]++; this.label3.Text = sumHeroPhoto[t2].ToString(); tp2[t2] = 0; boo = false; } else { tp2[t2]++; t2 = ran.Next(125); } } } //英雄认识率低于60%,出现的概率为1/125 else { aRandomName.Text=sumHeroNames[t2].ToString(); modelTwoName[t2]++; boo = false; } } this.label3.Text = modelTwoName[t2].ToString(); } // 获得一张随机图片1(干扰图片) int randomPhoto1() { Random ran = new Random(); p1 = ran.Next(125); while (p1 == p2 || p1 == t2) { p1 = ran.Next(125); } return p1; } // 获得一张随机图片2(干扰图片) int randomPhoto2() { Random ran = new Random(); p2 = ran.Next(125); while (p2 == p1 || p2 == t2) { p2 = ran.Next(125); } return p2; } // 随机显示三个选项 void getThreeChecked2() { Random rn = new Random(); int p = randomPhoto1(); int q = randomPhoto2(); num2[0] = t2; num2[1] = p; num2[2] = q; // 生成第一个选项 x1 = rn.Next(3); pictureBox2.Image = imageList1.Images[num2[x1]]; // 生成第二个选项 x2 = rn.Next(3); while (x2 == x1) // 排除重复 { x2 = rn.Next(3); } pictureBox3.Image = imageList1.Images[num2[x2]]; // 生成第三个选项 x3 = rn.Next(3); while (x3 == x1 || x3 == x2) // 排除重复 { x3 = rn.Next(3); } pictureBox4.Image = imageList1.Images[num2[x3]]; } // 点击第一图片触发的事件 private void pictureBox2_Click(object sender, EventArgs e) { // 第一张边框设置为卡其色 Graphics g = Graphics.FromHwnd(this.pictureBox2.Handle); PaintEventArgs a = new PaintEventArgs(g, this.pictureBox2.ClientRectangle); this.pictureBox2_Paint(this.pictureBox2, a); g.Dispose(); delay(100); pictureBox2.Image = imageList1.Images[num2[x1]]; // 实现模式一选择答案功能 if (re_elect == true) //检测是否重选 { textBox1.Text = "只能选择一次"; } else { if (num2[x1] == t2) { textBox1.Text = "正确"; trueGuessPhoto[num2[x1]]++; } else { textBox1.Text = "错误"; } } continueGame.Visible = true; // 显示继续游戏按钮 correctResult.Visible = true; // 查看正确答案按钮 re_elect = true; // 打开检查重选 //计算认识率 percent2[t2] = (float)trueGuessPhoto[t2] / (modelTwoName[t2] + 2); label4.Text = percent2[t2].ToString("0.00%"); } // 点击第二张图片触发的事件 private void pictureBox3_Click(object sender, EventArgs e) { Graphics g = Graphics.FromHwnd(this.pictureBox3.Handle); PaintEventArgs a = new PaintEventArgs(g, this.pictureBox3.ClientRectangle); this.pictureBox3_Paint(this.pictureBox3, a); g.Dispose(); delay(100); pictureBox3.Image = imageList1.Images[num2[x2]]; // 实现模式一选择答案功能 if (re_elect == true) { textBox1.Text = "只能选择一次"; } else { if (num2[x2] == t2) { textBox1.Text = "正确"; trueGuessPhoto[num2[x2]]++; } else { textBox1.Text = "错误"; } } continueGame.Visible = true; correctResult.Visible = true; re_elect = true; //计算认识率 percent2[t2] = (float)(trueGuessPhoto[t2]) / (modelTwoName[t2] + 2); label4.Text = percent2[t2].ToString("0.00%"); } // 点击第三张图片触发事件 private void pictureBox4_Click(object sender, EventArgs e) { Graphics g = Graphics.FromHwnd(this.pictureBox4.Handle); PaintEventArgs a = new PaintEventArgs(g, this.pictureBox4.ClientRectangle); this.pictureBox4_Paint(this.pictureBox4, a); g.Dispose(); delay(100); pictureBox4.Image = imageList1.Images[num2[x3]]; // 实现模式一选择答案功能 if (re_elect == true) { textBox1.Text = "只能选择一次"; } else { if (num2[x3] == t2) { textBox1.Text = "正确"; trueGuessPhoto[num2[x3]]++; } else { textBox1.Text = "错误"; } } continueGame.Visible = true; correctResult.Visible = true; re_elect = true; //计算认识率 percent2[t2] = (float)trueGuessPhoto[t2] / (modelTwoName[t2] + 2); label4.Text = percent2[t2].ToString("0.00%"); } // 第一张图片画边框(卡其色) private void pictureBox2_Paint(object sender, PaintEventArgs e) { PictureBox p = (PictureBox)sender; Pen pp = new Pen(Color.Khaki); e.Graphics.DrawRectangle(pp, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.X + e.ClipRectangle.Width - 1, e.ClipRectangle.Y + e.ClipRectangle.Height - 1); } // 第二张图片画边框(卡其色) private void pictureBox3_Paint(object sender, PaintEventArgs e) { PictureBox p = (PictureBox)sender; Pen pp = new Pen(Color.Khaki); e.Graphics.DrawRectangle(pp, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.X + e.ClipRectangle.Width - 1, e.ClipRectangle.Y + e.ClipRectangle.Height - 1); } // 第三张图片画边框(卡其色) private void pictureBox4_Paint(object sender, PaintEventArgs e) { PictureBox p = (PictureBox)sender; Pen pp = new Pen(Color.Khaki); e.Graphics.DrawRectangle(pp, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.X + e.ClipRectangle.Width - 1, e.ClipRectangle.Y + e.ClipRectangle.Height - 1); } // 全部信息记录 void messageRecord2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "125".ToString(); // 总英雄 for (int i = 0; i < 125; i++) { // 初认识 if (trueGuessPhoto[i] != 0) { n0++; } // 较熟悉 if (percent2[i] >= 0.6 && percent2[i] < 0.7) { n1++; } // 已认识 if (percent2[i] >= 0.7 && percent2[i] < 0.8) { n2++; } // 很熟悉 if (percent2[i] >= 0.8 && percent2[i] < 0.9) { n3++; } // 完全熟悉 if (percent2[i] >= 0.9 && percent2[i] < 0.99) { n4++; } // 一眼辨认 if (percent2[i] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 获取随机刺客 void getCi_ke2() { // 获取随机刺客 int[] s = new int[] { 3, 4, 10, 12, 16, 22, 31, 33, 52, 87, 99, 107, 109, 115, 116 }; for (int i = 0; i < 15; i++) { ci_keNum2[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(15); t2 = ci_keNum2[c]; aRandomName.Text=sumHeroNames[t2]; modelTwoName[t2]++; this.label3.Text = modelTwoName[t2].ToString(); } // 获取随机坦克 void getTan_ke2() { // 获取随机坦克 int[] s = new int[] { 18, 55, 56, 65, 66, 67, 69, 75, 78, 80, 81, 84, 91, 96, 108, 121 }; for (int i = 0; i < 16; i++) { tan_keNum2[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(16); t2 = tan_keNum2[c]; aRandomName.Text = sumHeroNames[t2]; modelTwoName[t2]++; this.label3.Text = modelTwoName[t2].ToString(); } // 获取随机射手 void getShe_shou2() { // 获取随机射手 int[] s = new int[] { 1, 6, 13, 20, 24, 29, 35, 59, 70, 74, 79, 82, 85, 89, 94, 98, 113, 114, 118 }; for (int i = 0; i < 19; i++) { she_shouNum2[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(19); t2 = she_shouNum2[c]; aRandomName.Text = sumHeroNames[t2]; modelTwoName[t2]++; this.label3.Text = modelTwoName[t2].ToString(); } // 获取随机战士 void getZhan_shi2() { // 获取随机战士 int[] s = new int[] {2,15,17,19,25,30,34,38,40,42,43,44, 47,48,49,53,54,58,60,61,62,68,71,72, 77,83,88,90,92,97,100,101,106,119,120,124}; for (int i = 0; i < 36; i++) { zhan_shiNum2[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(36); t2 = zhan_shiNum2[c]; aRandomName.Text = sumHeroNames[t2]; modelTwoName[t2]++; this.label3.Text = modelTwoName[t2].ToString(); } // 获取随机法师 void getFa_shi2() { // 获取随机法师 int[] s = new int[] {0,7,8,9,11,14,21,23,28,32,36,41, 45,46,50,51,57,63,64,76,93,95,103,105, 110,111,117,122}; for (int i = 0; i < 28; i++) { fa_shiNum2[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(28); t2 = fa_shiNum2[c]; aRandomName.Text = sumHeroNames[t2]; modelTwoName[t2]++; this.label3.Text = modelTwoName[t2].ToString(); } // 获取随机辅助 void getFu_zhu2() { // 获取随机战士 int[] s = new int[] { 5, 26, 27, 37, 39, 73, 86, 102, 104, 112, 123 }; for (int i = 0; i < 11; i++) { fu_zhuNum2[i] = s[i]; } int c = new int(); Random ran = new Random(); c = ran.Next(11); t2 = fu_zhuNum2[c]; aRandomName.Text = sumHeroNames[t2]; modelTwoName[t2]++; this.label3.Text = modelTwoName[t2].ToString(); } // 刺客信息 void ci_keMessage2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "15".ToString(); // 总英雄 for (int i = 0; i < 15; i++) { // 初认识 if (modelTwoName[ci_keNum2[i]] != 0) { n0++; } // 较熟悉 if (percent2[ci_keNum2[i]] >= 0.6 && percent2[ci_keNum2[i]] < 0.7) { n1++; } // 已认识 if (percent2[ci_keNum2[i]] >= 0.7 && percent2[ci_keNum2[i]] < 0.8) { n2++; } // 很熟悉 if (percent2[ci_keNum2[i]] >= 0.8 && percent2[ci_keNum2[i]] < 0.9) { n3++; } // 完全熟悉 if (percent2[ci_keNum2[i]] >= 0.9 && percent2[ci_keNum2[i]] < 0.99) { n4++; } // 一眼辨认 if (percent2[ci_keNum2[i]] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 坦克信息 void tan_keMessage2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "16".ToString(); // 总英雄 for (int i = 0; i < 16; i++) { // 初认识 if (modelTwoName[tan_keNum2[i]] != 0) { n0++; } // 较熟悉 if (percent2[tan_keNum2[i]] >= 0.6 && percent2[tan_keNum2[i]] < 0.7) { n1++; } // 已认识 if (percent2[tan_keNum2[i]] >= 0.7 && percent2[tan_keNum2[i]] < 0.8) { n2++; } // 很熟悉 if (percent2[tan_keNum2[i]] >= 0.8 && percent2[tan_keNum2[i]] < 0.9) { n3++; } // 完全熟悉 if (percent2[tan_keNum2[i]] >= 0.9 && percent2[tan_keNum2[i]] < 0.99) { n4++; } // 一眼辨认 if (percent2[tan_keNum2[i]] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 射手信息 void she_shouMessage2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "19".ToString(); // 总英雄 for (int i = 0; i < 19; i++) { // 初认识 if (modelTwoName[she_shouNum2[i]] != 0) { n0++; } // 较熟悉 if (percent2[she_shouNum2[i]] >= 0.6 && percent2[she_shouNum2[i]] < 0.7) { n1++; } // 已认识 if (percent2[she_shouNum2[i]] >= 0.7 && percent2[she_shouNum2[i]] < 0.8) { n2++; } // 很熟悉 if (percent2[she_shouNum2[i]] >= 0.8 && percent2[she_shouNum2[i]] < 0.9) { n3++; } // 完全熟悉 if (percent2[she_shouNum2[i]] >= 0.9 && percent2[she_shouNum2[i]] < 0.99) { n4++; } // 一眼辨认 if (percent2[she_shouNum2[i]] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 战士信息 void zhan_shiMessage2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "36".ToString(); // 总英雄 for (int i = 0; i < 36; i++) { // 初认识 if (modelTwoName[zhan_shiNum2[i]] != 0) { n0++; } // 较熟悉 if (percent2[zhan_shiNum2[i]] >= 0.6 && percent2[zhan_shiNum2[i]] < 0.7) { n1++; } // 已认识 if (percent2[zhan_shiNum2[i]] >= 0.7 && percent2[zhan_shiNum2[i]] < 0.8) { n2++; } // 很熟悉 if (percent2[zhan_shiNum2[i]] >= 0.8 && percent2[zhan_shiNum2[i]] < 0.9) { n3++; } // 完全熟悉 if (percent2[zhan_shiNum2[i]] >= 0.9 && percent2[zhan_shiNum2[i]] < 0.99) { n4++; } // 一眼辨认 if (percent2[zhan_shiNum2[i]] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 法师信息 void fa_shiMessage2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "28".ToString(); // 总英雄 for (int i = 0; i < 28; i++) { // 初认识 if (modelTwoName[fa_shiNum2[i]] != 0) { n0++; } // 较熟悉 if (percent2[fa_shiNum2[i]] >= 0.6 && percent2[fa_shiNum2[i]] < 0.7) { n1++; } // 已认识 if (percent2[fa_shiNum2[i]] >= 0.7 && percent2[fa_shiNum2[i]] < 0.8) { n2++; } // 很熟悉 if (percent2[fa_shiNum2[i]] >= 0.8 && percent2[fa_shiNum2[i]] < 0.9) { n3++; } // 完全熟悉 if (percent2[fa_shiNum2[i]] >= 0.9 && percent2[fa_shiNum2[i]] < 0.99) { n4++; } // 一眼辨认 if (percent2[fa_shiNum2[i]] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 辅助信息 void fu_zhuMessage2() { // 清空数据 n0 = 0; n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; label13.Text = "11".ToString(); // 总英雄 for (int i = 0; i < 11; i++) { // 初认识 if (modelTwoName[fu_zhuNum2[i]] != 0) { n0++; } // 较熟悉 if (percent2[fu_zhuNum2[i]] >= 0.6 && percent2[fu_zhuNum2[i]] < 0.7) { n1++; } // 已认识 if (percent2[fu_zhuNum2[i]] >= 0.7 && percent2[fu_zhuNum2[i]] < 0.8) { n2++; } // 很熟悉 if (percent2[fu_zhuNum2[i]] >= 0.8 && percent2[fu_zhuNum2[i]] < 0.9) { n3++; } // 完全熟悉 if (percent2[fu_zhuNum2[i]] >= 0.9 && percent2[fu_zhuNum2[i]] < 0.99) { n4++; } // 一眼辨认 if (percent2[fu_zhuNum2[i]] >= 0.99) { n5++; } } label14.Text = n0.ToString(); label15.Text = n1.ToString(); label16.Text = n2.ToString(); label17.Text = n3.ToString(); label18.Text = n4.ToString(); label19.Text = n5.ToString(); } // 延时函数 private void delay(int iInterval) { DateTime now = DateTime.Now; while (now.AddMilliseconds(iInterval) > DateTime.Now) { } return; } } }
用 modelOne保存模式一的数据,modelTwo保存模式二的数据
以下是模式一,功能展示
模式二功能展示
算法解析:
bool boo=new bool(); boo = true; Random ran = new Random(); t = ran.Next(125); while (t == m || t == n) { t = ran.Next(125); } imageList1.ImageSize = new Size(120, 120); // 判断英雄认识率是否大于 60% while (boo) { if (percent[t] >= 0.6) { // 英雄认识率高于99%时,出现的概率为原来的1/10 if (percent[t] >= 0.99) { m5++; if (tp[t] == 9) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在90%到99%之间,出现的概率为原来的1/5 if (percent[t] >= 0.9 && percent[t] < 0.99) { m4++; if (tp[t] == 4) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在80%到90%之间,出现的概率为原来的1/4 if (percent[t] >= 0.8 && percent[t] < 0.9) { m3++; if (tp[t] == 3) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在70%到80%之间,出现的概率为原来的1/3 if (percent[t] >= 0.7 && percent[t] < 0.8) { m2++; if (tp[t] == 2) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } // 英雄认识率在60%到70%之间,出现的概率为原来的1/2 if (percent[t] >= 0.6 && percent[t] < 0.7) { m1++; if (tp[t] == 1) { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; this.label3.Text = sumHeroPhoto[t].ToString(); tp[t] = 0; boo = false; } else { tp[t]++; t = ran.Next(125); } } } //英雄认识率低于60%,出现的概率为1/125 else { pictureBox1.Image = imageList1.Images[t]; sumHeroPhoto[t]++; boo = false; } } this.label3.Text = sumHeroPhoto[t].ToString();
用tp参数实现,出现一次,tp++ ,再用random获得一个随机数
出现第二次后,tp=0,此时才会出现该英雄
原文地址:http://blog.csdn.net/long381597329/article/details/46482113