标签:ring color 小游戏 system 循环 round int sum turn
我们先封装一个叫做战士的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 对战游戏
{
public class Soldier
{
//名字,生命值,攻击力,招式
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
private int _Blood;
public int Blood
{
get { return _Blood; }
set { _Blood = value; }
}
private int _gongji;
public int Gongji
{
get { return _gongji; }
set { _gongji = value; }
}
private zhaoshi xiaozhao;
public zhaoshi Xiaozhao
{
get { return xiaozhao; }
set { xiaozhao = value; }
}
private zhaoshi dazhao;
public zhaoshi Dazhao
{
get { return dazhao; }
set { dazhao = value; }
}
private int _Miss;
public int Miss
{
get { return _Miss; }
set { _Miss = value; }
}
}
}
然后我们在封装一个招式的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 对战游戏
{
public class zhaoshi
{
private string _Name;
/// <summary>
/// 招式名称
/// </summary>
public string Name
{
get { return _Name; }
set { _Name = value; }
}
private int _gongji;
/// <summary>
/// 招式攻击
/// </summary>
public int Gongji
{
get { return _gongji; }
set { _gongji = value; }
}
}
}
最后我们游戏主页开始
编写游戏
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("请输入第一个拳皇的名称:");
s1.Name = Console.ReadLine();
s1.Gongji = r.Next(10, 101);
s1.Blood = r.Next(1000, 2001);
zhaoshi z1 = new zhaoshi();
Console.Write("请输入小招名称:");
z1.Name = Console.ReadLine();
z1.Gongji = r.Next(100, 201);
s1.Xiaozhao = z1;
zhaoshi z2 = new zhaoshi();
Console.Write("请输入大招名称:");
z2.Name = Console.ReadLine();
z2.Gongji = r.Next(300, 501);
s1.Dazhao = z2;
s1.Miss = r.Next(0, 31);
Soldier s2 = new Soldier();
Console.Write("请输入第二个拳皇战士的名称:");
s2.Name = Console.ReadLine();
s2.Gongji = r.Next(10, 101);
s2.Blood = r.Next(1000, 2001);
zhaoshi z3 = new zhaoshi();
Console.Write("请输入小招名称:");
z3.Name = Console.ReadLine();
z3.Gongji = r.Next(100, 201);
s2.Xiaozhao = z3;
zhaoshi z4 = new zhaoshi();
Console.Write("请输入大招名称:");
z4.Name = Console.ReadLine();
z4.Gongji = r.Next(300, 501);
s2.Dazhao = z4;
s2.Miss = r.Next(0, 31);
Console.WriteLine("*******************************战士信息榜*******************************");
Console.WriteLine("战士1:" + s1.Name + ",攻击:" + s1.Gongji + ",闪避:" + s1.Miss + ",血量:" + s1.Blood + ",小招:" + s1.Xiaozhao.Name + "," + s1.Xiaozhao.Gongji + ",大招:" + s1.Dazhao.Name + "," + s1.Dazhao.Gongji);
Console.WriteLine("战士2:" + s2.Name + ",攻击:" + s2.Gongji + ",闪避:" + s2.Miss + ",血量:" + s2.Blood + ",小招:" + s2.Xiaozhao.Name + "," + s2.Xiaozhao.Gongji + ",大招:" + s2.Dazhao.Name + "," + s2.Dazhao.Gongji);
Console.WriteLine("按下任意键开始战斗!!!");
Console.ReadKey();
//循环战斗,战个痛快(不死不休)
int count = 1;
while (true)
{
Console.WriteLine("*******************************第" + count + "回合*******************************");
System.Threading.Thread.Sleep(1500);
if (r.Next(0, 101) < s2.Miss)
{
Console.WriteLine(s2.Name + "躲避了此次攻击!!!");
}
else
{
int ss1 = r.Next(0, 100);
if (ss1 > 95)//开大招
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("【" + s1.Name + "】对【" + s2.Name + "】释放了☆☆☆☆☆" + s1.Dazhao.Name + "☆☆☆☆☆,造成" + s1.Dazhao.Gongji + "点伤害,【" + s2.Name + "】剩余" + (s2.Blood - s1.Dazhao.Gongji) + "点血量");
Console.WriteLine();
//S2扣血
s2.Blood -= s1.Dazhao.Gongji;
}
else if (ss1 >= 80 && ss1 <= 95)//开小招
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("【" + s1.Name + "】对【" + s2.Name + "】释放了☆☆" + s1.Xiaozhao.Name + "☆☆,造成" + s1.Xiaozhao.Gongji + "点伤害,【" + s2.Name + "】剩余" + (s2.Blood - s1.Xiaozhao.Gongji) + "点血量");
Console.WriteLine();
//S2扣血
s2.Blood -= s1.Xiaozhao.Gongji;
}
else//普通攻击
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("【" + s1.Name + "】攻击了【" + s2.Name + "】,造成" + s1.Gongji + "点伤害,【" + s2.Name + "】剩余" + (s2.Blood - s1.Gongji) + "点血量");
Console.WriteLine();
//S2扣血
s2.Blood -= s1.Gongji;
}
//判断战士2是否阵亡
if (s2.Blood <= 0)
{
Console.WriteLine("【" + s2.Name + "】已over【" + s1.Name + "】fight!!!");
break;
}
}
//战士2开始攻击
System.Threading.Thread.Sleep(1500);
if (r.Next(0, 101) < s1.Miss)
{
Console.WriteLine(s1.Name + "躲避了此次攻击!!!");
}
else
{
int ss2 = r.Next(0, 100);
if (ss2 > 95)//开大招
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("【" + s2.Name + "】对【" + s1.Name + "】释放了☆☆☆☆☆" + s2.Dazhao.Name + "☆☆☆☆☆,造成" + s2.Dazhao.Gongji + "点伤害,【" + s1.Name + "】剩余" + (s1.Blood - s2.Dazhao.Gongji) + "点血量");
Console.WriteLine();
//S1扣血
s1.Blood -= s2.Dazhao.Gongji;
}
else if (ss2 >= 80 && ss2 <= 95)//开小招
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("【" + s2.Name + "】对【" + s1.Name + "】释放了☆☆" + s2.Xiaozhao.Name + "☆☆,造成" + s2.Xiaozhao.Gongji + "点伤害,【" + s1.Name + "】剩余" + (s1.Blood - s2.Xiaozhao.Gongji) + "点血量");
Console.WriteLine();
//S1扣血
s1.Blood -= s2.Xiaozhao.Gongji;
}
else//普通攻击
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("【" + s2.Name + "】攻击了【" + s1.Name + "】,造成" + s2.Gongji + "点伤害,【" + s1.Name + "】剩余" + (s1.Blood - s2.Gongji) + "点血量");
Console.WriteLine();
//S1扣血
s1.Blood -= s2.Gongji;
}
//判断战士2是否阵亡
if (s1.Blood <= 0)
{
Console.WriteLine("【" + s1.Name + "】已over【" + s2.Name + "】fight");
break;
}
}
count++;
}
Console.ReadKey();
}
}
}
标签:ring color 小游戏 system 循环 round int sum turn
原文地址:http://www.cnblogs.com/wuxiaochao/p/6105618.html