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(); }