结构体练习

结构体练习--自做对战练习

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace 对战练习
{
class Program
{
struct player
{
public string name;
public int atk;
public int hp;
public int defense;
public int quick;
public int power;
public int mp;
public renshu jn;
}
struct renshu
{
public renshuming name;
public int chakela;
}
struct renshuming
{
public string renshu1;
public string renshu2;
public string renshu3;
public string renshu4;
public JNshanghai shanghai;
}
struct JNshanghai
{

public int shanghai1;
public int shanghai2;
public int shanghai3;
public int shanghai4;
}
static void Main(string[] args)
{
Random r=new Random();
player wanjia1 = new player();
player wanjia2 = new player();
player p1 = new player();
player p2 = new player();
player p3 = new player();
player p4 = new player();
player p5 = new player();
p1.name = "初代-千手柱间";
p1.power = r.Next(60,80);
p1.hp = r.Next(3000, 3500) + p1.power * 10;
p1.quick = r.Next(30, 40);
p1.defense = p1.quick;
p1.mp = r.Next(40,50);
p1.atk = r.Next(130,150)+p1.power*2;
p1.atk = r.Next(80, 100) + p1.power * 2+p1.mp;
p1.jn.chakela = 1500;
p1.jn.name.renshu1 = "仙法-木遁-真数千手";
p1.jn.name.shanghai.shanghai1 = 900;
p1.jn.name.renshu2 = "木遁-花树界降临";
p1.jn.name.shanghai.shanghai2 = 800;
p1.jn.name.renshu3 = "木遁-树界降诞";
p1.jn.name.shanghai.shanghai3 = 700;
p1.jn.name.renshu4 = "木遁-巨木人之术";
p1.jn.name.shanghai.shanghai4 = 600;
p2.name = "旗木卡卡西";
p2.power = r.Next(40, 60);
p2.hp = r.Next(2800, 3300) + p2.power * 5;
p2.quick = r.Next(60, 80);
p2.defense = p2.quick * 2;
p2.mp = r.Next(30,40);
p2.atk = r.Next(90, 110) + p2.quick * 2+p2.mp;
p2.jn.chakela = 1000;
p2.jn.name.renshu1 = "神威";
p2.jn.name.shanghai.shanghai1 = 900;
p2.jn.name.renshu2 = "水遁·大瀑布之术";
p2.jn.name.shanghai.shanghai2 = 500;
p2.jn.name.renshu3 = "冰遁·一角白鲸";
p2.jn.name.shanghai.shanghai3 = 600;
p2.jn.name.renshu4 = "雷遁-雷切";
p2.jn.name.shanghai.shanghai4 = 650;
p3.name = "我爱罗";
p3.power = r.Next(20, 40);
p3.hp = r.Next(2700, 3200) + p3.power * 5;
p3.quick = r.Next(30, 50);
p3.defense = p3.quick;
p3.mp = r.Next(100, 120);
p3.atk = r.Next(100, 120) + p3.mp * 2+p3.quick;
p3.jn.chakela = 1200;
p3.jn.name.renshu1 = "砂之守鹤";
p3.jn.name.shanghai.shanghai1 = 850;
p3.jn.name.renshu2 = "守鹤之矛";
p3.jn.name.shanghai.shanghai2 = 800;
p3.jn.name.renshu3 = "砂瀑层大葬";
p3.jn.name.shanghai.shanghai3 = 600;
p3.jn.name.renshu4 = "风遁-无限砂尘大突破";
p3.jn.name.shanghai.shanghai4 = 650;
p4.name = "漩涡鸣人";
p4.power = r.Next(60, 80);
p4.hp = r.Next(3000, 3500) + p4.power * 10;
p4.quick = r.Next(80, 90);
p4.defense = p1.quick+30;
p4.mp = r.Next(1,10);
p4.atk = r.Next(80, 100) + p4.power * 2+p4.mp;
p4.jn.chakela = 1500;
p4.jn.name.renshu1 = "仙法-风遁-螺旋手里剑";
p4.jn.name.shanghai.shanghai1 = 800;
p4.jn.name.renshu2 = "超大玉螺旋丸";
p4.jn.name.shanghai.shanghai2 = 650;
p4.jn.name.renshu3 = "大玉螺旋丸";
p4.jn.name.shanghai.shanghai3 = 600;
p4.jn.name.renshu4 = "螺旋丸";
p4.jn.name.shanghai.shanghai4 = 500;
p5.name = "宇智波佐助";
p5.power = r.Next(40, 60);
p5.hp = r.Next(2800, 3300) + p5.power * 5;
p5.quick = r.Next(60, 80);
p5.defense = p2.quick * 2;
p5.mp = r.Next(20,30);
p5.atk = r.Next(90, 110) + p5.quick * 2+p5.mp;
p5.jn.chakela = 1000;
p5.jn.name.renshu1 = "须佐能乎";
p5.jn.name.shanghai.shanghai1= 850;
p5.jn.name.renshu2 = "天照";
p5.jn.name.shanghai.shanghai2 = 800;
p5.jn.name.renshu3 = "火遁-豪火球之术";
p5.jn.name.shanghai.shanghai3 = 500;
p5.jn.name.renshu4 = "雷遁-千鸟";
p5.jn.name.shanghai.shanghai4 = 600;
ArrayList p = new ArrayList();
p.Add(p1);
p.Add(p2);
p.Add(p3);
p.Add(p4);
p.Add(p5);
Console.WriteLine("火影第二版!暂时放出5个英雄,每个英雄四个专属技能。后续添加!"+
"欢迎各位大神指导修正!"+
"\n加入了查克拉,维持生命的基础查克拉量是200,也就是说查克拉如果低于200就无法施放技能。可以判断是否同归于尽,判定玩家一查克拉量是否高于"+
"150生命值是否低于250并且玩家二生命值高于玩家一生命值且玩家二生命值低于玩家一最强技能伤害值,满足条件玩家一可与玩家二同归于尽!");
Console.WriteLine("点击任意键继续。。。。");
Console.ReadKey();
Console.Clear();
Console.WriteLine("请玩家一选择英雄:\n1.初代 2.旗木卡卡西 3.我爱罗 4.漩涡鸣人 5.宇智波佐助");
int a1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请玩家二选择英雄:\n1.初代 2.旗木卡卡西 3.我爱罗 4.漩涡鸣人 5.宇智波佐助");
int a2 = Convert.ToInt32(Console.ReadLine());
wanjia1 = (player)p[a1-1];
wanjia2 = (player)p[a2-1];
Console.Clear();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("英雄名称:"+wanjia1.name+" HP "+wanjia1.hp+" 防御 "+wanjia1.defense+" 攻击 "+wanjia1.atk+" 敏捷 "+wanjia1.quick+" 智商 "
+wanjia1.mp+" 查克拉 "+wanjia1.jn.chakela);
Console.WriteLine("VS");
Console.WriteLine("英雄名称:" + wanjia2.name + " HP " + wanjia2.hp + " 防御 " + wanjia2.defense + " 攻击 " + wanjia2.atk +" 敏捷 "+
wanjia2.quick+ " 智商 " + wanjia2.mp+" 查克拉 "+wanjia2.jn.chakela);
Console.ResetColor();
Console.WriteLine("点击任意键开始游戏.....");
Console.ReadKey();
while (true)
{
if (wanjia1.hp<=0&&wanjia2.hp<=0)
{
Console.WriteLine("卧槽~战的不爽~来~~再来大战三百回合");
break;
}
else if (wanjia1.hp<=0&&wanjia2.hp>0)
{
Console.WriteLine(" "+wanjia1.name+" 你丫~回家修炼十年再来比过");
break;
}
else if (wanjia1.hp>0&&wanjia2.hp<=0)
{
Console.WriteLine(" "+wanjia2.name+" 你丫~回家修炼十年再来比过");
break;
}
else if (wanjia1.hp<250&&wanjia1.jn.chakela>150&&wanjia2.hp>wanjia1.hp&&wanjia2.hp<wanjia1.jn.name.shanghai.shanghai1)
{
Console.WriteLine(" "+wanjia1.name+" 施放最强技能 "+wanjia1.jn.name+"与"+wanjia2.name+"同归于尽");
break;
}
else if (wanjia2.hp<250&&wanjia2.jn.chakela>150&&wanjia1.hp>wanjia2.hp&&wanjia1.hp<wanjia2.jn.name.shanghai.shanghai1)
{
Console.WriteLine(" "+wanjia2.name+" 施放最强技能 "+wanjia2.jn.name+"与"+wanjia1.name+"同归于尽");
break;
}
if (wanjia1.quick>wanjia2.quick)//敏捷高的先出手
{
int s1 = r.Next(0, 10);//随机取值,来调节技能的施放几率
if (s1 > 7 && wanjia1.jn.chakela > 200)//调节技能的施放几率,并且必须在查克拉量200以上才可以施放,200为基础查克拉量,低于这个值便进入虚弱状态
{
int c = r.Next(200,300);//随机取值,查克拉的消耗量
int x1 = r.Next(0,4);//取随机数,用来施放不同的技能
int dhp2;//玩家二的掉血量
int atk1 = wanjia1.atk - 50;//浮动玩家一的普通攻击
int defense2 = wanjia2.defense - 10;//浮动玩家二的防御
switch (x1)
{
case 0:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai1 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai1 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp<0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu1 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
case 1:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai2 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai2 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp<0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu2 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
case 2:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai3 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai3 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp<0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu3 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
case 3:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai4 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai4 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp<0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu4 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
}
}
else
{
int dodge = r.Next(0,10);
if (dodge>6)//取随机数,用来调节闪避的几率
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(wanjia2.name+" 躲避了 "+wanjia1.name+"的攻击");
}
else
{
int dhp2;//玩家二的掉血量
int atk1 = wanjia1.atk - 50;
int defense2 = wanjia2.defense - 10;
dhp2 = (atk1 - defense2) < 0 ? 0 : (atk1 - defense2);
wanjia2.hp -= dhp2;
if (wanjia2.hp < 0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(wanjia1.name + "使用 普通攻击 对" + wanjia2.name + "造成" + dhp2 + "点伤害");
}
}
System.Threading.Thread.Sleep(1500);
int s2 = r.Next(0, 10);
if (s2 > 7&&wanjia2.jn.chakela>200)//调节技能的施放几率,并且必须在查克拉量200以上才可以施放,200为基础查克拉量,低于这个值便进入虚弱状态
{
int c = r.Next(200,300);//随机取值,表示查克拉的消耗量
int x2 = r.Next(0, 4);//取随机数,用来施放不同的技能
int dhp1;//玩家一的掉血量
int atk2 = wanjia2.atk - 50;//浮动玩家二的普通攻击
int defense1 = wanjia1.defense - 10;//浮动玩家一的防御
switch (x2)
{
case 0:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai1 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai1 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu1 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
case 1:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai2 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai2 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu2 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
case 2:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai3 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai3 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu3 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
case 3:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai4 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai4 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu4 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
}
}
else
{
int dodge = r.Next(0, 10);
if (dodge > 6)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(wanjia1.name + " 躲避了 " + wanjia2.name + "的攻击");
}
else
{
int dhp1;//玩家一的掉血量
int atk2 = wanjia2.atk - 50;
int defense1 = wanjia2.defense - 10;
dhp1 = (atk2 - defense1) < 0 ? 0 : (atk2 - defense1);
wanjia1.hp -= dhp1;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(wanjia2.name + "使用 普通攻击 对" + wanjia1.name + "造成" + dhp1 + "点伤害");
}
}
System.Threading.Thread.Sleep(1500);
}
else
{
int s2 = r.Next(0, 10);
if (s2 > 7&&wanjia2.jn.chakela>200)
{
int c = r.Next(200,300);
int x2 = r.Next(0, 4);//取随机数,用来施放不同的技能
int dhp1;//玩家一的掉血量
int atk2 = wanjia2.atk - 50;//浮动玩家二的普通攻击
int defense1 = wanjia1.defense - 10;//浮动玩家一的防御
switch (x2)
{
case 0:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai1 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai1 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu1 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
case 1:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai2 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai2 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu2 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
case 2:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai3 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai3 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu3 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
case 3:
dhp1 = (atk2 + wanjia2.jn.name.shanghai.shanghai4 - defense1) < 0 ? 0 : (atk2 + wanjia2.jn.name.shanghai.shanghai4 - defense1);
wanjia1.hp -= dhp1;
wanjia2.jn.chakela -= c;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia2.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia2.jn.name.renshu4 + " 对" + wanjia1.name + "造成" + dhp1 + "点伤害\n" + wanjia2.name + "剩余查克拉量" + wanjia2.jn.chakela);
break;
}
}
else
{
int dodge = r.Next(0, 10);
if (dodge > 6)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(wanjia1.name + " 躲避了 " + wanjia2.name + "的攻击");
}
else
{
int dhp1;//玩家一的掉血量
int atk2 = wanjia2.atk - 50;
int defense1 = wanjia2.defense - 10;
dhp1 = (atk2 - defense1) < 0 ? 0 : (atk2 - defense1);
wanjia1.hp -= dhp1;
if (wanjia1.hp < 0)
{
wanjia1.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(wanjia2.name + "使用 普通攻击 对" + wanjia1.name + "造成" + dhp1 + "点伤害");
}
}
System.Threading.Thread.Sleep(1500);
int s1 = r.Next(0, 10);
if (s1 > 7)
{
int c = r.Next(200,300);
int x1 = r.Next(0, 4);//取随机数,用来施放不同的技能
int dhp2;//玩家二的掉血量
int atk1 = wanjia1.atk - 50;//浮动玩家一的普通攻击
int defense2 = wanjia2.defense - 10;//浮动玩家二的防御
switch (x1)
{
case 0:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai1 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai1 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp < 0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu1 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
case 1:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai2 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai2 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp < 0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu2 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
case 2:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai3 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai3 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp < 0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu3 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
case 3:
dhp2 = (atk1 + wanjia1.jn.name.shanghai.shanghai4 - defense2) < 0 ? 0 : (atk1 + wanjia1.jn.name.shanghai.shanghai4 - defense2);
wanjia2.hp -= dhp2;
wanjia1.jn.chakela -= c;
if (wanjia2.hp < 0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(wanjia1.name + "消耗 " + c + " 点查克拉" + "施放 " + wanjia1.jn.name.renshu4 + " 对" + wanjia2.name + "造成" + dhp2 + "点伤害\n" + wanjia1.name + "剩余查克拉" + wanjia1.jn.chakela);
break;
}
}
else
{
int dodge = r.Next(0, 10);
if (dodge > 6)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(wanjia2.name + " 躲避了 " + wanjia1.name + "的攻击");
}
else
{
int dhp2;//玩家二的掉血量
int atk1 = wanjia1.atk - 50;
int defense2 = wanjia2.defense - 10;
dhp2 = (atk1 - defense2) < 0 ? 0 : (atk1 - defense2);
wanjia2.hp -= dhp2;
if (wanjia2.hp < 0)
{
wanjia2.hp = 0;
}
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(wanjia1.name + "使用 普通攻击 对" + wanjia2.name + "造成" + dhp2 + "点伤害");
}
}
System.Threading.Thread.Sleep(1500);
}
Console.ResetColor();
Console.WriteLine();
Console.WriteLine(wanjia1.name+"剩余血量 "+wanjia1.hp+" "+wanjia2.name+"剩余血量 "+wanjia2.hp);
Console.WriteLine();
}
Console.ReadLine();
}
}
}

