欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2022-06-30 23:39:57
  windows phone开发的书籍,正如ios开发一样,是那么的少,苹果有斯坦福的公开课,而wp7也有她的白胡子老头的<>,在看了他的...

 
windows phone开发的书籍,正如ios开发一样,是那么的少,苹果有斯坦福的公开课,而wp7也有她的白胡子老头的<<wp7 四天速成教程>>,在看了他的教程他所谓的四天中的不到两天之后,我写了这个简单的<<猜数字>>应用,这个程序就是在折腾着字符串,应用地址()





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

 




 

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

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

 

[csharp]
<span style="font-size:24px;">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"; 
                } 
            }    
        }</span> 
<span style="font-size:24px;">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";
                }
            }  
        }</span>
第二段代码,用于按键"确定"的事件,我们有8行来显示输入数据及其它的结果,如果第一行有正确的内容,那么向第二行中添加数据,以此类推,当输入正确之后,之后的行中显示"winner":


[csharp]
<span style="font-size:24px;">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()); 
                     
                } 
......</span> 
<span style="font-size:24px;">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());
                   
                }
......</span>
第三段代码,用于显示用户输入数据后返回结果


[csharp]
<span style="font-size:24px;">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; 
        }</span> 
<span style="font-size:24px;">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;
        }</span> 适合初学者,练习对字符串的操作



摘自 wintelsui