手机算命源码(Windows mobile SDK 5)

  1. //主要代码放在form2:
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Collections;
  10. namespace getLifespan
  11. {
  12.     public partial class Form2 : Form
  13.     {
  14.       
  15.         public Form2()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         static int questionIndex = 0;//设置问题的索引
  20.         static int lifespan = 72;//预期寿命的平均值
  21.         int[][] answerArr;
  22.         ArrayList questionArrList=new ArrayList ();
  23.         string[][] answer;
  24.         
  25.         
  26.         private void Form2_Load(object sender, EventArgs e)
  27.         {
  28.             answerArr = new int[][] { new int[] { -3, 1 }, new int[] { -2, 2, 0 }, new int[] { 2, 6, 0 }, new int[] { 0,-4, -3 }, new int[] { -2,0},
  29.                 new int[]{1,4,3,0},new int[]{5,0},new int[]{-3,0},new int[]{3,0},new int[]{4,2,0},new int[]{-4,-3,0},new int[]{-3,3,0},new int[]{1,-1},
  30.                 new int[]{0,-1},new int[]{-8,-6,-3,-3},new int[]{0,-1},new int[]{-2,-4,-8},new int[]{2,2,0},new int[]{3,5,7,0}
  31.             };
  32.             //以下添加问题
  33.             questionArrList.Add("1:您的性别是?");
  34.             questionArrList.Add("2:你的居住地是?");
  35.             questionArrList.Add("3:请选择:");
  36.             questionArrList.Add("4:请选择:");
  37.             questionArrList.Add("5:你是百万富翁吗?(可支配流动资金>100万人民币)");
  38.             questionArrList.Add("6:请选择符合你的情况:");
  39.             questionArrList.Add("7:你有和配偶住在一起吗?");
  40.             questionArrList.Add("8:您经常伏案工作吗?");
  41.             questionArrList.Add("9:您经常从事体力劳动吗?");
  42.             questionArrList.Add("10:您每星期进行球类、游泳、跑步等运动多少次?");
  43.             questionArrList.Add("11:您的睡眠情况是:");
  44.             questionArrList.Add("12:你的生活状态符合以下哪种情况?");
  45.             questionArrList.Add("13:您经常感到快乐吗?");
  46.             questionArrList.Add("14:您去年因一次交通违章受罚吗?");
  47.             questionArrList.Add("15:您的抽烟量是?(扣除分给别人的)");
  48.             questionArrList.Add("16:平均每天喝白酒50毫升以上");
  49.             questionArrList.Add("17:您的标准体重符合以下那种情况?(标准体重=身高-105)Kg");
  50.             questionArrList.Add("18:下列情况哪种符合您的情况?");
  51.             questionArrList.Add("19:请选择:");
  52.          
  53.             //以下添加答案
  54.             answer = new string[][] { 
  55.                 new string[] { "男性""女性" }, 
  56.                 new string[] { "100万以上大城市""人口少于1万人的小镇或农村"},
  57.                 new string[]{"祖父母或外祖父母中有1位活到85岁","4位祖辈都活到80岁"},
  58.                 new string[]{"以下都没有","父母有1人在50岁以前死于中风或心脏病","直系亲属中有50岁前得癌或心脏不正常或自幼就有糖尿病"},
  59.                 new string[]{"是","否"},
  60.                 new string[]{"大学毕业","大学毕业且65岁仍在工作","未大学毕业,不过65岁仍在工作","没有大学毕业,65岁也不再工作"},
  61.                 new string[]{"有","没有"},
  62.                 new string[]{"是的","没有或很少"},
  63.                 new string[]{"是的","没有或很少"},
  64.                 new string[]{"5次及以上","2-3次","没有或很少"},
  65.                 new string[]{"差不多每晚超过10个小时","睡眠经常不好","其它"},
  66.                 new string []{"经常紧张、易怒、性急","感到生活很轻松,工作应付自如","不好说"},
  67.                 new string[]{"是的","不是"},
  68.                 new string[]{"没有","有"},
  69.                 new string[]{"2包及其以上","1-2包","1包以下","我不抽烟"},
  70.                 new string []{"没有","有"},
  71.                 new string []{"超过标准5公斤","超过15公斤","超过25公斤"},
  72.                 new string []{"我已40多岁(男性)且每年体检一次","我每年妇科体检2次","其它"},
  73.                 new string []{"我今年30-40岁","我今年40-50岁","我超过70岁啦","其他"}
  74.             
  75.             };
  76.             lblQuestion.Text = questionArrList[0].ToString ();
  77.             //初始化第一个选择题的答案
  78.             label1.Text = answer[0][0].ToString();
  79.             label2.Text = answer[0][1].ToString();
  80.             label3.Text = "";
  81.             label4.Text = "";
  82.             
  83.         }
  84.         private void button1_Click(object sender, EventArgs e)
  85.         {
  86.             //下一题时清空各个选项答案
  87.             label1.Text = "";
  88.             label2.Text = "";
  89.             label3.Text = "";
  90.             label4.Text  = "";
  91.             //判断是否已经完成全部答题
  92.             if (questionIndex >= questionArrList.Count-1)
  93.             {
  94.                 //处理第一个选项被选择时
  95.                 try
  96.                 {
  97.                     if (rb0.Checked)
  98.                     {
  99.                         lifespan += (int)answerArr[questionIndex][0];
  100.                     }
  101.                     //处理第二个选项被选择时
  102.                     if (rb1.Checked)
  103.                     {
  104.                         lifespan += (int)answerArr[questionIndex][1];
  105.                     }
  106.                     if (rb2.Checked)
  107.                     {
  108.                         lifespan += (int)answerArr[questionIndex][2];
  109.                     }
  110.                     if (rb3.Checked)
  111.                     {
  112.                         lifespan += (int)answerArr[questionIndex][3];
  113.                     }
  114.                 }
  115.                 catch (Exception e1)
  116.                 {
  117.                     MessageBox.Show("该项没有内容,请重新选择!");
  118.                     for (int j = 0; j < answer[questionIndex].Length; j++)
  119.                     {
  120.                         switch (j)
  121.                         {
  122.                             case 0: label1.Text = answer[questionIndex][j].ToString();
  123.                                 break;
  124.                             case 1: label2.Text = answer[questionIndex][j].ToString();
  125.                                 break;
  126.                             case 2: label3.Text = answer[questionIndex][j].ToString();
  127.                                 break;
  128.                             case 3: label4.Text = answer[questionIndex][j].ToString();
  129.                                 break;
  130.                             default:
  131.                                 MessageBox.Show("错误");
  132.                                 break;
  133.                         }
  134.                     }
  135.                     return;
  136.                 }
  137.                 button1.Text = "完成";
  138.                 MessageBox.Show("您的预期寿命是:" + lifespan.ToString() + "岁。如果您对该结果不满意,请不要灰心丧气,从现在做起,改变不良生活习惯,戒烟、戒酒、正确进行身体锻炼、乐观地生活,您的寿命就会延长,生命的钥匙就在您自己手上。");
  139.                 #region
  140.                 //显示最后一道题
  141.                 lblQuestion.Text = questionArrList[questionIndex].ToString();
  142.                 for (int j = 0; j < answer[questionIndex].Length; j++)
  143.                 {
  144.                     switch (j)
  145.                     {
  146.                         case 0: label1.Text = answer[questionIndex][j].ToString();
  147.                             break;
  148.                         case 1: label2.Text = answer[questionIndex][j].ToString();
  149.                             break;
  150.                         case 2: label3.Text = answer[questionIndex][j].ToString();
  151.                             break;
  152.                         case 3: label4.Text = answer[questionIndex][j].ToString();
  153.                             break;
  154.                         default:
  155.                             MessageBox.Show("错误");
  156.                             break;
  157.                     }
  158.                 }
  159.                 #endregion
  160.                
  161.             }
  162.             else
  163.             {
  164.                 try
  165.                 {
  166.                     //处理第一个选项被选择时
  167.                     if (rb0.Checked)
  168.                     {
  169.                         lifespan += (int)answerArr[questionIndex][0];
  170.                     }
  171.                     //处理第二个选项被选择时
  172.                     if (rb1.Checked)
  173.                     {
  174.                         lifespan += (int)answerArr[questionIndex][1];
  175.                     }
  176.                     if (rb2.Checked)
  177.                     {
  178.                         lifespan += (int)answerArr[questionIndex][2];
  179.                     }
  180.                     if (rb3.Checked)
  181.                     {
  182.                         lifespan += (int)answerArr[questionIndex][3];
  183.                     }
  184.                 }
  185.                 catch (Exception e2)
  186.                 {
  187.                     MessageBox.Show("该项没有内容,请重新选择!");
  188.                     for (int j = 0; j < answer[questionIndex].Length; j++)
  189.                     {
  190.                         switch (j)
  191.                         {
  192.                             case 0: label1.Text = answer[questionIndex][j].ToString();
  193.                                 break;
  194.                             case 1: label2.Text = answer[questionIndex][j].ToString();
  195.                                 break;
  196.                             case 2: label3.Text = answer[questionIndex][j].ToString();
  197.                                 break;
  198.                             case 3: label4.Text = answer[questionIndex][j].ToString();
  199.                                 break;
  200.                             default:
  201.                                 MessageBox.Show("错误");
  202.                                 break;
  203.                         }
  204.                     }
  205.                     return;
  206.                 }
  207.                 questionIndex++;
  208.                 lblQuestion.Text = questionArrList[questionIndex].ToString();
  209.                 for (int j = 0; j < answer[questionIndex].Length; j++)
  210.                 {
  211.                     switch (j)
  212.                     {
  213.                         case 0: label1.Text = answer[questionIndex][j].ToString();
  214.                             break;
  215.                         case 1: label2.Text = answer[questionIndex][j].ToString();
  216.                             break;
  217.                         case 2: label3.Text = answer[questionIndex][j].ToString();
  218.                             break;
  219.                         case 3: label4.Text = answer[questionIndex][j].ToString();
  220.                             break;
  221.                         default:
  222.                             MessageBox.Show("错误");
  223.                             break;
  224.                     }
  225.                 }
  226.                     
  227.             }//end else   
  228.         }
  229.         private void menuItem1_Click(object sender, EventArgs e)
  230.         {
  231.             Application.Exit();
  232.         }
  233.         private void menuItem2_Click(object sender, EventArgs e)
  234.         {
  235.             MessageBox.Show("作者:阿佛 2008-11-11");
  236.         }
  237.     }
  238. }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值