c#day03

c#中的随机数

 

Random  random = new Random();

//随机1~200之间的一个数

random.Next(1,201);

 

//怪兽:防御为10,血量为10 
        //玩家:随机8~12的攻击力
        //描述怪兽掉血的情况,每次伤害大于防御则扣攻击力-防御的血,否则不扣血

        public void Games()
        {
            Random random = new Random();
            int defense = 10;
            int hp = 10;
            int atk;

            while (hp!=0)
            {

                atk = random.Next(8,13);

               

                if(atk>defense)
                {
                hp = hp - ( atk - defense);
                Console.WriteLine("本次攻击力为{0}------当前怪兽的血量为:{1}", atk, hp);
                }
                else
                {
                    Console.WriteLine("本次攻击力为{0} ------未破防",atk);
                }

            }
            Console.WriteLine("恭喜你成功击杀了怪兽!");

        }

 

 //输入一串数字,把它换成对应的中文大写 例如123   一二三;

        public void Conversion()
        {
            int num;
            int teml = 0;
            string snum;
            Console.WriteLine ("请输入一串数字"); 

            snum =  Console.ReadLine();
            num = int.Parse(snum);
            
            for (int i = 0; i < snum.Length;i++ )
            {
                teml = teml * 10 + num % 10;
                num = num / 10;
            }

            for (int j = 0; j < snum.Length; j++)
            {
                

                switch (teml%10)
                {
                    case 0:
                        Console.Write("");teml = teml / 10;continue;
                    case 1:
                        Console.Write("");teml = teml / 10; continue;
                    case 2:
                        Console.Write("");teml = teml / 10; continue;
                    case 3:
                        Console.Write("");teml = teml / 10; continue;
                    case 4:
                        Console.Write("");teml = teml / 10; continue;
                    case 5:
                        Console.Write("");teml = teml / 10; continue;
                    case 6:
                        Console.Write("");teml = teml / 10; continue;
                    case 7:
                        Console.Write("");teml = teml / 10; continue;
                    case 8:
                        Console.Write("");teml = teml / 10; continue;
                    case 9:
                        Console.Write("");teml = teml / 10; continue;


                }

               
            }
            Console.WriteLine();

        }

 

posted @ 2019-01-02 15:45  D个人笔记  阅读(132)  评论(0编辑  收藏  举报