内容纲要
using System;

namespace ConsoleApp1
{
    class Program
    {
        //产生随机数函数
        static int Rand(int value = 100)
        {
            Random rd = new Random();
            return rd.Next(value);
        }
        //比较
        static Boolean uCompare(int value1, int value2)
        {
            Boolean flag = true;
            if (value1 == value2)
            {
                Console.WriteLine("回答正确!");

                return flag;
            }
            else
            {
                if (value1 < value2)
                    Console.WriteLine("小于答案");
                else
                    Console.WriteLine("大于答案");

                flag = false;
                return flag;
            }
        }
        static void Main(string[] args)
        {
            //当前剩余游戏次数
            int flag = 5;
            //选项
            string option;
            //ABCD
            int A, B, C, D,Answer;

            while (flag >= 0)
            {
                //回答正确不扣除次数直接跳回
                stat:

                Console.WriteLine("当前剩余游戏次数:{0}", flag);

                //产生答案和选项 每次都会生成新的答案和选项
                Answer = Rand(100);
                A = Rand(100);
                B = Rand(100);
                C = Rand(100);
                D = Rand(100);

                if (Answer >= 80)
                    A = Answer;
                else if (Answer < 80 && Answer >= 60)
                    B = Answer;
                else if (Answer < 60 && Answer >= 40)
                    C = Answer;
                else
                    D = Answer;

                //检测答案
                Console.WriteLine("答案:" + Answer + "\n");
                Console.WriteLine("A:{0} B:{1} C:{2} D:{3}\n", A, B, C, D);
                Console.WriteLine("请输入选项:");
                option = Console.ReadLine();
                switch (option)
                {
                    case "A":
                        if (uCompare(A, Answer))
                            goto stat;
                        break;
                    case "B":
                        if (uCompare(B, Answer))
                            goto stat;
                        break;
                    case "C":
                        if (uCompare(C, Answer))
                            goto stat;
                        break;
                    case "D":
                        if (uCompare(D, Answer))
                            goto stat;
                        break;
                    default:
                        Console.WriteLine("输入错误请重新输入");
                        goto stat;
                }
                //完成一次游戏扣除一次次数
                flag--;
            }
            Console.WriteLine("游戏结束!");
        }
    }
}

1 对 “选择题”的想法;

发表评论