函数 及对战游戏

//对战游戏

struct duizhan

{

public string name;

public int  xue;

public int  gongji;

public int  fangyu;

public int  mingzhong;

public int  shengfa;

}

static void Main(string[] args)

{

duizhan[] a = new duizhan[5];//定义结构体,并建立数组

int i = 0;

for (; i < 5;i++ )//输入

{

Console.Write("请输入第{0}个人的姓名:",i+1);

a[i].name = Console.ReadLine();

int m = (int)Convert.ToChar(a[i].name.Substring(0,1));

Random n = new Random(m);

a[i].xue = 1000+ n.Next(1000);

a[i].gongji = 50 + n.Next(100);

a[i].mingzhong = 50 + n.Next(100);

a[i].fangyu = 30 + n.Next(100);

a[i].shengfa = 30 + n.Next(100);

Console.Write("生命力:"+a[i].xue +"\t攻击力:"+a[i].gongji +"\t命中率:"+a[i].mingzhong +"\t防御力"+a[i].fangyu +"\t身法"+a[i].shengfa +"\n");

}

Console.WriteLine("按任意键开始!");

Console.ReadKey();//按任意键开始

while (true)

{

Random m = new Random();

int p = m.Next(5);

int q = m.Next(5);//随机生成两名选手

if (p != q && a[p].xue > 0 && a[q].xue > 0)

{

Console.WriteLine("\n");

Console.ForegroundColor = ConsoleColor.Yellow ;//修改字体颜色

Console.WriteLine(a[p].name + "准备攻击" + a[q].name);

Thread.Sleep(3000); //延迟3秒

a[p].gongji = m.Next(150) + 50;

a[p].mingzhong = m.Next(150) + 50;

int shashangli = a[p].gongji + a[p].mingzhong;

a[q].fangyu = m.Next(130) + 50;

a[q].shengfa = m.Next(130) + 50;

int dikangli = a[q].fangyu + a[q].shengfa;

Console.Write("\n");

if (shashangli > dikangli)//判断攻击条件

{

int shixue = a[p].gongji - a[q].fangyu;

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine(a[p].name + "攻击掉" + a[q].name + shixue + "滴血!");

Console.ForegroundColor = ConsoleColor.Green;

a[q].xue = a[q].xue - shixue;

Console.WriteLine(a[q].name + "剩余" + a[q].xue  + "滴血!");

}

else

{

Console.ForegroundColor = ConsoleColor.Blue ;

Console.WriteLine(a[q].name + "躲过了" + a[p].name + "的攻击!");

}

}

else if(a[p].xue <=0)

{

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine(a[p].name +"战败!");

}

else if (a[q].xue <= 0)

{

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine(a[q].name + "战败!");

}

else

{

continue ;

}

}

//函数 ( 名 输入 加工 输出 )高内聚,低耦合    独立 常用 分工 会做 调用

//在class里面加入static int Max(int a,int b)

//{

//     if(a>b){return a}else{return b}

//}

//在main里就能利用了

//int x = 3, y = 4;

//Console.WriteLine("最大值是:"+max(x,y));

//int x = 3, y = 4, c = 5;

//int a = max(max(x,y),c);

//Console.WriteLine("最大值是:" + a);

时间: 2024-12-09 14:22:44

函数 及对战游戏的相关文章

模拟德州扑克对战游戏

================================================================ 注意:本文参考"巧妙的Python数据结构玩法|实战德州扑克"的相关内容,并在此基础之上完成模拟扑克对战游戏. 原文网址:http://mp.weixin.qq.com/s/JQ0zJGf7Tz49Xn78x7Z40g ================================================================ 我们写了两

结构体、枚举类型及其练习题,最后的对战游戏(基础版)

结构体:在内存中临时存储数据的方式1.变量.常量2.数组,可以存储固定长度统一类型的数据3.集合4.结构体 学生信息:姓名,性别,年龄,系别 结构体含义:就是将生活中的一些个体,封装成一个特殊的类型 结构体是:用户自定义数据类型 创建:创建的位置:main函数之外struct Student{ public int Code; public string Name; public string Sex; public int Old; public DateTime Birthday;} 定义:

第十二天学习内容 综合应用 推箱子和对战游戏

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace day12{    class Program    {        static void Main(string[] args)        { //推箱子游戏            int x = 1, y = 1, i = 0;        

对战游戏1.0

//主函数using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 作业_对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); //战士,名字,生命值,攻击力,招式,闪躲 Soldier S1 = new Soldier(); Console.Write(

ADO.NET 扩展属性、配置文件 和 对战游戏

扩展属性 有外键关系时将信息处理成用户可看懂的 利用扩展属性 如:Info表中的民族列显示的是民族代号处理成Nation表中的民族名称 需要在Info类里面扩展一个显示nation名称的属性 例:先前在NationDA里面已经下好了一个代号换成名称的方法 public class Info { //扩展的名族名称属性 public string NationName { get { NationDA da = new NationDA(); return da.NationName(this.n

对战游戏

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); Soldier s1 = new Soldier(); Console.Write(

封装练习 对战游戏

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); //战士,名字,生命值,攻击力,招式 Soldier s1 = new Soldier(); Console.Write("请输入第一个战士的姓

【经典】C++&amp;RPG对战游戏

博文背景: 还记大二上学期的时候看的这个C++&RPG游戏(博主大一下学期自学的php,涵盖oop内容),一个外校的同学他们大一学的C++,大二初期C++实训要求做一个程序填空,就是这个 RPG 对战游戏,有几处空需要填上,问我可以不,我就信誓旦旦的说OK,最后“万般无奈多方考究”才给将程序补充完整.最近在做毕业设计,用到C++&QT oop部分,重新温习了下C++ oop,就想起来大二的时候还“捣鼓”过这么个游戏,现重新看了下,进行整理总结,写下该博文. ----------------

VS 游戏:推箱子&amp;对战游戏

推箱子 //只做了两关 class Program { static void Main(string[] args) { int x = 1; int y = 8; int z = 0; int end1x = 6; int end1y = 3; int end2x = 6; int end2y = 3; #region 地图绘制 string[,,] map = new string[3, 10, 10] { { {"●", "●", "●"