Windows Phone 7 Dev (WP7 开发其实很简单) 稍微讲解_微软商店上架应用<<猜数字>>,适合初学者作为小练习,但是也很耗时

Windows Phone开发的书籍,正如iOS开发一样,是那么的少,苹果有斯坦福的公开课,而WP7也有她的白胡子老头的<<WP7 四天速成教程>>,在看了他的教程他所谓的四天中的不到两天之后,我写了这个简单的<<猜数字>>应用,这个程序就是在折腾着字符串,应用地址(http://windowsphone.com/s?appid=e8cc529e-1672-494a-b8a3-8c11aa531e59)

Windows Phone 7 Dev (WP7 开发其实很简单) 稍微讲解_微软商店上架应用<<猜数字>>,适合初学者作为小练习,但是也很耗时_第1张图片Windows Phone 7 Dev (WP7 开发其实很简单) 稍微讲解_微软商店上架应用<<猜数字>>,适合初学者作为小练习,但是也很耗时_第2张图片Windows Phone 7 Dev (WP7 开发其实很简单) 稍微讲解_微软商店上架应用<<猜数字>>,适合初学者作为小练习,但是也很耗时_第3张图片

创建一个最简单程序,它就好像是HELLO WORLD一样,随意没事儿的时候,可以自己写着玩,我们拖控件,之后写事件,声明4个变量用于得到4个随机数字,

第一段代码,用于按键"1"的事件:

private void button1_Click(object sender, RoutedEventArgs e)
        {
            if(textBlockNow.Text.Length<4){
                int tmp = 0;
                for (int i = 0; i < textBlockNow.Text.Length; i++) {
                    if (textBlockNow.Text.ElementAt(i).ToString().CompareTo("1") == 0) {
                        tmp++;
                    }
                } if (tmp == 0)
                {
                    textBlockNow.Text = textBlockNow.Text + "1";
                }
            }   
        }

第二段代码,用于按键"确定"的事件,我们有8行来显示输入数据及其它的结果,如果第一行有正确的内容,那么向第二行中添加数据,以此类推,当输入正确之后,之后的行中显示"WINNER":

if (textBlockNow.Text.Length == 4) {
                if (textBlockshow1.Text.Length == 0)
                {
                    textBlockshow1.Text = textBlockNow.Text;
                    textBlockNow.Text = "";
                    if ((test(textBlockshow1.Text.ToString())).CompareTo("4A0B") == 0)
                    {
                        textBlockshow2.Text = "WINNER";
                        textBlockshow3.Text = "WINNER";
                        textBlockshow4.Text = "WINNER";
                        textBlockshow5.Text = "WINNER";
                        textBlockshow6.Text = "WINNER";
                        textBlockshow7.Text = "WINNER";
                        textBlockshow8.Text = "WINNER";
                        textBlockwin.Text = "YOU ARE WINNER!!!!!";
                    }
                    textBlockshow1.Text = textBlockshow1.Text + "......" + test(textBlockshow1.Text.ToString());
                }
                else if (textBlockshow2.Text.Length == 0)
                {
                    textBlockshow2.Text = textBlockNow.Text;
                    textBlockNow.Text = "";
                    if ((test(textBlockshow2.Text.ToString())).CompareTo("4A0B") == 0)
                    {
                        textBlockshow3.Text = "WINNER";
                        textBlockshow4.Text = "WINNER";
                        textBlockshow5.Text = "WINNER";
                        textBlockshow6.Text = "WINNER";
                        textBlockshow7.Text = "WINNER";
                        textBlockshow8.Text = "WINNER";
                        textBlockwin.Text = "YOU ARE WINNER!!!!!";
                    }
                    textBlockshow2.Text = textBlockshow2.Text + "......" + test(textBlockshow2.Text.ToString());
                    
                }
......

第三段代码,用于显示用户输入数据后返回结果

public string test(string str) {
            int A = 0;
            int B = 0;
            int tempnum = int.Parse(str);
            int tempn1 = tempnum / 1000;
            int tempn2 = tempnum % 1000 /100;
            int tempn3 = tempnum % 1000 % 100 / 10;
            int tempn4 = tempnum % 10;
            if (tempn1 == num1) { A++; } else if (tempn1 == num2 || tempn1 == num3 || tempn1 == num4) { B++; }
            if (tempn2 == num2) { A++; } else if (tempn2 == num1 || tempn2 == num3 || tempn2 == num4) { B++; }
            if (tempn3 == num3) { A++; } else if (tempn3 == num1 || tempn3 == num2 || tempn3 == num4) { B++; }
            if (tempn4 == num4) { A++; } else if (tempn4 == num1 || tempn4 == num3 || tempn4 == num2) { B++; }
            string string02 = A.ToString() + "A" + B.ToString() + "B";
            return string02;
        }
适合初学者,练习对字符串的操作


你可能感兴趣的:(ios,windows,object,String,button,微软,phone)