欢迎光临
我们一直在努力

c#小游戏——-猜数字 (solarsoft原创)-.net教程,算法/线

建站超值云服务器,限时71元/月

朋友们,刚编写完这个小游戏,已经11点多了.休息一下,欣赏一下.学习任何的语言,都是在不断的编写中提高了.勿以简小而不为.using system;
public class game
{
    private string number;
    private static int x,y;
    private int count=0;
    
    public void init()
    {
      do{
      console.writeline("please input number:");
      number=(string)console.readline();
      }while(number.length!=4);
    }
    public void play()
    {
     string ready="1234";
//这里ready的值是要随机变化的.否则,没人玩你的游戏了.
//char[] r=new char[]{0,…….9};
// 用循环和随机函数将其顺序打乱.在取其前4个元素,给ready就可以了.
     do{
        x=0;
        y=0;
        init();
        for(int i=0;i<=3;i++)
        {
           for(int j=0;j<=3;j++)
           {
              if(number[i]==ready[j])
              {
                 if (i==j)
                 ++x;
                 else
                 ++y;
              }
           }
         }
     ++count;   
     console.writeline("{0}a{1}b",x.tostring(),y.tostring());
      if(count>=8)
      {
       console.writeline("——————-");
       console.writeline("you already lossed");
       console.writeline("——————-");
       return;
       }
     }while(number!=ready);
      console.writeline("—————————-");
      console.writeline("ok! you are very cleverness!");
      console.writeline("—————————-");

   }
}
public class mygame
{
   public static void main()
{
   game g=new game();
   g.play();
}
}
已经编译通过.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » c#小游戏——-猜数字 (solarsoft原创)-.net教程,算法/线
分享到: 更多 (0)

相关推荐

  • 暂无文章