标签:
现在我们开始学习面向对象的3天,我发现面向对象好绕;
eg: public int Baoji
{
get
{
return baoji;
}
set
{
baoji = value;
if (baoji < 0)
{
baoji = 0;
}
if (baoji > 100)
{
baoji = 100;
}
}
}
public void Attackmonster(monster m)
{ Console.ForegroundColor = ConsoleColor.Magenta;
Random rad = new Random();//随机数
int num = rad.Next(1, 101);//随机数值
//检查是否被闪避
if (num <= m.Shanbi)
{
Console.WriteLine("对不起!!攻击无效,聪明的怪兽轻而易举的躲开了你的攻击");
return;
}
int shanhai = Attack -m.Deface;
shanhai = shanhai < 1 ? 1 : shanhai ;
//检查是否暴击
num = rad.Next(1, 101);
if (num <= Baoji)
{
shanhai *= 2;
Console.Write("暴击!");
}
m.Shengmingli -= shanhai;
Console.WriteLine("英雄烈猛的攻击了怪兽,使怪兽受了{0}点伤害,怪兽剩余生命力:{1}", shanhai, m.Shengmingli);
}
等等、、、、
标签:
原文地址:http://www.cnblogs.com/yangxingxiu/p/4399075.html