c#day03

c#中的随机数

Random  random = new Random();

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

random.Next(,);
//怪兽:防御为10,血量为10
//玩家:随机8~12的攻击力
//描述怪兽掉血的情况,每次伤害大于防御则扣攻击力-防御的血,否则不扣血 public void Games()
{
Random random = new Random();
int defense = ;
int hp = ;
int atk; while (hp!=)
{ atk = random.Next(,); 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 = ;
string snum;
Console.WriteLine ("请输入一串数字"); snum = Console.ReadLine();
num = int.Parse(snum); for (int i = ; i < snum.Length;i++ )
{
teml = teml * + num % ;
num = num / ;
} for (int j = ; j < snum.Length; j++)
{ switch (teml%)
{
case :
Console.Write("零");teml = teml / ;continue;
case :
Console.Write("一");teml = teml / ; continue;
case :
Console.Write("二");teml = teml / ; continue;
case :
Console.Write("三");teml = teml / ; continue;
case :
Console.Write("四");teml = teml / ; continue;
case :
Console.Write("五");teml = teml / ; continue;
case :
Console.Write("六");teml = teml / ; continue;
case :
Console.Write("七");teml = teml / ; continue;
case :
Console.Write("八");teml = teml / ; continue;
case :
Console.Write("九");teml = teml / ; continue; } }
Console.WriteLine(); }
上一篇:原创翻译-值得关注的10个python语言博客


下一篇:Spring-boot(一)通过向导快速创建Spring-boot项目