用C#猜数字大小的程序

using System;//2.输入一个由若干字符组成的字符串,输出其中的大写字母、小写字母、数字和其他字符的个数。

 

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

       
            int i =0,num1,num2;
            Random r = new Random();

           num1 = r.Next(0, 100);

         

            do
         
            {

                Console.WriteLine("在0到100之间输入一个数 看你能不能猜出来是几");

                num2 = Convert.ToInt32(Console.ReadLine());

                if (num2 > num1)
                {
                    Console.WriteLine("大了!往小里猜呀。");

                }
                else
                {
                    if (num2 < num1)
                    {

                        Console.WriteLine("小了!往大里猜呀。");
                    }
                    else
                    {
                        Console.WriteLine("恭喜你猜对了 亲爱的");
                    }
               

                }

                i++;

            }
            while (i < 100) ;
           

       

          
       

       


        }
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C#编写的GUI游戏 源代码 using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace gn { public partial class Form1 : Form { string ready; int counti = 1; public Form1() { InitializeComponent(); this.label1.Hide(); this.button2.Hide(); this.button1.Hide(); this.button3.Hide(); this.button4.Hide(); this.textBox1.Hide(); this.pictureBox1.Hide(); this.pictureBox2.Hide(); } private void button1_Click(object sender, EventArgs e) { string number; int x, y; int count = 0; number = textBox1.Text; if (number.Length != 4) { MessageBox.Show("请输入4位数字"); } else { if (counti <=8) { if (count <= 3) { x = 0; y = 0; 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; } } } label2.Text = "你已经过" + counti + "次"; ++count; label3.Text = x.ToString() + "A" + y.ToString() + "B"; if (number == ready) { this.label2.Text = "答对了"; this.pictureBox1.Show(); } } if (counti == 8) { this.button1.Enabled = false; this.pictureBox2.Show(); } } else { this.button1.Enabled = false; this.pictureBox2.Show(); } ++counti; } } private void button2_Click(object sender, EventArgs e) { MessageBox.Show(ready); } private void button3_Click(object sender, EventArgs e) { //this.button2.Hide(); this.textBox1.Text = ""; this.label3.Text = ""; this.label2.Text = ""; this.button1.Enabled = true; counti = 1; this.pictureBox1.Hide(); this.pictureBox2.Hide(); Random r = new Random(); string[] a; a = new string[8]; a[0] = "1263"; a[1] = "6598"; a[2] = "9654"; a[3] = "5986"; a[4] = "2915"; a[5] = "2046"; a[6] = "9035"; a[7] = "1057"; int z; z = r.Next(8); ready = a[z]; } private void label1_Click(object sender, EventArgs e) { } private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { } private void button4_Click(object sender, EventArgs e) { Close(); } private void button5_Click(object sender, EventArgs e) { Random r = new Random(); string[] a; a = new string[8]; a[0] = "1263"; a[1] = "6598"; a[2] = "9654"; a[3] = "5986"; a[4] = "2915"; a[5] = "2046"; a[6] = "9035"; a[7] = "1057"; int z; z = r.Next(8); ready = a[z]; this.textBox1.Show(); this.button1.Show(); this.button3.Show(); this.button4.Show(); this.label1.Show(); this.button2.Show(); this.button5.Hide(); } private void label4_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } private void pictureBox1_Click_1(object sender, EventArgs e) { } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值