本人编的一点测智商小程序,用的是visual2010
public class bas_game
{
private String trueAns;
private DateTime str;
public String getcalc()
{
String calc = "";
Random rdm = new Random();
int x = rdm.Next(11, 20);
int y = rdm.Next(11, 20);
int z = x * y;
calc = x.ToString() + "*" + y.ToString();
trueAns = z.ToString();
str = DateTime.Now;
return calc;
}
public String getIQ(String name, String Ans)
{
String iq = "";
double x = Math.Round((DateTime.Now - str).TotalSeconds);
if (name == "AAA")
{
iq = "140";
}
else
{
if (Ans == trueAns)
{
iq = (120 - x).ToString();
}
else
{
iq = (60 - x).ToString();
}
}
iq = "亲爱的" + name + ",你的IQ指数为" + iq;
return iq;
}
}
public partial class Game1 : Form
{
private bas_game c1;
public Game1()
{
InitializeComponent();
c1 = new bas_game();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请输入你的名字,再点击开始!");
}
else
{
textBox2.Clear();
label5.Text = "";
label4.Text = c1.getcalc();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请输入你的名字,再点击开始!");
}
else
{
if (textBox2.Text == "")
{
MessageBox.Show("请输入你的答案,再点击确认!");
}
else
{
label5.Text = c1.getIQ(textBox1.Text, textBox2.Text);
}
}
}
}
[
本帖最后由 平遥小D 于 2012-7-17 11:13 编辑 ]