时间: 2024-12-31 03:33:54

结构体练习的相关文章

关于结构体

1.结构体(struct)是由一系列具有相同类型或不同类型的数据构成的数据集合,叫做结构. typedef struct People { int a; char b; double c; }P: 其中:struct是关键词, People是标签, a b c是成员, P是此结构体声明的变量. 于是在声明变量的时候就可:P p1; 这里的P实际上就是struct People的别名.P==struct People 另外这里也可以不写People(于是也不能struct People p1;了,

Linux C中结构体初始化

    在阅读GNU/Linux内核代码时,我们会遇到一种特殊的结构初始化方式.该方式是某些C教材(如谭二版.K&R二版)中没有介绍过的.这种方式称为指定初始化(designated initializer).下面我们看一个例子,Linux-2.6.x/drivers/usb/storage/usb.c中有这样一个结构体初始化项目: static struct usb_driver usb_storage_driver = { .owner = THIS_MODULE, .name = "

在Swift结构体中如何实现写时复制?

结构体(Struct)在Swift语言中占有重要地位,在Swift标准库中,大约有90%的公开类型都是结构体,包括我们常用的Array.String.Dictionary.结构体相比类,一个最重要的特性就是它是值类型,而类似引用类型.值类型是通过复制值来赋值的,而不是引用同一个内存地址,这样就不存在数据共享的问题,能防止意外的数据改变,并且它是线程安全的. 举一个很简单的例子,在objc中,数组是类,是引用类型,在Swift中,数组是结构体,是值类型.因此下面的代码中: let array1 =

结构体的大小

系统在存储结构体变量时存在地址对齐问题,编译器在编译程序时会遵循两条原则: 一.结构体变量中成员的偏移量必须是成员大小的整数倍: 二.结构体大小必须是所有成员大小的整数倍. 1 #include<stdio.h> 2 3 struct a{ 4 int i; 5 float f; 6 char c; 7 double d; 8 long l; 9 }b; 10 11 int main(){ 12 printf("%d\n",sizeof(b.i));// 4 13 prin

关于OC中直接打印结构体,点(CGRect,CGSize,CGPoint,UIOffset)等数据类型

关于OC直接打印结构体,点(CGRect,CGSize,CGPoint,UIOffset)等数据类型,我们完全可以把其转换为OC对象来进项打印调试,而不必对结构体中的成员变量进行打印.就好比我们可以使用NSStringFromCGRect(CGRect rect)来直接打印一个结构体,其他打印可以参考以下内容 UIKIT_EXTERN NSString *NSStringFromCGPoint(CGPoint point); UIKIT_EXTERN NSString *NSStringFrom

38-oc常用结构体

常用结构体 在开发中苹果推荐我们使用CG开头的结构体, 也就是说NS开头的结构体一般不用 OC中定义一个点,用什么结构体 NSPoint; CGPoint point = NSMakePoint(10, 20); OC中保存物体尺寸的,用什么结构体 NSSize; CGSize size = NSMakeSize(100, 50); OC中保存某个物体的位置和尺寸,用什么结构体 NSRect; CGRect rect = NSMakeRect(10, 20, 100, 50); NSNumber

结构体在固件库中的应用

上次介绍了一般结构体的定义以及引用方法,那么接下来将对结构体在官方固件库是如何具体使用的做出简单说明. 结构体指针成员变量引用方法是通过“→”符号来实现,比如要访问student1结构体指针指向的结构体的成员变量name,那么方法是: stuednt1—>name; 如在STM32官方固件库中对端口使用模式结构体定义如下: typedef enum { GPIO_Mode_AIN = 0x0, //模拟输入模式 GPIO_Mode_IN_FLOATING = 0x04, //浮空输入模式 GPI

C# 定义一个学生的结构体,输入学生信息,学号,姓名,身高,按身高排序输出

class Program { //定义一个结构体 struct student//student就是我们自己造的新数据类型 { public int code;//public修饰符 public string name;//结构体的成员 public decimal height; } static void Main(string[] args) { ArrayList arr = new ArrayList(); for (int i = 0; i < 3; i++) { student

类和结构体

//类  class A {     var a = 0 } let classA = A() classA.a = 12     //虽然classA定义为常量,但是仍然可以修改A类中的变量值;结构体则不可以 //类属于引用类型,结构体属于值类型

C语言结构体及函数传递数组参数示例

注:makeSphere()函数返回Sphere结构体,main函数中,调用makeSphere()函数,传递的第一个参数为数组,传递的数组作为指针. 版权声明:本文为博主原创文章,未经博主允许不得转载.