标签:
class Program
{
struct player
{
public string name;
public int hp;
public int attack;
public int defend;
public int quick;
public WuGong WG;
}
struct WuGong
{
public string name;
public int atk;
}
static void gongfu(WuGong[] wg)
{
wg[0].name="降龙十八掌";
wg[0].atk = 500;
wg[1].name = "打狗棒法";
wg[1].atk = 600;
wg[2].name = "独孤九剑";
wg[2].atk = 600;
}
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
player p1 = new player();
player p2 = new player();
Random r = new Random();
//生成两个玩家
Console.Write("请输入第一个战士的名字:");
p1.name = Console.ReadLine();
Console.Write("请输入第一个战士的名字:");
p2.name = Console.ReadLine();
//生成血量
p1.hp = r.Next(1, 1000) + 1000;//初始血量
p2.hp = r.Next(1, 1000) + 1000;
//生成攻防
p1.attack = r.Next(1, 50) + 80;
p2.attack = r.Next(1, 50) + 80;
p1.defend = r.Next(1, 50) + 50;
p2.defend = r.Next(1, 50) + 50;
//生成身法-敏捷度
p1.quick = r.Next(100);
p2.quick = r.Next(100);
Console.WriteLine("玩家:" + p1.name + " 血量:" + p1.hp + "\t攻击力:" + p1.attack
+ "\t物防:" + p1.defend + " 敏捷度:" + p1.quick);
Console.WriteLine("VS");
Console.WriteLine("玩家:" + p2.name + " 血量:" + p2.hp + "\t攻击力:" + p2.attack
+ "\t物防:" + p2.defend + " 敏捷度:" + p2.quick);
Console.WriteLine("点击任意键开始游戏.....");
Console.ReadKey();
while (true)
{
// 得出最后结果,跳出循环
if (p1.hp <= 0 && p2.hp <= 0)
{
Console.WriteLine(p1.name + "与" + p2.name + "同归于尽!");
Console.ReadLine();
break;
}
if (p1.hp <= 0)
{
Console.WriteLine(p1.name + "把" + p2.name + "KO..");
Console.ReadLine();
break;
}
if (p2.hp <= 0)
{
Console.WriteLine(p2.name + "把" + p1.name + "KO..");
Console.ReadLine();
break;
}
//对战
WuGong[] wg = new WuGong[3];
gongfu(wg);
//大招
int dz1 = r.Next(10);//大招随机
if (dz1 >= 5) //从1到9的随机数里 取8和9 有20%的几率用大招。
{
Random x = new Random();
int a = x.Next(0, 3);
int dx1 = r.Next(100);//声明 掉血 变量
int gj1 = r.Next(100) - 50;//为了浮动 P2的 攻击力;
int fy1 = r.Next(100) - 50;//为了浮动 P1的防御力;
dx1 = ((dx1 + wg[a].atk) - (p1.defend + fy1)) < 0 ? 0 : ((dx1 + wg[a].atk) - (p1.defend + fy1));
//为了防止掉血 出现负值
p1.hp -= dx1;
if (p1.hp < 0)
{
p1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(p2.name + "使用大招 "+wg[a].name+" 攻击,对" + p1.name + "造成" + dx1 + "的伤害。");
}
else //平常招式
{
//躲闪
int sf1 = r.Next(80);//身法的随机数
if (p1.quick - sf1 >= 0)
{
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(p1.name + "躲闪" + p2.name + "的攻击");
}
else
{
int dx1 = r.Next(100);//声明 掉血 变量
int gj1 = r.Next(100) - 50;//为了浮动 P2的 攻击力;
int fy1 = r.Next(100) - 50;//为了浮动 P1的防御力;
dx1 = (dx1 + (p2.attack + gj1) - (p1.defend + fy1)) < 0 ? 0 : (dx1 + (p2.attack + gj1) - (p1.defend + fy1));
//为了防止掉血 出现负值
p1.hp -= dx1;
if (p1.hp < 0)
{
p1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(p1.name + "使用普通攻击,对" + p2.name + "造成" + dx1 + "的伤害。");
}
}
//稍等一下
System.Threading.Thread.Sleep(1000);
int dz2 = r.Next(10);
if (dz2 >= 5)
{
Random y = new Random();
int b = y.Next(0,3);
int dx2 = r.Next(100);
int gj2 = r.Next(100) - 50;//为了浮动 P1的 攻击力;
int fy2 = r.Next(100) - 50;//为了浮动 P2的防御力;
dx2 = ((dx2 + wg[b].atk) - (p2.defend + fy2)) < 0 ? 0 : ((dx2 + wg[b].atk) - (p2.defend + fy2));
//为了防止掉血 出现负值
p2.hp -= dx2;
if (p2.hp < 0)
{
p2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(p1.name + "使用大招 "+wg[b].name+" 攻击,对" + p2.name + "造成" + dx2 + "的伤害。");
}
else
{
//躲闪
int sf2 = r.Next(80);
if (p2.quick - sf2 > sf2)
{
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(p2.name + "躲闪" + p1.name + "的攻击");
}
else
{
int dx2 = r.Next(100);
int gj2 = r.Next(100) - 50;//为了浮动 P1的 攻击力;
int fy2 = r.Next(100) - 50;//为了浮动 P2的防御力;
dx2 = (dx2 + (p1.attack + gj2 ) - (p2.defend + fy2)) < 0 ? 0 : (dx2 + (p1.attack + gj2 ) - (p2.defend + fy2));
//为了防止掉血 出现负值
p2.hp -= dx2;
if (p2.hp < 0)
{
p2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(p2.name + "使用普通攻击,对" + p1.name + "造成" + dx2 + "的伤害。");
}
}
//稍等一下
System.Threading.Thread.Sleep(1000);
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("玩家:" + p1.name + "\t血量:" + p1.hp + "\t");
Console.WriteLine("玩家:" + p2.name + "\t血量:" + p2.hp);
}
}
}
标签:
原文地址:http://www.cnblogs.com/likaixuan/p/4343462.html