C#第六次作业

原创 2015年07月07日 12:42:31

以下是源代码

[csharp] view plaincopy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.IO;  
  11. using System.Data.SqlClient;  
  12.   
  13. namespace 猜猜看  
  14. {  
  15.     public partial class Form1 : Form  
  16.     {  
  17.         public Form1()  
  18.         {  
  19.             InitializeComponent();  
  20.         }  
  21.         int model = new int();                              // 判断是模式几  
  22.         int[] sumHeroPhoto = new int[125];                  // 记录imagelist1的数组,图片出现的总数  
  23.         int[] modelTwoName = new int[125];                  // 记录模式二随机出现的名字出现的总次数  
  24.   
  25.         String[] sumHeroNames=new String[125];      // 记录英雄的名字  
  26.         int m,n ;                                   // 记录两个错误名字选项的下标  
  27.         int p1, p2;                                 // 记录两个错误图片选项的下标  
  28.         int t = 0;                                  // 记录正确答案数组的下标  
  29.         int t2 = 0;                                 // 记录模式二正确答案数组的下标  
  30.   
  31.         int x1,x2,x3;              // 三个选项的参数  
  32.         int[] num = new int[3];    // 获得模式一 三个选项的名字数组的下标  
  33.         int[] num2 = new int[3];   // 获得模式二 三个选项的名字数组的下标  
  34.         bool re_elect=new bool();  // 坚持玩家是否重选了  
  35.   
  36.         float[] percent = new float[125];       // 认识率  
  37.         float[] percent2 = new float[125];      //模式二认识率  
  38.         int[] trueGuessNum = new int[125];      // 记录每张图片猜对的次数  
  39.         int[] trueGuessPhoto = new int[125];    // 记录每个名字猜对的次数  
  40.         int[] tp = new int[125];                // 控制高认识率英雄出现的概率  
  41.         int[] tp2 = new int[125];               // 模式二控制高认识率英雄出现的概率  
  42.   
  43.         int m0, m1, m2, m3, m4, m5;              // 显示认识程度变量  
  44.         int n0, n1, n2, n3, n4, n5;              // 模式二认识度变量  
  45.   
  46.         // 筛选英雄类型数组  
  47.         int[] ci_keNum = new int[15];  
  48.         int[] tan_keNum = new int[16];  
  49.         int[] she_shouNum = new int[19];  
  50.         int[] zhan_shiNum = new int[36];  
  51.         int[] fa_shiNum = new int[28];  
  52.         int[] fu_zhuNum = new int[11];  
  53.   
  54.         // 模式二筛选英雄类型数组  
  55.         int[] ci_keNum2 = new int[15];  
  56.         int[] tan_keNum2 = new int[16];  
  57.         int[] she_shouNum2 = new int[19];  
  58.         int[] zhan_shiNum2 = new int[36];  
  59.         int[] fa_shiNum2 = new int[28];  
  60.         int[] fu_zhuNum2 = new int[11];  
  61.   
  62.         private void Form1_Load(object sender, EventArgs e)  
  63.         {  
  64.             modelOneVisible(false);  
  65.             modelTwoVisible(false);  
  66.             textBox1.ReadOnly = true;              //     文本框不可修改  
  67.             // 将名字存入数组  
  68.             getHeroName();  
  69.             comboBox1.SelectedIndex=0;         // 默认显示"全部"  
  70.             comboBox1.SelectionChangeCommitted += new System.EventHandler(this.scc_Click);  
  71.         }  
  72.   
  73.         // 模式一按钮  
  74.         private void modelOne_Click(object sender, EventArgs e)  
  75.         {  
  76.             model = 1;              //模式一  
  77.             // 连接数据库  
  78.             String con = (@"server=LONG-PC\LONG;database=caicaikan;user id=sa;password=123456");  
  79.             SqlConnection conn = new SqlConnection(con);  
  80.             // 读取数据库数据  
  81.             conn.Open();  
  82.             SqlCommand cmd = new SqlCommand();  
  83.             cmd.CommandText = "select * from modelOne";  
  84.             cmd.Connection = conn;  
  85.             SqlDataAdapter da = new SqlDataAdapter(cmd);  
  86.             DataSet ds = new DataSet();  
  87.             da.Fill(ds);  
  88.             DataTable dt = new DataTable();  
  89.             dt = ds.Tables[0].Copy();  
  90.             double[] a = new double[125];  
  91.             for (int i = 0; i < 125; i++)  
  92.             {  
  93.                 sumHeroPhoto[i] = (int)dt.Rows[i].ItemArray[0];  
  94.                 trueGuessNum[i] = (int)dt.Rows[i].ItemArray[1];  
  95.   
  96.                 // 先将数据库中的float转换为c#中的double  
  97.                 a[i] = (double)dt.Rows[i].ItemArray[2];  
  98.                 percent[i] = (float)a[i];  
  99.   
  100.                 tp[i] = (int)dt.Rows[i].ItemArray[3];  
  101.             }  
  102.             conn.Close();  
  103.             conn.Dispose();                  //释放内存空  
  104.   
  105.             // 显示模式一的控件  
  106.             modelOneVisible(true);  
  107.             // 隐藏模式二相关控件  
  108.             aRandomName.Visible = false;  
  109.             pictureBox2.Visible = false;  
  110.             pictureBox3.Visible = false;  
  111.             pictureBox4.Visible = false;  
  112.   
  113.             randomHero();                           // 得到随机图片  
  114.             messageRecord();                        // 显示英雄认识度信息  
  115.             
  116.             cleanRadio123();                        // 清空radiobutton选项  
  117.             getThreeChecked();                      // 得到三个选项的值  
  118.             continueGame.Visible = false;           // 隐藏继续游戏按钮  
  119.             correctResult.Visible = false;          // 隐藏查看正确答案按钮  
  120.             this.textBox1.Text = "请选择答案";  
  121.             re_elect = false;                       // 默认没有重选  
  122.             label4.Text = "选择答案查看";  
  123.               
  124.         }  
  125.   
  126.         // 第一个选项按钮  
  127.         private void radioButton1_CheckedChanged(object sender, EventArgs e)  
  128.         {  
  129.             if (re_elect == true)    //检测是否重选  
  130.             {  
  131.                 textBox1.Text = "只能选择一次";  
  132.             }  
  133.             else  
  134.             {  
  135.                 if (num[x1] == t)  
  136.                 {  
  137.                     textBox1.Text = "正确";  
  138.                     trueGuessNum[num[x1]]++;  
  139.                 }  
  140.                 else  
  141.                 {  
  142.                     textBox1.Text = "错误";  
  143.                 }  
  144.             }  
  145.             continueGame.Visible = true;    // 显示继续游戏按钮  
  146.             correctResult.Visible = true;   // 查看正确答案按钮  
  147.             re_elect = true;                // 打开检查重选  
  148.             //计算认识率  
  149.             percent[t] = (float)trueGuessNum[t] / (sumHeroPhoto[t] + 2);  
  150.             label4.Text = percent[t].ToString("0.00%");                     
  151.         }  
  152.   
  153.         // 第二个选项按钮  
  154.         private void radioButton2_CheckedChanged(object sender, EventArgs e)  
  155.         {  
  156.             if (re_elect == true)  
  157.             {  
  158.                 textBox1.Text = "只能选择一次";  
  159.             }  
  160.             else  
  161.             {  
  162.                 if (num[x2] == t)  
  163.                 {  
  164.                     textBox1.Text = "正确";  
  165.                     trueGuessNum[num[x2]]++;  
  166.                 }  
  167.                 else  
  168.                 {  
  169.                     textBox1.Text = "错误";  
  170.                 }  
  171.             }  
  172.   
  173.             continueGame.Visible = true;  
  174.             correctResult.Visible = true;    
  175.             re_elect = true;  
  176.   
  177.             //计算认识率  
  178.             percent[t] = (float)(trueGuessNum[t]) / (sumHeroPhoto[t] + 2);  
  179.             label4.Text = percent[t].ToString("0.00%");             
  180.         }  
  181.   
  182.         // 第三个选项按钮  
  183.         private void radioButton3_CheckedChanged(object sender, EventArgs e)  
  184.         {  
  185.             if (re_elect == true)  
  186.             {  
  187.                 textBox1.Text = "只能选择一次";  
  188.             }  
  189.             else  
  190.             {  
  191.                 if (num[x3] == t)  
  192.                 {  
  193.                     textBox1.Text = "正确";  
  194.                     trueGuessNum[num[x3]]++;  
  195.                 }  
  196.                 else  
  197.                 {  
  198.                     textBox1.Text = "错误";  
  199.                 }  
  200.             }  
  201.               
  202.             continueGame.Visible = true;  
  203.             correctResult.Visible = true;    
  204.             re_elect = true;  
  205.             //计算认识率  
  206.             percent[t] =(float) trueGuessNum[t] / (sumHeroPhoto[t] + 2);  
  207.             label4.Text = percent[t].ToString("0.00%");  
  208.         }  
  209.   
  210.         // 继续游戏按钮  
  211.         private void continueGame_Click(object sender, EventArgs e)  
  212.         {  
  213.             this.textBox1.Text = "请选择答案";  
  214.             this.label4.Text = "选择答案查看";  
  215.             re_elect = false;  
  216.             if (model == 1)  
  217.             {  
  218.                 switch (comboBox1.SelectedIndex)  
  219.                 {  
  220.                     case 0:  
  221.                          randomHero();  
  222.                          getThreeChecked();  
  223.                          cleanRadio123();  
  224.                          messageRecord();  
  225.                          this.textBox1.Text = "请选择答案";  
  226.                          this.label4.Text = "选择答案查看";  
  227.                          re_elect = false;  
  228.                          break;  
  229.   
  230.                     case 1:  
  231.                         getCi_ke();  
  232.                         getThreeChecked();  
  233.                         cleanRadio123();  
  234.                         ci_keMessage();  
  235.                         this.textBox1.Text = "请选择答案";  
  236.                         this.label4.Text = "选择答案查看";  
  237.                         re_elect = false;  
  238.                         break;  
  239.   
  240.                     case 2:  
  241.                         getTan_ke();  
  242.                         getThreeChecked();  
  243.                         cleanRadio123();  
  244.                         tan_keMessage();  
  245.                         this.textBox1.Text = "请选择答案";  
  246.                         this.label4.Text = "选择答案查看";  
  247.                         re_elect = false;  
  248.                         break;  
  249.   
  250.                     case 3:  
  251.                         getShe_shou();  
  252.                         getThreeChecked();  
  253.                         cleanRadio123();  
  254.                         she_shouMessage();  
  255.                         this.textBox1.Text = "请选择答案";  
  256.                         this.label4.Text = "选择答案查看";  
  257.                         re_elect = false;  
  258.                         break;  
  259.   
  260.                     case 4:  
  261.                         getZhan_shi();  
  262.                         getThreeChecked();  
  263.                         cleanRadio123();  
  264.                         zhan_shiMessage();  
  265.                         this.textBox1.Text = "请选择答案";  
  266.                         this.label4.Text = "选择答案查看";  
  267.                         re_elect = false;  
  268.                         break;  
  269.   
  270.                     case 5:  
  271.                         getFa_shi();  
  272.                         getThreeChecked();  
  273.                         cleanRadio123();  
  274.                         fa_shiMessage();  
  275.                         this.textBox1.Text = "请选择答案";  
  276.                         this.label4.Text = "选择答案查看";  
  277.                         re_elect = false;  
  278.                         break;  
  279.   
  280.                     case 6:  
  281.                         getFu_zhu();  
  282.                         getThreeChecked();  
  283.                         cleanRadio123();  
  284.                         fu_zhuMessage();  
  285.                         this.textBox1.Text = "请选择答案";  
  286.                         this.label4.Text = "选择答案查看";  
  287.                         re_elect = false;  
  288.                         break;  
  289.                 }  
  290.         
  291.             }  
  292.             else  
  293.             {  
  294.                 switch (comboBox1.SelectedIndex)  
  295.                 {  
  296.                     case 0:  
  297.                         getName();                                  // 获得随机名字  
  298.                         getThreeChecked2();                         // 获得3个选项  
  299.                         messageRecord2();  
  300.                         break;  
  301.   
  302.                     case 1:  
  303.                         getCi_ke2();  
  304.                         getThreeChecked2();                         // 获得3个选项  
  305.                         ci_keMessage2();  
  306.                         break;  
  307.   
  308.                     case 2:  
  309.                         getTan_ke2();  
  310.                         getThreeChecked2();  
  311.                         tan_keMessage2();  
  312.                         break;  
  313.   
  314.                     case 3:  
  315.                         getShe_shou2();  
  316.                         getThreeChecked2();  
  317.                         she_shouMessage2();  
  318.                         break;  
  319.   
  320.                     case 4:  
  321.                         getZhan_shi2();  
  322.                         getThreeChecked2();  
  323.                         zhan_shiMessage2();  
  324.                         break;  
  325.   
  326.                     case 5:  
  327.                         getFa_shi2();  
  328.                         getThreeChecked2();  
  329.                         fa_shiMessage2();  
  330.                         break;  
  331.   
  332.                     case 6:  
  333.                         getFu_zhu2();  
  334.                         getThreeChecked2();  
  335.                         fu_zhuMessage2();  
  336.                         break;  
  337.                 }  
  338.             }  
  339.         }  
  340.   
  341.         // 随机产生三个选项  
  342.         void getThreeChecked()  
  343.         {  
  344.             Random rn=new Random();  
  345.             int p = randomHeroName1();  
  346.             int q = randomHeroName2();  
  347.   
  348.             num[0] = t;  
  349.             num[1] = p;  
  350.             num[2] = q;  
  351.            
  352.             // 生成第一个选项  
  353.             x1 = rn.Next(3);  
  354.             radioButton1.Text = sumHeroNames[num[x1]].ToString();  
  355.   
  356.             // 生成第二个选项  
  357.             x2 = rn.Next(3);  
  358.             while (x2 == x1)     // 排除重复  
  359.             {  
  360.                 x2 = rn.Next(3);  
  361.             }  
  362.             radioButton2.Text = sumHeroNames[num[x2]].ToString();  
  363.   
  364.             // 生成第三个选项  
  365.             x3 = rn.Next(3);  
  366.             while (x3 == x1 || x3 == x2)       // 排除重复  
  367.             {  
  368.                 x3 = rn.Next(3);  
  369.             }  
  370.             radioButton3.Text = sumHeroNames[num[x3]].ToString();  
  371.         }  
  372.   
  373.         // 模式一可见性函数  
  374.         void modelOneVisible(bool mv)  
  375.         {  
  376.             if (mv == true)  
  377.             {  
  378.                 pictureBox1.Visible = true;  
  379.                 label1.Visible = true;  
  380.                 label2.Visible = true;  
  381.                 label3.Visible = true;  
  382.                 label4.Visible = true;  
  383.                 radioButton1.Visible = true;  
  384.                 radioButton2.Visible = true;  
  385.                 radioButton3.Visible = true;  
  386.                 textBox1.Visible = true;  
  387.                 continueGame.Visible = false;  
  388.                 correctResult.Visible = false;  
  389.                 label6.Visible = true;  
  390.                 label7.Visible = true;  
  391.                 label8.Visible = true;  
  392.                 label9.Visible = true;  
  393.                 label10.Visible = true;  
  394.                 label11.Visible = true;  
  395.                 label12.Visible = true;  
  396.                 label13.Visible = true;  
  397.                 label14.Visible = true;  
  398.                 label15.Visible = true;  
  399.                 label16.Visible = true;  
  400.                 label17.Visible = true;  
  401.                 label18.Visible = true;  
  402.                 label19.Visible = true;                  
  403.             }  
  404.             else  
  405.             {  
  406.                 pictureBox1.Visible = false;  
  407.                 label1.Visible = false;  
  408.                 label2.Visible = false;  
  409.                 label3.Visible = false;  
  410.                 label4.Visible = false;  
  411.                 radioButton1.Visible = false;  
  412.                 radioButton2.Visible = false;  
  413.                 radioButton3.Visible = false;  
  414.                 textBox1.Visible = false;  
  415.                 continueGame.Visible = false;  
  416.                 correctResult.Visible = false;  
  417.                 label6.Visible = false;  
  418.                 label7.Visible = false;  
  419.                 label8.Visible = false;  
  420.                 label9.Visible = false;  
  421.                 label10.Visible = false;  
  422.                 label11.Visible = false;  
  423.                 label12.Visible = false;  
  424.                 label13.Visible = false;  
  425.                 label14.Visible = false;  
  426.                 label15.Visible = false;  
  427.                 label16.Visible = false;  
  428.                 label17.Visible = false;  
  429.                 label18.Visible = false;  
  430.                 label19.Visible = false;  
  431.             }  
  432.         }  
  433.   
  434.         // 清除三个选项的选择记录  
  435.         void cleanRadio123()  
  436.         {  
  437.             radioButton1.Checked = false;  
  438.             radioButton2.Checked = false;  
  439.             radioButton3.Checked = false;  
  440.         }  
  441.   
  442.         // 随机显示英雄  
  443.         void randomHero()  
  444.         {  
  445.             bool boo=new bool();  
  446.             boo = true;         
  447.             Random ran = new Random();             
  448.             t = ran.Next(125);  
  449.             while (t == m || t == n)  
  450.             {  
  451.                 t = ran.Next(125);  
  452.             }  
  453.             imageList1.ImageSize = new Size(120, 120);  
  454.   
  455.             // 判断英雄认识率是否大于 60%  
  456.             while (boo)  
  457.             {  
  458.                 if (percent[t] >= 0.6)  
  459.                 {  
  460.                     // 英雄认识率高于99%时,出现的概率为原来的1/10  
  461.                     if (percent[t] >= 0.99)  
  462.                     {  
  463.                         m5++;  
  464.                         if (tp[t] == 9)  
  465.                         {  
  466.                             pictureBox1.Image = imageList1.Images[t];  
  467.                             sumHeroPhoto[t]++;  
  468.                             this.label3.Text = sumHeroPhoto[t].ToString();  
  469.                             tp[t] = 0;  
  470.                             boo = false;  
  471.                         }  
  472.                         else  
  473.                         {  
  474.                             tp[t]++;  
  475.                             t = ran.Next(125);  
  476.                         }  
  477.                     }  
  478.                     // 英雄认识率在90%到99%之间,出现的概率为原来的1/5  
  479.                     if (percent[t] >= 0.9 && percent[t] < 0.99)  
  480.                     {  
  481.                         m4++;  
  482.                         if (tp[t] == 4)  
  483.                         {  
  484.                             pictureBox1.Image = imageList1.Images[t];  
  485.                             sumHeroPhoto[t]++;  
  486.                             this.label3.Text = sumHeroPhoto[t].ToString();  
  487.                             tp[t] = 0;  
  488.                             boo = false;  
  489.                         }  
  490.                         else  
  491.                         {  
  492.                             tp[t]++;  
  493.                             t = ran.Next(125);  
  494.                         }  
  495.                     }  
  496.                     // 英雄认识率在80%到90%之间,出现的概率为原来的1/4  
  497.                     if (percent[t] >= 0.8 && percent[t] < 0.9)  
  498.                     {  
  499.                         m3++;  
  500.                         if (tp[t] == 3)  
  501.                         {  
  502.                             pictureBox1.Image = imageList1.Images[t];  
  503.                             sumHeroPhoto[t]++;  
  504.                             this.label3.Text = sumHeroPhoto[t].ToString();  
  505.                             tp[t] = 0;  
  506.                             boo = false;  
  507.                         }  
  508.                         else  
  509.                         {  
  510.                             tp[t]++;  
  511.                             t = ran.Next(125);  
  512.                         }  
  513.                     }  
  514.                     // 英雄认识率在70%到80%之间,出现的概率为原来的1/3  
  515.                     if (percent[t] >= 0.7 && percent[t] < 0.8)  
  516.                     {  
  517.                         m2++;  
  518.                         if (tp[t] == 2)  
  519.                         {  
  520.                             pictureBox1.Image = imageList1.Images[t];  
  521.                             sumHeroPhoto[t]++;  
  522.                             this.label3.Text = sumHeroPhoto[t].ToString();  
  523.                             tp[t] = 0;  
  524.                             boo = false;  
  525.                         }  
  526.                         else  
  527.                         {  
  528.                             tp[t]++;  
  529.                             t = ran.Next(125);  
  530.                         }  
  531.                     }  
  532.                     // 英雄认识率在60%到70%之间,出现的概率为原来的1/2  
  533.                     if (percent[t] >= 0.6 && percent[t] < 0.7)  
  534.                     {  
  535.                         m1++;  
  536.                         if (tp[t] == 1)  
  537.                         {  
  538.                             pictureBox1.Image = imageList1.Images[t];  
  539.                             sumHeroPhoto[t]++;  
  540.                             this.label3.Text = sumHeroPhoto[t].ToString();  
  541.                             tp[t] = 0;  
  542.                             boo = false;  
  543.                         }  
  544.                         else  
  545.                         {  
  546.                             tp[t]++;  
  547.                             t = ran.Next(125);  
  548.                         }  
  549.                     }  
  550.                 }  
  551.                 //英雄认识率低于60%,出现的概率为1/125  
  552.                 else  
  553.                 {                      
  554.                     pictureBox1.Image = imageList1.Images[t];  
  555.                     sumHeroPhoto[t]++;  
  556.                     boo = false;  
  557.                 }  
  558.             }  
  559.             this.label3.Text = sumHeroPhoto[t].ToString();  
  560.         }  
  561.   
  562.         // 将名字存入sumHeroName[]  
  563.         void getHeroName()  
  564.         {  
  565.   
  566.             StreamReader reader = new StreamReader(@"D:\c#\GuessFile\names.txt", Encoding.GetEncoding("gb2312"));  
  567.   
  568.             String line = reader.ReadLine();  
  569.             int i = 0;  
  570.             while (line != null)  
  571.             {  
  572.                 sumHeroNames[i] = line;  
  573.                 i++;  
  574.                 line = reader.ReadLine();  
  575.             }  
  576.             reader.Close();  
  577.         }  
  578.   
  579.         // 随机产生英雄名字1(错误答案)  
  580.         int randomHeroName1()  
  581.         {  
  582.             Random ran = new Random();  
  583.             m = ran.Next(125);  
  584.             while (m == n || m == t)  
  585.             {  
  586.                 m = ran.Next(125);  
  587.             }  
  588.             return m;  
  589.         }  
  590.   
  591.         // 随机产生英雄名字2(错误答案)  
  592.         int randomHeroName2()  
  593.         {  
  594.             Random ran = new Random();  
  595.             n = ran.Next(125);  
  596.             while(n == m||n==t)  
  597.             {  
  598.                 n = ran.Next(125);  
  599.             }  
  600.             return n;  
  601.         }  
  602.   
  603.         // 获取随机刺客  
  604.         void getCi_ke()  
  605.         {  
  606.             // 获取随机刺客  
  607.             int[] s = new int[] { 3, 4, 10, 12, 16, 22, 31, 33, 52, 87, 99, 107, 109, 115, 116 };  
  608.             for (int i = 0; i < 15; i++)  
  609.             {  
  610.                 ci_keNum[i] = s[i];  
  611.             }  
  612.             int c = new int();  
  613.             Random ran = new Random();  
  614.             c = ran.Next(15);  
  615.             t = ci_keNum[c];  
  616.             imageList1.ImageSize = new Size(120, 120);  
  617.             pictureBox1.Image = imageList1.Images[t];  
  618.             sumHeroPhoto[t]++;  
  619.             this.label3.Text = sumHeroPhoto[t].ToString();  
  620.   
  621.         }  
  622.   
  623.         // 获取随机坦克  
  624.         void getTan_ke()  
  625.         {  
  626.             // 获取随机坦克  
  627.             int[] s = new int[] { 18, 55, 56, 65, 66, 67, 69, 75, 78, 80, 81, 84, 91, 96, 108, 121 };  
  628.             for (int i = 0; i < 16; i++)  
  629.             {  
  630.                 tan_keNum[i] = s[i];  
  631.             }  
  632.             int c = new int();  
  633.             Random ran = new Random();  
  634.             c = ran.Next(16);  
  635.             t = tan_keNum[c];  
  636.             imageList1.ImageSize = new Size(120, 120);  
  637.             pictureBox1.Image = imageList1.Images[t];  
  638.             sumHeroPhoto[t]++;  
  639.             this.label3.Text = sumHeroPhoto[t].ToString();  
  640.         }  
  641.   
  642.         // 获取随机射手  
  643.         void getShe_shou()  
  644.         {  
  645.             // 获取随机射手  
  646.             int[] s = new int[] { 1, 6, 13, 20, 24, 29, 35, 59, 70, 74, 79, 82, 85, 89, 94, 98, 113, 114, 118 };  
  647.             for (int i = 0; i < 19; i++)  
  648.             {  
  649.                 she_shouNum[i] = s[i];  
  650.             }  
  651.             int c = new int();  
  652.             Random ran = new Random();  
  653.             c = ran.Next(19);  
  654.             t = she_shouNum[c];  
  655.             imageList1.ImageSize = new Size(120, 120);  
  656.             pictureBox1.Image = imageList1.Images[t];  
  657.             sumHeroPhoto[t]++;  
  658.             this.label3.Text = sumHeroPhoto[t].ToString();  
  659.         }  
  660.   
  661.         // 获取随机战士  
  662.         void getZhan_shi()  
  663.         {  
  664.             // 获取随机战士  
  665.             int[] s = new int[] {2,15,17,19,25,30,34,38,40,42,43,44,  
  666.                                     47,48,49,53,54,58,60,61,62,68,71,72,  
  667.                                         77,83,88,90,92,97,100,101,106,119,120,124};  
  668.             for (int i = 0; i < 36; i++)  
  669.             {  
  670.                 zhan_shiNum[i] = s[i];  
  671.             }  
  672.             int c = new int();  
  673.             Random ran = new Random();  
  674.             c = ran.Next(36);  
  675.             t = zhan_shiNum[c];  
  676.             imageList1.ImageSize = new Size(120, 120);  
  677.             pictureBox1.Image = imageList1.Images[t];  
  678.             sumHeroPhoto[t]++;  
  679.             this.label3.Text = sumHeroPhoto[t].ToString();  
  680.         }  
  681.   
  682.         // 获取随机法师  
  683.         void getFa_shi()  
  684.         {  
  685.             // 获取随机法师  
  686.             int[] s = new int[] {0,7,8,9,11,14,21,23,28,32,36,41,  
  687.                                     45,46,50,51,57,63,64,76,93,95,103,105,  
  688.                                         110,111,117,122};  
  689.             for (int i = 0; i < 28; i++)  
  690.             {  
  691.                 fa_shiNum[i] = s[i];  
  692.             }  
  693.             int c = new int();  
  694.             Random ran = new Random();  
  695.             c = ran.Next(28);  
  696.             t = fa_shiNum[c];  
  697.             imageList1.ImageSize = new Size(120, 120);  
  698.             pictureBox1.Image = imageList1.Images[t];  
  699.             sumHeroPhoto[t]++;  
  700.             this.label3.Text = sumHeroPhoto[t].ToString();  
  701.         }  
  702.   
  703.         // 获取随机辅助  
  704.         void getFu_zhu()  
  705.         {  
  706.             // 获取随机战士  
  707.             int[] s = new int[] { 5, 26, 27, 37, 39, 73, 86, 102, 104, 112, 123 };  
  708.             for (int i = 0; i < 11; i++)  
  709.             {  
  710.                 fu_zhuNum[i] = s[i];  
  711.             }  
  712.             int c = new int();  
  713.             Random ran = new Random();  
  714.             c = ran.Next(11);  
  715.             t = fu_zhuNum[c];  
  716.             imageList1.ImageSize = new Size(120, 120);  
  717.             pictureBox1.Image = imageList1.Images[t];  
  718.             sumHeroPhoto[t]++;  
  719.             this.label3.Text = sumHeroPhoto[t].ToString();  
  720.         }  
  721.   
  722.         // 全部信息记录  
  723.         void messageRecord()  
  724.         {  
  725.             // 清空数据  
  726.             m0 = 0;  
  727.             m1 = 0;  
  728.             m2 = 0;  
  729.             m3 = 0;  
  730.             m4 = 0;  
  731.             m5 = 0;  
  732.   
  733.             label13.Text = "125".ToString();      // 总英雄  
  734.   
  735.             for (int i = 0; i < 125; i++)  
  736.             {  
  737.                 // 初认识  
  738.                 if (sumHeroPhoto[i] != 0)  
  739.                 {  
  740.                     m0++;  
  741.                 }  
  742.                 // 较熟悉  
  743.                 if (percent[i] >= 0.6 && percent[i] < 0.7)  
  744.                 {  
  745.                     m1++;  
  746.                 }  
  747.                 // 已认识  
  748.                 if (percent[i] >= 0.7 && percent[i] < 0.8)  
  749.                 {  
  750.                     m2++;  
  751.                 }  
  752.                 // 很熟悉  
  753.                 if (percent[i] >= 0.8 && percent[i] < 0.9)  
  754.                 {  
  755.                     m3++;  
  756.                 }  
  757.                 // 完全熟悉  
  758.                 if (percent[i] >= 0.9 && percent[i] < 0.99)  
  759.                 {  
  760.                     m4++;  
  761.                 }  
  762.                 // 一眼辨认  
  763.                 if (percent[i] >= 0.99)  
  764.                 {  
  765.                     m5++;  
  766.                 }  
  767.             }  
  768.             label14.Text = m0.ToString();  
  769.             label15.Text = m1.ToString();  
  770.             label16.Text = m2.ToString();  
  771.             label17.Text = m3.ToString();  
  772.             label18.Text = m4.ToString();  
  773.             label19.Text = m5.ToString();  
  774.         }  
  775.   
  776.         // 刺客信息  
  777.         void ci_keMessage()  
  778.         {  
  779.             // 清空数据  
  780.             m0 = 0;  
  781.             m1 = 0;  
  782.             m2 = 0;  
  783.             m3 = 0;  
  784.             m4 = 0;  
  785.             m5 = 0;  
  786.   
  787.             label13.Text = "15".ToString();      // 总英雄  
  788.   
  789.             for (int i = 0; i < 15; i++)  
  790.             {  
  791.                 // 初认识  
  792.                 if (sumHeroPhoto[ci_keNum[i]] != 0)  
  793.                 {  
  794.                     m0++;  
  795.                 }  
  796.                 // 较熟悉  
  797.                 if (percent[ci_keNum[i]] >= 0.6 && percent[ci_keNum[i]] < 0.7)  
  798.                 {  
  799.                     m1++;  
  800.                 }  
  801.                 // 已认识  
  802.                 if (percent[ci_keNum[i]] >= 0.7 && percent[ci_keNum[i]] < 0.8)  
  803.                 {  
  804.                     m2++;  
  805.                 }  
  806.                 // 很熟悉  
  807.                 if (percent[ci_keNum[i]] >= 0.8 && percent[ci_keNum[i]] < 0.9)  
  808.                 {  
  809.                     m3++;  
  810.                 }  
  811.                 // 完全熟悉  
  812.                 if (percent[ci_keNum[i]] >= 0.9 && percent[ci_keNum[i]] < 0.99)  
  813.                 {  
  814.                     m4++;  
  815.                 }  
  816.                 // 一眼辨认  
  817.                 if (percent[ci_keNum[i]] >= 0.99)  
  818.                 {  
  819.                     m5++;  
  820.                 }  
  821.             }  
  822.             label14.Text = m0.ToString();  
  823.             label15.Text = m1.ToString();  
  824.             label16.Text = m2.ToString();  
  825.             label17.Text = m3.ToString();  
  826.             label18.Text = m4.ToString();  
  827.             label19.Text = m5.ToString();  
  828.         }  
  829.   
  830.         // 坦克信息  
  831.         void tan_keMessage()  
  832.         {  
  833.             // 清空数据  
  834.             m0 = 0;  
  835.             m1 = 0;  
  836.             m2 = 0;  
  837.             m3 = 0;  
  838.             m4 = 0;  
  839.             m5 = 0;  
  840.   
  841.             label13.Text = "16".ToString();      // 总英雄  
  842.   
  843.             for (int i = 0; i < 16; i++)  
  844.             {  
  845.                 // 初认识  
  846.                 if (sumHeroPhoto[tan_keNum[i]] != 0)  
  847.                 {  
  848.                     m0++;  
  849.                 }  
  850.                 // 较熟悉  
  851.                 if (percent[tan_keNum[i]] >= 0.6 && percent[tan_keNum[i]] < 0.7)  
  852.                 {  
  853.                     m1++;  
  854.                 }  
  855.                 // 已认识  
  856.                 if (percent[tan_keNum[i]] >= 0.7 && percent[tan_keNum[i]] < 0.8)  
  857.                 {  
  858.                     m2++;  
  859.                 }  
  860.                 // 很熟悉  
  861.                 if (percent[tan_keNum[i]] >= 0.8 && percent[tan_keNum[i]] < 0.9)  
  862.                 {  
  863.                     m3++;  
  864.                 }  
  865.                 // 完全熟悉  
  866.                 if (percent[tan_keNum[i]] >= 0.9 && percent[tan_keNum[i]] < 0.99)  
  867.                 {  
  868.                     m4++;  
  869.                 }  
  870.                 // 一眼辨认  
  871.                 if (percent[tan_keNum[i]] >= 0.99)  
  872.                 {  
  873.                     m5++;  
  874.                 }  
  875.             }  
  876.             label14.Text = m0.ToString();  
  877.             label15.Text = m1.ToString();  
  878.             label16.Text = m2.ToString();  
  879.             label17.Text = m3.ToString();  
  880.             label18.Text = m4.ToString();  
  881.             label19.Text = m5.ToString();   
  882.         }  
  883.   
  884.         // 射手信息  
  885.         void she_shouMessage()  
  886.         {  
  887.             // 清空数据  
  888.             m0 = 0;  
  889.             m1 = 0;  
  890.             m2 = 0;  
  891.             m3 = 0;  
  892.             m4 = 0;  
  893.             m5 = 0;  
  894.   
  895.             label13.Text = "19".ToString();      // 总英雄  
  896.   
  897.             for (int i = 0; i < 19; i++)  
  898.             {  
  899.                 // 初认识  
  900.                 if (sumHeroPhoto[she_shouNum[i]] != 0)  
  901.                 {  
  902.                     m0++;  
  903.                 }  
  904.                 // 较熟悉  
  905.                 if (percent[she_shouNum[i]] >= 0.6 && percent[she_shouNum[i]] < 0.7)  
  906.                 {  
  907.                     m1++;  
  908.                 }  
  909.                 // 已认识  
  910.                 if (percent[she_shouNum[i]] >= 0.7 && percent[she_shouNum[i]] < 0.8)  
  911.                 {  
  912.                     m2++;  
  913.                 }  
  914.                 // 很熟悉  
  915.                 if (percent[she_shouNum[i]] >= 0.8 && percent[she_shouNum[i]] < 0.9)  
  916.                 {  
  917.                     m3++;  
  918.                 }  
  919.                 // 完全熟悉  
  920.                 if (percent[she_shouNum[i]] >= 0.9 && percent[she_shouNum[i]] < 0.99)  
  921.                 {  
  922.                     m4++;  
  923.                 }  
  924.                 // 一眼辨认  
  925.                 if (percent[she_shouNum[i]] >= 0.99)  
  926.                 {  
  927.                     m5++;  
  928.                 }  
  929.             }  
  930.             label14.Text = m0.ToString();  
  931.             label15.Text = m1.ToString();  
  932.             label16.Text = m2.ToString();  
  933.             label17.Text = m3.ToString();  
  934.             label18.Text = m4.ToString();  
  935.             label19.Text = m5.ToString();   
  936.         }  
  937.   
  938.         // 战士信息  
  939.         void zhan_shiMessage()  
  940.         {  
  941.             // 清空数据  
  942.             m0 = 0;  
  943.             m1 = 0;  
  944.             m2 = 0;  
  945.             m3 = 0;  
  946.             m4 = 0;  
  947.             m5 = 0;  
  948.   
  949.             label13.Text = "36".ToString();      // 总英雄  
  950.   
  951.             for (int i = 0; i < 36; i++)  
  952.             {  
  953.                 // 初认识  
  954.                 if (sumHeroPhoto[zhan_shiNum[i]] != 0)  
  955.                 {  
  956.                     m0++;  
  957.                 }  
  958.                 // 较熟悉  
  959.                 if (percent[zhan_shiNum[i]] >= 0.6 && percent[zhan_shiNum[i]] < 0.7)  
  960.                 {  
  961.                     m1++;  
  962.                 }  
  963.                 // 已认识  
  964.                 if (percent[zhan_shiNum[i]] >= 0.7 && percent[zhan_shiNum[i]] < 0.8)  
  965.                 {  
  966.                     m2++;  
  967.                 }  
  968.                 // 很熟悉  
  969.                 if (percent[zhan_shiNum[i]] >= 0.8 && percent[zhan_shiNum[i]] < 0.9)  
  970.                 {  
  971.                     m3++;  
  972.                 }  
  973.                 // 完全熟悉  
  974.                 if (percent[zhan_shiNum[i]] >= 0.9 && percent[zhan_shiNum[i]] < 0.99)  
  975.                 {  
  976.                     m4++;  
  977.                 }  
  978.                 // 一眼辨认  
  979.                 if (percent[zhan_shiNum[i]] >= 0.99)  
  980.                 {  
  981.                     m5++;  
  982.                 }  
  983.             }  
  984.             label14.Text = m0.ToString();  
  985.             label15.Text = m1.ToString();  
  986.             label16.Text = m2.ToString();  
  987.             label17.Text = m3.ToString();  
  988.             label18.Text = m4.ToString();  
  989.             label19.Text = m5.ToString();   
  990.         }  
  991.   
  992.         // 法师信息  
  993.         void fa_shiMessage()  
  994.         {  
  995.             // 清空数据  
  996.             m0 = 0;  
  997.             m1 = 0;  
  998.             m2 = 0;  
  999.             m3 = 0;  
  1000.             m4 = 0;  
  1001.             m5 = 0;  
  1002.   
  1003.             label13.Text = "28".ToString();      // 总英雄  
  1004.   
  1005.             for (int i = 0; i < 28; i++)  
  1006.             {  
  1007.                 // 初认识  
  1008.                 if (sumHeroPhoto[fa_shiNum[i]] != 0)  
  1009.                 {  
  1010.                     m0++;  
  1011.                 }  
  1012.                 // 较熟悉  
  1013.                 if (percent[fa_shiNum[i]] >= 0.6 && percent[fa_shiNum[i]] < 0.7)  
  1014.                 {  
  1015.                     m1++;  
  1016.                 }  
  1017.                 // 已认识  
  1018.                 if (percent[fa_shiNum[i]] >= 0.7 && percent[fa_shiNum[i]] < 0.8)  
  1019.                 {  
  1020.                     m2++;  
  1021.                 }  
  1022.                 // 很熟悉  
  1023.                 if (percent[fa_shiNum[i]] >= 0.8 && percent[fa_shiNum[i]] < 0.9)  
  1024.                 {  
  1025.                     m3++;  
  1026.                 }  
  1027.                 // 完全熟悉  
  1028.                 if (percent[fa_shiNum[i]] >= 0.9 && percent[fa_shiNum[i]] < 0.99)  
  1029.                 {  
  1030.                     m4++;  
  1031.                 }  
  1032.                 // 一眼辨认  
  1033.                 if (percent[fa_shiNum[i]] >= 0.99)  
  1034.                 {  
  1035.                     m5++;  
  1036.                 }  
  1037.             }  
  1038.             label14.Text = m0.ToString();  
  1039.             label15.Text = m1.ToString();  
  1040.             label16.Text = m2.ToString();  
  1041.             label17.Text = m3.ToString();  
  1042.             label18.Text = m4.ToString();  
  1043.             label19.Text = m5.ToString();   
  1044.         }  
  1045.   
  1046.         // 辅助信息  
  1047.         void fu_zhuMessage()  
  1048.         {  
  1049.             // 清空数据  
  1050.             m0 = 0;  
  1051.             m1 = 0;  
  1052.             m2 = 0;  
  1053.             m3 = 0;  
  1054.             m4 = 0;  
  1055.             m5 = 0;  
  1056.   
  1057.             label13.Text = "11".ToString();      // 总英雄  
  1058.   
  1059.             for (int i = 0; i < 11; i++)  
  1060.             {  
  1061.                 // 初认识  
  1062.                 if (sumHeroPhoto[fu_zhuNum[i]] != 0)  
  1063.                 {  
  1064.                     m0++;  
  1065.                 }  
  1066.                 // 较熟悉  
  1067.                 if (percent[fu_zhuNum[i]] >= 0.6 && percent[fu_zhuNum[i]] < 0.7)  
  1068.                 {  
  1069.                     m1++;  
  1070.                 }  
  1071.                 // 已认识  
  1072.                 if (percent[fu_zhuNum[i]] >= 0.7 && percent[fu_zhuNum[i]] < 0.8)  
  1073.                 {  
  1074.                     m2++;  
  1075.                 }  
  1076.                 // 很熟悉  
  1077.                 if (percent[fu_zhuNum[i]] >= 0.8 && percent[fu_zhuNum[i]] < 0.9)  
  1078.                 {  
  1079.                     m3++;  
  1080.                 }  
  1081.                 // 完全熟悉  
  1082.                 if (percent[fu_zhuNum[i]] >= 0.9 && percent[fu_zhuNum[i]] < 0.99)  
  1083.                 {  
  1084.                     m4++;  
  1085.                 }  
  1086.                 // 一眼辨认  
  1087.                 if (percent[fu_zhuNum[i]] >= 0.99)  
  1088.                 {  
  1089.                     m5++;  
  1090.                 }  
  1091.             }  
  1092.             label14.Text = m0.ToString();  
  1093.             label15.Text = m1.ToString();  
  1094.             label16.Text = m2.ToString();  
  1095.             label17.Text = m3.ToString();  
  1096.             label18.Text = m4.ToString();  
  1097.             label19.Text = m5.ToString();   
  1098.         }  
  1099.   
  1100.         // 退出游戏按钮  
  1101.         private void exitGame_Click(object sender, EventArgs e)  
  1102.         {  
  1103.             // 连接数据库  
  1104.             String con = (@"server=LONG-PC\LONG;database=caicaikan;user id=sa;password=123456");  
  1105.             SqlConnection conn = new SqlConnection(con);  
  1106.             // 定义对象,用于sql语句将数据写入数据库  
  1107.             StringBuilder sqlstr = new StringBuilder();  
  1108.             conn.Open();  
  1109.   
  1110.             if (model == 1)  
  1111.             {  
  1112.                 // 清空数据表原数据  
  1113.                 SqlCommand sc = new SqlCommand();  
  1114.                 sc.CommandText = ("truncate table modelOne");  
  1115.                 sc.Connection = conn;  
  1116.                 sc.ExecuteNonQuery();  
  1117.                 for (int i = 0; i < 125; i++)  
  1118.                 {  
  1119.                     sqlstr.Append("insert into modelOne(sumHeroPhoto,trueGuessNum,[percent],tp)");  
  1120.                     sqlstr.Append("values");  
  1121.                     sqlstr.Append("('" + sumHeroPhoto[i] + "','" + trueGuessNum[i] + "','" + percent[i] + "','" + tp[i] + "')");  
  1122.   
  1123.                     using (SqlCommand cmd = new SqlCommand(sqlstr.ToString(), conn)) //定义连接命令  
  1124.                     {  
  1125.                         //cmd.CommandType = CommandType.StoredProcedure;                    
  1126.                         cmd.ExecuteNonQuery();//执行sql语句        
  1127.                     }  
  1128.   
  1129.                     sqlstr.Clear();  
  1130.                 }  
  1131.             }  
  1132.             else  
  1133.             {  
  1134.                 // 清空数据表原数据  
  1135.                 SqlCommand sc2 = new SqlCommand();  
  1136.                 sc2.CommandText = ("truncate table modelTwo");  
  1137.                 sc2.Connection = conn;  
  1138.                 sc2.ExecuteNonQuery();  
  1139.                 for (int i = 0; i < 125; i++)  
  1140.                 {  
  1141.                     sqlstr.Append("insert into modelTwo(modelTwoName,trueGuessPhoto,percent2,tp2)");  
  1142.                     sqlstr.Append("values");  
  1143.                     sqlstr.Append("('" + modelTwoName[i] + "','" + trueGuessPhoto[i] + "','" + percent2[i] + "','" + tp2[i] + "')");  
  1144.   
  1145.                     using (SqlCommand cmd2 = new SqlCommand(sqlstr.ToString(), conn)) //定义连接命令  
  1146.                     {  
  1147.                         //cmd.CommandType = CommandType.StoredProcedure;                    
  1148.                         cmd2.ExecuteNonQuery();//执行sql语句        
  1149.                     }  
  1150.   
  1151.                     sqlstr.Clear();  
  1152.                 }  
  1153.             }  
  1154.             conn.Close();  
  1155.             conn.Dispose(); //释放内存空  
  1156.             this.Close();  
  1157.         }  
  1158.   
  1159.         // 查看正确答案按钮  
  1160.         private void correctResult_Click(object sender, EventArgs e)  
  1161.         {  
  1162.             if (model == 1)  
  1163.             {  
  1164.                 if (num[x1] == t)  
  1165.                     radioButton1.Checked = true;  
  1166.                 if (num[x2] == t)  
  1167.                     radioButton2.Checked = true;  
  1168.                 if (num[x3] == t)  
  1169.                     radioButton3.Checked = true;  
  1170.                 textBox1.Text = "该英雄的名字为:";  
  1171.             }  
  1172.             else  
  1173.             {  
  1174.                 if (num2[x1] == t2)  
  1175.                 {                      
  1176.                     // 第一张边框设置为卡其色  
  1177.                     Graphics g = Graphics.FromHwnd(this.pictureBox2.Handle);  
  1178.                     PaintEventArgs a = new PaintEventArgs(g, this.pictureBox2.ClientRectangle);  
  1179.                     this.pictureBox2_Paint(this.pictureBox2, a);  
  1180.                     g.Dispose();  
  1181.                     
  1182.                     delay(100);  
  1183.                     pictureBox2.Image = imageList1.Images[num2[x1]];  
  1184.                 }  
  1185.   
  1186.                 if (num2[x2] == t2)  
  1187.                 {  
  1188.                     
  1189.                     Graphics g = Graphics.FromHwnd(this.pictureBox3.Handle);  
  1190.                     PaintEventArgs a = new PaintEventArgs(g, this.pictureBox3.ClientRectangle);  
  1191.                     this.pictureBox3_Paint(this.pictureBox3, a);  
  1192.                     g.Dispose();  
  1193.   
  1194.                     delay(100);  
  1195.                     pictureBox3.Image = imageList1.Images[num2[x2]];  
  1196.                       
  1197.                 }  
  1198.   
  1199.                 if (num2[x3] == t2)  
  1200.                 {  
  1201.                     Graphics g = Graphics.FromHwnd(this.pictureBox4.Handle);  
  1202.                     PaintEventArgs a = new PaintEventArgs(g, this.pictureBox4.ClientRectangle);  
  1203.                     this.pictureBox4_Paint(this.pictureBox4, a);  
  1204.                     g.Dispose();  
  1205.   
  1206.                     delay(100);  
  1207.                     pictureBox4.Image = imageList1.Images[num2[x3]];  
  1208.                 }  
  1209.                 textBox1.Text = "该英雄的头像为:";  
  1210.             }  
  1211.         }  
  1212.   
  1213.         // 晒选英雄类型按钮  
  1214.         private void scc_Click(object sender, EventArgs e)  
  1215.         {  
  1216.             continueGame.Visible = false;  
  1217.             correctResult.Visible = false;  
  1218.             this.textBox1.Text = "请选择答案";  
  1219.             re_elect = false;  
  1220.             this.label4.Text = "选择答案查看";  
  1221.   
  1222.             //筛选  
  1223.             if (model == 1)  
  1224.             {  
  1225.                 switch (comboBox1.SelectedIndex)  
  1226.                 {  
  1227.                     case 0:  
  1228.                         randomHero();  
  1229.                         getThreeChecked();  
  1230.                         cleanRadio123();  
  1231.                         messageRecord();  
  1232.                         break;  
  1233.   
  1234.                     case 1:  
  1235.                         getCi_ke();  
  1236.                         getThreeChecked();  
  1237.                         cleanRadio123();  
  1238.                         ci_keMessage();  
  1239.                         break;  
  1240.   
  1241.                     case 2:  
  1242.                         getTan_ke();  
  1243.                         getThreeChecked();  
  1244.                         cleanRadio123();  
  1245.                         tan_keMessage();  
  1246.                         break;  
  1247.   
  1248.                     case 3:  
  1249.                         getShe_shou();  
  1250.                         getThreeChecked();  
  1251.                         cleanRadio123();  
  1252.                         she_shouMessage();  
  1253.                         break;  
  1254.   
  1255.                     case 4:  
  1256.                         getZhan_shi();  
  1257.                         getThreeChecked();  
  1258.                         cleanRadio123();  
  1259.                         zhan_shiMessage();  
  1260.                         break;  
  1261.   
  1262.                     case 5:  
  1263.                         getFa_shi();  
  1264.                         getThreeChecked();  
  1265.                         cleanRadio123();  
  1266.                         fa_shiMessage();  
  1267.                         break;  
  1268.   
  1269.                     case 6:  
  1270.                         getFu_zhu();  
  1271.                         getThreeChecked();  
  1272.                         cleanRadio123();  
  1273.                         fu_zhuMessage();  
  1274.                         break;  
  1275.                 }  
  1276.             }  
  1277.             else  
  1278.             {  
  1279.                 switch (comboBox1.SelectedIndex)  
  1280.                 {  
  1281.                     case 0:  
  1282.                         getName();                                  // 获得随机名字  
  1283.                         getThreeChecked2();                         // 获得3个选项  
  1284.                         messageRecord2();  
  1285.                         break;  
  1286.   
  1287.                     case 1:  
  1288.                         getCi_ke2();  
  1289.                         getThreeChecked2();                         // 获得3个选项  
  1290.                         ci_keMessage2();  
  1291.                         break;  
  1292.   
  1293.                     case 2:  
  1294.                         getTan_ke2();  
  1295.                         getThreeChecked2();  
  1296.                         tan_keMessage2();  
  1297.                         break;  
  1298.   
  1299.                     case 3:  
  1300.                         getShe_shou2();  
  1301.                         getThreeChecked2();  
  1302.                         she_shouMessage2();  
  1303.                         break;  
  1304.   
  1305.                     case 4:  
  1306.                         getZhan_shi2();  
  1307.                         getThreeChecked2();  
  1308.                         zhan_shiMessage2();  
  1309.                         break;  
  1310.   
  1311.                     case 5:  
  1312.                         getFa_shi2();  
  1313.                         getThreeChecked2();  
  1314.                         fa_shiMessage2();  
  1315.                         break;  
  1316.   
  1317.                     case 6:  
  1318.                         getFu_zhu2();  
  1319.                         getThreeChecked2();  
  1320.                         fu_zhuMessage2();  
  1321.                         break;  
  1322.                 }  
  1323.             }  
  1324.         }  
  1325.   
  1326. /**************************** 模式二 ********************************/  
  1327.          
  1328.         // 模式二按钮  
  1329.         private void moderTwo_Click(object sender, EventArgs e)  
  1330.         {  
  1331.             model = 2;  
  1332.             // 连接数据库  
  1333.             String con = (@"server=LONG-PC\LONG;database=caicaikan;user id=sa;password=123456");  
  1334.             SqlConnection conn = new SqlConnection(con);  
  1335.             // 读取数据库数据  
  1336.             conn.Open();  
  1337.             SqlCommand cmd = new SqlCommand();  
  1338.             cmd.CommandText = "select * from modelTwo";  
  1339.             cmd.Connection = conn;  
  1340.             SqlDataAdapter da = new SqlDataAdapter(cmd);  
  1341.             DataSet ds = new DataSet();  
  1342.             da.Fill(ds);  
  1343.             DataTable dt = new DataTable();  
  1344.             dt = ds.Tables[0].Copy();  
  1345.             double[] a = new double[125];  
  1346.             for (int i = 0; i < 125; i++)  
  1347.             {  
  1348.                 modelTwoName[i] = (int)dt.Rows[i].ItemArray[0];  
  1349.                 trueGuessPhoto[i] = (int)dt.Rows[i].ItemArray[1];  
  1350.   
  1351.                 // 先将数据库中的float转换为c#中的double  
  1352.                 a[i] = (double)dt.Rows[i].ItemArray[2];  
  1353.                 percent2[i] = (float)a[i];  
  1354.   
  1355.                 tp2[i] = (int)dt.Rows[i].ItemArray[3];  
  1356.             }  
  1357.             conn.Close();  
  1358.             conn.Dispose();                  //释放内存空  
  1359.   
  1360.             // 显示模式二控件,同时隐藏模式一相关按钮    
  1361.             modelTwoVisible(true);  
  1362.             pictureBox1.Visible = false;  
  1363.             radioButton1.Visible = false;  
  1364.             radioButton2.Visible = false;  
  1365.             radioButton3.Visible = false;           
  1366.   
  1367.               
  1368.             getName();                                  // 获得随机名字  
  1369.             getThreeChecked2();                         // 获得3个选项  
  1370.             this.textBox1.Text = "请选择答案";  
  1371.             re_elect = false;                           // 默认没有重选  
  1372.             label4.Text = "选择答案查看";  
  1373.             messageRecord2();                           // 显示模式二进度  
  1374.   
  1375.         }  
  1376.   
  1377.         // 模式二可见性函数  
  1378.         void modelTwoVisible(bool mv)  
  1379.         {  
  1380.             if (mv == true)  
  1381.             {  
  1382.                 pictureBox2.Visible = true;  
  1383.                 pictureBox3.Visible = true;  
  1384.                 pictureBox4.Visible = true;                                
  1385.                 textBox1.Visible = true;  
  1386.                 continueGame.Visible = false;  
  1387.                 correctResult.Visible = false;  
  1388.                 label1.Visible = true;  
  1389.                 label2.Visible = true;  
  1390.                 label3.Visible = true;  
  1391.                 label4.Visible = true;  
  1392.                 label6.Visible = true;  
  1393.                 label7.Visible = true;  
  1394.                 label8.Visible = true;  
  1395.                 label9.Visible = true;  
  1396.                 label10.Visible = true;  
  1397.                 label11.Visible = true;  
  1398.                 label12.Visible = true;  
  1399.                 label13.Visible = true;  
  1400.                 label14.Visible = true;  
  1401.                 label15.Visible = true;  
  1402.                 label16.Visible = true;  
  1403.                 label17.Visible = true;  
  1404.                 label18.Visible = true;  
  1405.                 label19.Visible = true;  
  1406.                 aRandomName.Visible = true;  
  1407.             }  
  1408.             else  
  1409.             {  
  1410.                 pictureBox2.Visible = false;  
  1411.                 pictureBox3.Visible = false;  
  1412.                 pictureBox4.Visible = false;  
  1413.                 textBox1.Visible = false;  
  1414.                 continueGame.Visible = false;  
  1415.                 correctResult.Visible = false;  
  1416.                 label1.Visible = false;  
  1417.                 label2.Visible = false;  
  1418.                 label3.Visible = false;  
  1419.                 label4.Visible = false;  
  1420.                 label6.Visible = false;  
  1421.                 label7.Visible = false;  
  1422.                 label8.Visible = false;  
  1423.                 label9.Visible = false;  
  1424.                 label10.Visible = false;  
  1425.                 label11.Visible = false;  
  1426.                 label12.Visible = false;  
  1427.                 label13.Visible = false;  
  1428.                 label14.Visible = false;  
  1429.                 label15.Visible = false;  
  1430.                 label16.Visible = false;  
  1431.                 label17.Visible = false;  
  1432.                 label18.Visible = false;  
  1433.                 label19.Visible = false;  
  1434.                 aRandomName.Visible = false;  
  1435.             }  
  1436.         }  
  1437.   
  1438.         // 随机得到一个名字  
  1439.         void getName()  
  1440.         {  
  1441.             bool boo = new bool();  
  1442.             boo = true;  
  1443.             Random ran = new Random();  
  1444.             t2 = ran.Next(125);  
  1445.             while (t2 == p1 || t2 == p2)  
  1446.             {  
  1447.                 t2 = ran.Next(125);  
  1448.             }           
  1449.             // 判断英雄认识率是否大于 60%  
  1450.             while (boo)  
  1451.             {  
  1452.                 if (percent2[t2] >= 0.6)  
  1453.                 {  
  1454.                     // 英雄认识率高于99%时,出现的概率为原来的1/10  
  1455.                     if (percent2[t2] >= 0.99)  
  1456.                     {  
  1457.                         n5++;  
  1458.                         if (tp2[t2] == 9)  
  1459.                         {  
  1460.                             pictureBox1.Image = imageList1.Images[t2];  
  1461.                             sumHeroPhoto[t2]++;  
  1462.                             this.label3.Text = sumHeroPhoto[t2].ToString();  
  1463.                             tp2[t2] = 0;  
  1464.                             boo = false;  
  1465.                         }  
  1466.                         else  
  1467.                         {  
  1468.                             tp2[t2]++;  
  1469.                             t2 = ran.Next(125);  
  1470.                         }  
  1471.                     }  
  1472.                     // 英雄认识率在90%到99%之间,出现的概率为原来的1/5  
  1473.                     if (percent2[t2] >= 0.9 && percent2[t2] < 0.99)  
  1474.                     {  
  1475.                         n4++;  
  1476.                         if (tp2[t2] == 4)  
  1477.                         {  
  1478.                             pictureBox1.Image = imageList1.Images[t2];  
  1479.                             sumHeroPhoto[t2]++;  
  1480.                             this.label3.Text = sumHeroPhoto[t2].ToString();  
  1481.                             tp2[t2] = 0;  
  1482.                             boo = false;  
  1483.                         }  
  1484.                         else  
  1485.                         {  
  1486.                             tp2[t2]++;  
  1487.                             t2 = ran.Next(125);  
  1488.                         }  
  1489.                     }  
  1490.                     // 英雄认识率在80%到90%之间,出现的概率为原来的1/4  
  1491.                     if (percent2[t2] >= 0.8 && percent2[t2] < 0.9)  
  1492.                     {  
  1493.                         n3++;  
  1494.                         if (tp2[t2] == 3)  
  1495.                         {  
  1496.                             pictureBox1.Image = imageList1.Images[t2];  
  1497.                             sumHeroPhoto[t2]++;  
  1498.                             this.label3.Text = sumHeroPhoto[t2].ToString();  
  1499.                             tp2[t2] = 0;  
  1500.                             boo = false;  
  1501.                         }  
  1502.                         else  
  1503.                         {  
  1504.                             tp2[t2]++;  
  1505.                             t2 = ran.Next(125);  
  1506.                         }  
  1507.                     }  
  1508.                     // 英雄认识率在70%到80%之间,出现的概率为原来的1/3  
  1509.                     if (percent2[t2] >= 0.7 && percent2[t2] < 0.8)  
  1510.                     {  
  1511.                         n2++;  
  1512.                         if (tp2[t2] == 2)  
  1513.                         {  
  1514.                             pictureBox1.Image = imageList1.Images[t2];  
  1515.                             sumHeroPhoto[t2]++;  
  1516.                             this.label3.Text = sumHeroPhoto[t2].ToString();  
  1517.                             tp2[t2] = 0;  
  1518.                             boo = false;  
  1519.                         }  
  1520.                         else  
  1521.                         {  
  1522.                             tp2[t2]++;  
  1523.                             t2 = ran.Next(125);  
  1524.                         }  
  1525.                     }  
  1526.                     // 英雄认识率在60%到70%之间,出现的概率为原来的1/2  
  1527.                     if (percent2[t2] >= 0.6 && percent2[t2] < 0.7)  
  1528.                     {  
  1529.                         n1++;  
  1530.                         if (tp2[t2] == 1)  
  1531.                         {  
  1532.                             pictureBox1.Image = imageList1.Images[t2];  
  1533.                             sumHeroPhoto[t2]++;  
  1534.                             this.label3.Text = sumHeroPhoto[t2].ToString();  
  1535.                             tp2[t2] = 0;  
  1536.                             boo = false;  
  1537.                         }  
  1538.                         else  
  1539.                         {  
  1540.                             tp2[t2]++;  
  1541.                             t2 = ran.Next(125);  
  1542.                         }  
  1543.                     }  
  1544.                 }  
  1545.                 //英雄认识率低于60%,出现的概率为1/125  
  1546.                 else  
  1547.                 {  
  1548.                     aRandomName.Text=sumHeroNames[t2].ToString();  
  1549.                     modelTwoName[t2]++;  
  1550.                     boo = false;  
  1551.                 }  
  1552.             }  
  1553.             this.label3.Text = modelTwoName[t2].ToString();  
  1554.         }  
  1555.   
  1556.         // 获得一张随机图片1(干扰图片)  
  1557.         int randomPhoto1()   
  1558.         {  
  1559.             Random ran = new Random();  
  1560.             p1 = ran.Next(125);  
  1561.             while (p1 == p2 || p1 == t2)  
  1562.             {  
  1563.                 p1 = ran.Next(125);  
  1564.             }  
  1565.             return p1;  
  1566.         }  
  1567.   
  1568.         // 获得一张随机图片2(干扰图片)  
  1569.         int randomPhoto2()  
  1570.         {  
  1571.             Random ran = new Random();  
  1572.             p2 = ran.Next(125);  
  1573.             while (p2 == p1 || p2 == t2)  
  1574.             {  
  1575.                 p2 = ran.Next(125);  
  1576.             }  
  1577.             return p2;  
  1578.         }  
  1579.   
  1580.         // 随机显示三个选项  
  1581.         void getThreeChecked2()  
  1582.         {  
  1583.             Random rn = new Random();  
  1584.             int p = randomPhoto1();  
  1585.             int q = randomPhoto2();  
  1586.   
  1587.             num2[0] = t2;  
  1588.             num2[1] = p;  
  1589.             num2[2] = q;  
  1590.   
  1591.             // 生成第一个选项  
  1592.             x1 = rn.Next(3);  
  1593.             pictureBox2.Image = imageList1.Images[num2[x1]];  
  1594.   
  1595.             // 生成第二个选项  
  1596.             x2 = rn.Next(3);  
  1597.             while (x2 == x1)     // 排除重复  
  1598.             {  
  1599.                 x2 = rn.Next(3);  
  1600.             }  
  1601.             pictureBox3.Image = imageList1.Images[num2[x2]];  
  1602.   
  1603.             // 生成第三个选项  
  1604.             x3 = rn.Next(3);  
  1605.             while (x3 == x1 || x3 == x2)       // 排除重复  
  1606.             {  
  1607.                 x3 = rn.Next(3);  
  1608.             }  
  1609.             pictureBox4.Image = imageList1.Images[num2[x3]];  
  1610.         }  
  1611.   
  1612.         // 点击第一图片触发的事件  
  1613.         private void pictureBox2_Click(object sender, EventArgs e)  
  1614.         {  
  1615.             // 第一张边框设置为卡其色  
  1616.             Graphics g = Graphics.FromHwnd(this.pictureBox2.Handle);  
  1617.             PaintEventArgs a = new PaintEventArgs(g, this.pictureBox2.ClientRectangle);  
  1618.             this.pictureBox2_Paint(this.pictureBox2, a);  
  1619.             g.Dispose();  
  1620.   
  1621.             delay(100);  
  1622.             pictureBox2.Image = imageList1.Images[num2[x1]];  
  1623.   
  1624.   
  1625.             // 实现模式一选择答案功能  
  1626.             if (re_elect == true)    //检测是否重选  
  1627.             {  
  1628.                 textBox1.Text = "只能选择一次";  
  1629.             }  
  1630.             else  
  1631.             {  
  1632.                 if (num2[x1] == t2)  
  1633.                 {  
  1634.                     textBox1.Text = "正确";  
  1635.                     trueGuessPhoto[num2[x1]]++;  
  1636.                 }  
  1637.                 else  
  1638.                 {  
  1639.                     textBox1.Text = "错误";  
  1640.                 }  
  1641.             }  
  1642.             continueGame.Visible = true;    // 显示继续游戏按钮  
  1643.             correctResult.Visible = true;   // 查看正确答案按钮  
  1644.             re_elect = true;                // 打开检查重选  
  1645.             //计算认识率  
  1646.             percent2[t2] = (float)trueGuessPhoto[t2] / (modelTwoName[t2] + 2);  
  1647.             label4.Text = percent2[t2].ToString("0.00%");                     
  1648.         }  
  1649.   
  1650.         // 点击第二张图片触发的事件  
  1651.         private void pictureBox3_Click(object sender, EventArgs e)  
  1652.         {  
  1653.             Graphics g = Graphics.FromHwnd(this.pictureBox3.Handle);  
  1654.             PaintEventArgs a = new PaintEventArgs(g, this.pictureBox3.ClientRectangle);  
  1655.             this.pictureBox3_Paint(this.pictureBox3, a);  
  1656.             g.Dispose();  
  1657.   
  1658.             delay(100);  
  1659.             pictureBox3.Image = imageList1.Images[num2[x2]];  
  1660.   
  1661.             // 实现模式一选择答案功能  
  1662.             if (re_elect == true)  
  1663.             {  
  1664.                 textBox1.Text = "只能选择一次";  
  1665.             }  
  1666.             else  
  1667.             {  
  1668.                 if (num2[x2] == t2)  
  1669.                 {  
  1670.                     textBox1.Text = "正确";  
  1671.                     trueGuessPhoto[num2[x2]]++;  
  1672.                 }  
  1673.                 else  
  1674.                 {  
  1675.                     textBox1.Text = "错误";  
  1676.                 }  
  1677.             }  
  1678.   
  1679.             continueGame.Visible = true;  
  1680.             correctResult.Visible = true;  
  1681.             re_elect = true;  
  1682.   
  1683.             //计算认识率  
  1684.             percent2[t2] = (float)(trueGuessPhoto[t2]) / (modelTwoName[t2] + 2);  
  1685.             label4.Text = percent2[t2].ToString("0.00%");            
  1686.         }  
  1687.